Skip to content

Resolve 35 mismatch stubbings in ServletResourceProviderCreateTest.java#56

Open
ARMS2025 wants to merge 1 commit intoapache:masterfrom
ARMS2025:resolve-mismatch-stubbing-3
Open

Resolve 35 mismatch stubbings in ServletResourceProviderCreateTest.java#56
ARMS2025 wants to merge 1 commit intoapache:masterfrom
ARMS2025:resolve-mismatch-stubbing-3

Conversation

@ARMS2025
Copy link

We are researchers and analyzed the test doubles (mocks) in the test code of the project. In our analysis of the project, we observed that

  • In the testCreateMethodsDefault test, 1 stubbing for the getProperty method is stubbed with the argument "service.id", but in actual execution, it is called with the argument "sling.servlet.paths". Additionally, the getProperty method is called with "sling.servlet.selectors", "sling.servlet.extensions", "sling.servlet.methods", "sling.servlet.prefix", and "sling.servlet.resourceSuperType", none of which were stubbed, resulting in mismatch stubbings.

  • In the testCreateMethodsSingle test, 1 stubbing for the getProperty method is stubbed with the argument "service.id", but in actual execution, it is called with the argument "sling.servlet.paths". Additionally, the getProperty method is called with "sling.servlet.selectors", "sling.servlet.extensions", "sling.servlet.prefix", and "sling.servlet.resourceSuperType", none of which were stubbed, resulting in mismatch stubbings.

  • In the testCreateMethodsMultiple test, 1 stubbing for the getProperty method is stubbed with the argument "service.id", but in actual execution, it is called with the argument "sling.servlet.paths". Additionally, the getProperty method is called with "sling.servlet.selectors", "sling.servlet.extensions", "sling.servlet.prefix", and "sling.servlet.resourceSuperType", none of which were stubbed, resulting in mismatch stubbings.

  • In the testCreateMethodsAll test, 1 stubbing for the getProperty method is stubbed with the argument "service.id", but in actual execution, it is called with the argument "sling.servlet.paths". Additionally, the getProperty method is called with "sling.servlet.selectors", "sling.servlet.extensions", "sling.servlet.prefix", and "sling.servlet.resourceSuperType", none of which were stubbed, resulting in mismatch stubbings.

  • In the testCreateSelectorsExtensions test, 1 stubbing for the getProperty method is stubbed with the argument "service.id", but in actual execution, it is called with the argument "sling.servlet.paths". Additionally, the getProperty method is called with "sling.servlet.prefix" and "sling.servlet.resourceSuperType", none of which were stubbed, resulting in mismatch stubbings.

  • In the testCreateMethodsExtensions test, 1 stubbing for the getProperty method is stubbed with the argument "service.id", but in actual execution, it is called with the argument "sling.servlet.paths". Additionally, the getProperty method is called with "sling.servlet.selectors", "sling.servlet.prefix", and "sling.servlet.resourceSuperType", none of which were stubbed, resulting in mismatch stubbings.

  • In the testCreateWithResourceSuperType test, 1 stubbing for the getProperty method is stubbed with the argument "service.id", but in actual execution, it is called with the argument "sling.servlet.paths". Additionally, the getProperty method is called with "sling.servlet.selectors", "sling.servlet.methods", and "sling.servlet.prefix", none of which were stubbed, resulting in mismatch stubbings.

  • In the testCreateWithDefaultResourceSuperType test, 1 stubbing for the getProperty method is stubbed with the argument "service.id", but in actual execution, it is called with the argument "sling.servlet.paths". Additionally, the getProperty method is called with "sling.servlet.methods" and "sling.servlet.prefix", none of which were stubbed, resulting in mismatch stubbings.

In this pull request, we propose a solution to resolve the mismatch stubbing.

Mismatched stubbing occurs when a mocked method is stubbed with specific arguments in a test but later invoked with different arguments in the code, potentially causing unexpected behavior. Mockito recommends addressing these issues, (https://www.javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/exceptions/misusing/PotentialStubbingProblem.html).

@sonarqubecloud
Copy link

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