chore: upgrade Mockito to 5.18.0 - #24006
Merged
Merged
Conversation
…ility - Bump mockito.version to 5.18.0 (from 5.2.0) - Remove mockito-inline dependency (absorbed into mockito-core in 5.x) - Add byte-buddy 1.17.5 to dependency management to align with the agent version and fix Java 21 class-file support - Add byte-buddy-agent as javaagent in Surefire argLine (required for inline mock maker instrumentation) - Configure mock-maker-subclass as the default in dhis-support-system to avoid Java 21 retransformation restrictions on java.base types - Replace Mockito mocks in StubDriver with JDK Proxy to prevent SubclassMockMaker from entering Mockito's shared static map and causing assertion failures in downstream tests - Fix AnalyticsControllerTest: inject security context in setUp/tearDown to prevent NPE in ConcurrentHashMap on null username key - Fix OAuth2ClientCredentialsAuthSchemeTest: minor test adaptations for Mockito 5.x strictness Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…Line
The byte-buddy startup javaagent supplies the Instrumentation the inline
mock maker needs on Java 21, so the subclass mock-maker override and its
knock-on changes are not required:
- Remove dhis-support-system mockito-extensions MockMaker; the inline
maker mocks concrete Spring classes fine once the agent is attached.
- Revert StubDriver to Mockito mocks; with no subclass maker anywhere
there is no shared-state cascade to avoid.
- Revert OAuth2ClientCredentialsAuthSchemeTest; the original mocks pass
unchanged under 5.18.
- surefire argLine uses @{argLine} so Jacoco's agent is preserved in the
default (non-profile) build, matching the unit/integration profiles.
Verified locally: dhis-support-system (227), dhis-support-hibernate (37),
OAuth2 test (4), AnalyticsControllerTest (7) all pass on Java 21.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…to 5.18 Two CI failures surfaced by the upgrade (both failing on the prior commit too, missed because integration tests weren't run locally): - integration-h2-test: SqlViewControllerTest hit a NullPointerException because Mockito 5.18's @Injectmocks no longer falls back to field injection once constructor injection (via Lombok @requiredargsconstructor) succeeds, leaving the inherited @Autowired contextService field null. Inject it explicitly in a @beforeeach via ReflectionTestUtils. - check-formatting / SonarCloud: AnalyticsControllerTest had a Spotless wrap violation and a new public lifecycle method (rule java:S5786). Reformat and drop the redundant public modifiers. Verified locally: SqlViewControllerTest (8) passes under -Pintegration-h2-test; spotless:check passes on dhis-web-api. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
jbee
approved these changes
May 27, 2026
stian-sandvold
marked this pull request as ready for review
May 27, 2026 10:57
stian-sandvold
enabled auto-merge (squash)
May 27, 2026 10:57
david-mackessy
approved these changes
May 27, 2026
stian-sandvold
added a commit
that referenced
this pull request
May 30, 2026
`-Xshare:off` was added to surefireArgLine in the Mockito 5.18 upgrade (#24006), alongside the byte-buddy startup agent. It disables Class Data Sharing — a JVM default that speeds startup — but it isn't needed: the byte-buddy agent and CDS coexist fine, since a class the inline mock maker redefines simply isn't served from the shared archive. Removing the flag restores the JVM's default (-Xshare:auto) without affecting the agent. Verified: the full test workflow is green with CDS enabled, and dhis-support-system (the inline-mock module) passes 227/0/0 locally on Java 21 with CDS on. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



What
Upgrades Mockito
5.2.0→5.18.0.Why the non-test changes
mockito-inline(4 module poms + root): discontinued after 5.2.0; the inline mock maker now ships insidemockito-core.byte-buddyto 1.17.5 and attachbyte-buddy-agentat JVM startup (pom.xml): withoutmockito-inline's shaded copy, Mockito uses the classpathbyte-buddy, which transitive resolution otherwise pins to a version that can't read Java 21 class files. The agent is attached via Surefire'sargLinebecause Java 21 blocks dynamic self-attachment.@{argLine}is kept so Jacoco coverage still works.Test fixes (behaviour changes in 5.18)
SqlViewControllerTest:@InjectMocksno longer field-injects inherited@Autowiredfields once constructor injection succeeds, socontextServiceis injected explicitly.AnalyticsControllerTest: sets/clears a security context sogetCurrentUsername()is non-null.Test plan
This PR was created by Claude (AI).