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

Removed 2 unnecessary stubbings in AbstractOidcTest.java and 3 unnecessary stubbings in OidcClientTest.java #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ARUS2023
Copy link

@ARUS2023 ARUS2023 commented Oct 5, 2023

In our analysis of the project, we observed that

  1. 1 unnecessary stubbings which stubbed createValidator method is created in AbstractOidcTest.createSpyOidcClient, which is invoked in OidcClientTest.newSpyOidcClient is created but never executed by 5 tests: OidcClientTest.createAuthenticationRequest, OidcClientTest.invalidAuthenticationRequestUri,OidcClientTest.tokenErrorResponse, OidcClientTest.tokenErrorResponseWithoutErrorCode, OidcClientTest.invalidTokenRequestUri; It is also created by never executed by 2 tests: IntegrationTest.redirect_browser_to_oidc_authentication_form and IntegrationTest.callback_throws_ISE_if_error_when_requesting_id_token

  2. 2 unnecessary stubbings which stubbed createValidator method, getProviderMetadata method are created in AbstractOidcTest.createSpyOidcClient, which is invoked in OidcClientTest.newSpyOidcClient is created but never executed by 4 tests: OidcClientTest.getUserInfo, OidcClientTest.getAuthorizationCode,OidcClientTest.invalidAuthenticationResponseUri, OidcClientTest.authenticationErrorResponse;

  3. 3 unnecessary stubbings that are created in OidcClientTest.newSpyOidcClient is created but never executed by 7 tests: OidcClientTest.createAuthenticationRequest, OidcClientTest.invalidAuthenticationRequestUri, OidcClientTest.tokenErrorResponseWithoutErrorCode, OidcClientTest.invalidTokenRequestUri, OidcClientTest.authenticationErrorResponse, OidcClientTest.invalidAuthenticationResponseUri, OidcClientTest.getAuthorizationCode;

  4. 2 unnecessary stubbings which returned tokenResponse and userInfo are created in OidcClientTest.newSpyOidcClient is created but never executed by the tests: OidcClientTest.tokenErrorResponse;

  5. 2 unnecessary stubbings which returned tokenResponse and errorTokenResponse are created in OidcClientTest.newSpyOidcClient is created but never executed by the tests: OidcClientTest.getUserInfo;

In summary:
There are 4 tests did not execute the stubbing which stubbed createValidator method in AbstractOidcTest.createSpyOidcClient and 3 stubbings inOidcClientTest.newSpyOidcClient. We first duplicated the method AbstractOidcTest.createSpyOidcClient, named it AbstractOidcTest.createSpyOidcClient2 and remove the unnecessary stubbings from the new method; then duplicated OidcClientTest.newSpyOidcClient, named it OidcClientTest.newSpyOidcClient2, removed the 3 unnecessary stubbings, and changed the method createSpyOidcClient to createSpyOidcClient2; At last, we applied OidcClientTest.newSpyOidcClient2 to the 4 tests.

There is 1 test did not execute the stubbing which stubbed createValidator method in AbstractOidcTest.createSpyOidcClient and 2 stubbings which returned tokenResponse and userInfo in OidcClientTest.newSpyOidcClient. We first duplicated OidcClientTest.newSpyOidcClient, named it OidcClientTest.newSpyOidcClient3, remove the 2 unnecessary stubbings, and changed the method createSpyOidcClient to createSpyOidcClient2; Then, we applied OidcClientTest.newSpyOidcClient3 to the test.

There are 1 test did not execute the 2 stubbings in AbstractOidcTest.createSpyOidcClient and 2 stubbings which returned tokenResponse and errorTokenResponse in OidcClientTest.newSpyOidcClient. We first duplicated the method AbstractOidcTest.createSpyOidcClient, named it AbstractOidcTest.createSpyOidcClient3 and remove the 2 unnecessary stubbings from the new method; then duplicated OidcClientTest.newSpyOidcClient, named it OidcClientTest.newSpyOidcClient4, removed the 2 unnecessary stubbings, and changed the method createSpyOidcClient to createSpyOidcClient3; At last, we applied OidcClientTest.newSpyOidcClient4 to the test.

There are 3 tests did not execute the 2 stubbings in AbstractOidcTest.createSpyOidcClient and and 3 stubbings inOidcClientTest.newSpyOidcClient. We first duplicated OidcClientTest.newSpyOidcClient, named it OidcClientTest.newSpyOidcClient5, removed the 2 unnecessary stubbings, and changed the method createSpyOidcClient to createSpyOidcClient3; At last, we applied OidcClientTest.newSpyOidcClient5 to the 3 tests.

Unnecessary stubbings are stubbed method calls that were never realized during test execution. Mockito recommends to remove unnecessary stubbings (https://www.javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/exceptions/misusing/UnnecessaryStubbingException.html).

We propose below a solution to remove the unnecessary stubbings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant