Align SessionMock.getService with real behavior #11111
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR brings SessionMock in line with the real Session implementation:
getService(Class)
now throwsNoSuchElementException
for unknown services by default.It also simplifies the mock by centralizing the list of configured services and strengthens test coverage.
Motivation
null
for unknown services (Mockito default), diverging from production behavior and occasionally masking test errors.What changed
NoSuchElementException
, matchingAbstractSession
semantics.CONFIGURED_SERVICES
set and acontains
check, replacing the chained predicate.argThat
to apply the default-throw behavior only for services not inCONFIGURED_SERVICES
.getMockSessionWithEnhancedServiceBehavior(...)
;getMockSession(...)
now has the enhanced behavior by default.Compatibility
null
for unknown services should now either configure/stub those services or expectNoSuchElementException
.impl/maven-testing
and its tests.Files touched
impl/maven-testing/src/main/java/org/apache/maven/api/plugin/testing/stubs/SessionMock.java
impl/maven-testing/src/test/java/org/apache/maven/api/plugin/testing/stubs/SessionGetServiceTest.java
impl/maven-testing/src/test/java/org/apache/maven/api/plugin/testing/stubs/SessionMockDefaultBehaviorTest.java
Verification