Skip to content

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

Open
Mbd06b wants to merge 1 commit intoethosengine:2.1.1from
ARUS2023:remove-unnecessary-stubbings-1
Open

Removed 2 unnecessary stubbings in AbstractOidcTest.java and 3 unnecessary stubbings in OidcClientTest.java#2
Mbd06b wants to merge 1 commit intoethosengine:2.1.1from
ARUS2023:remove-unnecessary-stubbings-1

Conversation

@Mbd06b
Copy link
Member

@Mbd06b Mbd06b commented Feb 1, 2025

ARUS2023 commented on 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.

@Mbd06b Mbd06b changed the base branch from 2.1.x to 2.1.1 February 1, 2025 17:16
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.

2 participants