Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mockito inline dependency and introduce SamlAssertionConsumerFunctionTest #5735

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

yeojin-dev
Copy link
Contributor

Motivation:

This PR introduces the Mockito inline dependency to enhance mocking capabilities, particularly for final classes and static methods. Additionally, it introduces a new test class SamlAssertionConsumerFunctionTest to ensure the proper functionality of the SamlAssertionConsumerFunction class when login is failed. This is a follow-up to PR #5622.

Modifications:

  1. Dependencies:
  • Added mockito-inline to build.gradle and dependencies.toml for enhanced mocking capabilities.
  1. New Test Class:
  • Introduced SamlAssertionConsumerFunctionTest with two test methods:
    • testServeWithNullMessageContext: Verifies the behavior when messageContext is null.
    • testServeWithNonNullMessageContext: Verifies the behavior when messageContext is not null.
  • Utilized Mockito inline dependency to mock HttpPostBindingUtil for testing purposes.

Result:

  • The addition of the Mockito inline dependency allows for more flexible and powerful mocking in test cases, specifically to mock HttpPostBindingUtil.
  • The new SamlAssertionConsumerFunctionTest class ensures that SamlAssertionConsumerFunction behaves correctly under different scenarios.

@yeojin-dev yeojin-dev marked this pull request as draft June 5, 2024 23:58
Comment on lines 42 to 43
ServiceRequestContext ctx = mock(ServiceRequestContext.class);
AggregatedHttpRequest req = mock(AggregatedHttpRequest.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to mock these two types. Please use:

  • ServiceRequestContext.of() or .builder(); and
  • AggregatedHttpRequest.of().

SamlSingleSignOnHandler ssoHandler = mock(SamlSingleSignOnHandler.class);
SamlAssertionConsumerFunction underTest = new SamlAssertionConsumerFunction(
consumerConfig, "entityId", mock(Map.class), null,
mock(SamlRequestIdManager.class), ssoHandler, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto - we don't need to use Mockito to mock Map and SamlRequestIdManager - just pass a new HashMap and a dummy SamlRequestIdManager implementation.

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see you after the sprint 👍

@@ -244,6 +244,7 @@ configure(projectsWithFlags('java')) {
testRuntimeOnly libs.checkerframework // Required by guava-testlib
testImplementation libs.assertj
testImplementation libs.mockito
testImplementation libs.mockito.inline
Copy link
Contributor

@jrhee17 jrhee17 Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps adding this to only the saml module will help with the build

dependencies {

@github-actions github-actions bot added the Stale label Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants