Skip to content

test: rewrite DefaultClassRealmManagerTest to drop Mockito static mocking and javaagent - #14192

Open
gnodet wants to merge 1 commit into
apache:masterfrom
gnodet:fix/drop-mockito-agent
Open

gnodet wants to merge 1 commit into
apache:masterfrom
gnodet:fix/drop-mockito-agent

Conversation

@gnodet

@gnodet gnodet commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Remove the Mockito javaagent from the Maven build by rewriting the one test that required it.

Root Cause

DefaultClassRealmManagerTest used Mockito.mockStatic(LoggerFactory.class) to inject a mock logger and verify debug message ordering. Static mocking requires ByteBuddy instrumentation, which on JDK 21+ cannot self-attach without an explicit -javaagent:mockito-core.jar.

To supply the agent path, the build used dependency:properties — which triggers full transitive dependency resolution and sets ${org.mockito:mockito-core:jar} as a property. This introduced two problems:

  1. dependency:properties forces full transitive resolution, creating a scheduling barrier in concurrent builds (all transitive reactor JARs must be built before the mojo can run)
  2. The whole mechanism (dependency:properties → property → profile activation → argLine.mockito) adds unnecessary complexity for a single test

Fix

The test was verifying two distinct things:

  • Structural outcomes (realm ID, parent classloader, artifact inclusion based on file presence) — meaningful invariants
  • Debug message ordering — an implementation detail, not a contract

The debug message assertions (testDebugEnabled / testDebugDisabled) verify that different log messages are emitted depending on isDebugEnabled(), but the structural outcome (which artifacts end up in the realm) is identical in both cases. The isDebugEnabled() guard is a performance optimization, not a testable behavioral difference.

Rewrite as a single test asserting only the structural outcomes directly from the ClassRealm. Remove:

  • mockStatic(LoggerFactory.class) and all Mockito static/InOrder imports
  • The dependency:properties plugin execution (prepare-for-mockito-agent)
  • The mockito profile and argLine.mockito property
  • The argLine.mockito placeholder from <properties>

Tests

The rewritten testProjectRealmIncludesArtifactsWithFileAndExcludesOthers covers all the meaningful invariants previously spread across two tests.


Hermes Agent (Claude Sonnet 4.5) on behalf of Guillaume Nodet

…king and remove javaagent

The test used mockStatic(LoggerFactory.class) only to inject a mock
logger and verify debug message ordering. This required a Mockito
javaagent (-javaagent:mockito-core.jar) which in turn required the
dependency:properties goal to resolve the agent path, adding full
transitive dependency resolution to the build (a scheduling barrier
in concurrent builds).

The structural invariants under test (realm identity, parent
classloader, artifact inclusion/exclusion based on file presence)
are verifiable directly from the ClassRealm without any logger
involvement. The debug message order is an implementation detail,
not a testable contract.

Rewrite the test to assert only the structural outcomes. Remove the
dependency:properties execution, the mockito profile, and all
argLine.mockito plumbing from the root POM.
@gnodet
gnodet marked this pull request as ready for review November 30, 2026 23:30

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Clean removal of Mockito static mocking and javaagent infrastructure. The rewritten test (testProjectRealmIncludesArtifactsWithFileAndExcludesOthers) preserves all meaningful behavioral assertions — realm identity, parent classloader, artifact inclusion/exclusion by file presence — while correctly dropping the debug-log-ordering verification that was testing an implementation detail, not a behavioral contract.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants