Skip to content

chore: upgrade Mockito to 5.18.0 - #24006

Merged
stian-sandvold merged 4 commits into
masterfrom
upgrade-mockito-5.18.0
May 27, 2026
Merged

chore: upgrade Mockito to 5.18.0#24006
stian-sandvold merged 4 commits into
masterfrom
upgrade-mockito-5.18.0

Conversation

@stian-sandvold

@stian-sandvold stian-sandvold commented May 27, 2026

Copy link
Copy Markdown
Contributor

What

Upgrades Mockito 5.2.05.18.0.

Why the non-test changes

  • Removed mockito-inline (4 module poms + root): discontinued after 5.2.0; the inline mock maker now ships inside mockito-core.
  • Pinned byte-buddy to 1.17.5 and attach byte-buddy-agent at JVM startup (pom.xml): without mockito-inline's shaded copy, Mockito uses the classpath byte-buddy, which transitive resolution otherwise pins to a version that can't read Java 21 class files. The agent is attached via Surefire's argLine because Java 21 blocks dynamic self-attachment. @{argLine} is kept so Jacoco coverage still works.

Test fixes (behaviour changes in 5.18)

  • SqlViewControllerTest: @InjectMocks no longer field-injects inherited @Autowired fields once constructor injection succeeds, so contextService is injected explicitly.
  • AnalyticsControllerTest: sets/clears a security context so getCurrentUsername() is non-null.

Test plan

  • CI green: unit, integration, integration-h2, formatting, Sonar quality gate

This PR was created by Claude (AI).

stian-sandvold and others added 4 commits May 27, 2026 10:13
…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>
@sonarqubecloud

Copy link
Copy Markdown

@stian-sandvold
stian-sandvold marked this pull request as ready for review May 27, 2026 10:57
@stian-sandvold
stian-sandvold enabled auto-merge (squash) May 27, 2026 10:57
@stian-sandvold
stian-sandvold merged commit 59aa38a into master May 27, 2026
19 of 20 checks passed
@stian-sandvold
stian-sandvold deleted the upgrade-mockito-5.18.0 branch May 27, 2026 11:33
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>
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.

3 participants