Skip to content

[LIVY-1089] Upgrade Mockito 1.10.19 -> 3.4.6 (mockito-all -> mockito-core) - #565

Open
roczei wants to merge 1 commit into
apache:masterfrom
roczei:mockito_upgrade_to_3.4.6
Open

roczei wants to merge 1 commit into
apache:masterfrom
roczei:mockito_upgrade_to_3.4.6

Conversation

@roczei

@roczei roczei commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

mockito-all:1.10.19 is an uber-jar that bundles Hamcrest 1.x which conflicts with the Hamcrest 2.x pulled in by the ScalaTest 3.2.9 / scalatestplus mockito-3-4 upgrade: the bundled LocalizedMatcher does not implement Matcher.describeMismatch(Object, Description) and fails to compile. This switches to mockito-core (which does not bundle Hamcrest) and aligns the version with the mockito-3-4_2.13:3.2.9.0 binding.

  • pom.xml: mockito-all -> mockito-core, version 1.10.19 -> 3.4.6
  • Replace removed org.mockito.Matchers with org.mockito.ArgumentMatchers
  • Replace removed anyObject() with any()
  • Rewrite the custom ArgumentMatcher[Path] to the Mockito 2+ shape (matches(T) instead of matches(Object); drop the removed describeTo), dropping the now-unused Hamcrest Description and internal Equals imports

Note: in Mockito 3.4.6 org.mockito.Matchers still exists only as a deprecated subclass of ArgumentMatchers and declares no members of its own, so Scala cannot import its inherited statics (e.g. "import org.mockito.Matchers.any" fails to compile). All Scala specs must import from org.mockito.ArgumentMatchers directly.

Updated specs: HttpClientSpec, ScalaJobHandleTest, BatchSessionSpec, InteractiveSessionServletSpec, InteractiveSessionSpec, FileSystemStateStoreSpec, SparkYarnAppSpec.

JIRA: https://issues.apache.org/jira/browse/LIVY-1089

How was this patch tested?

Compiled the server module and its reactor dependencies with mvn -pl server -am test-compile, which succeeds (exit 0) and confirms all migrated specs now compile under Mockito 3.4.6 - including SparkYarnAppSpec, whose import org.mockito.Matchers.any would otherwise fail to compile.

Also compiled the thriftserver modules with the profile enabled via mvn -Pthriftserver -pl thriftserver/server,thriftserver/session,thriftserver/client -am test-compile, which succeeds (exit 0) - its tests use org.mockito.Mockito mock/when, which are unaffected by the migration.

Existing unit tests exercise the migrated mocks.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 4.8)

…core)

## What changes were proposed in this pull request?

mockito-all:1.10.19 is an uber-jar that bundles Hamcrest 1.x which
conflicts with the Hamcrest 2.x pulled in by the ScalaTest 3.2.9 /
scalatestplus mockito-3-4 upgrade: the bundled LocalizedMatcher does
not implement Matcher.describeMismatch(Object, Description) and fails
to compile. This switches to mockito-core (which does not bundle
Hamcrest) and aligns the version with the mockito-3-4_2.13:3.2.9.0
binding.

- pom.xml: mockito-all -> mockito-core, version 1.10.19 -> 3.4.6
- Replace removed org.mockito.Matchers with org.mockito.ArgumentMatchers
- Replace removed anyObject() with any()
- Rewrite the custom ArgumentMatcher[Path] to the Mockito 2+ shape
  (matches(T) instead of matches(Object); drop the removed describeTo),
  dropping the now-unused Hamcrest Description and internal Equals imports

Note: in Mockito 3.4.6 org.mockito.Matchers still exists only as a
deprecated subclass of ArgumentMatchers and declares no members of its
own, so Scala cannot import its inherited statics (e.g.
"import org.mockito.Matchers.any" fails to compile). All Scala specs
must import from org.mockito.ArgumentMatchers directly.

Updated specs: HttpClientSpec, ScalaJobHandleTest, BatchSessionSpec,
InteractiveSessionServletSpec, InteractiveSessionSpec,
FileSystemStateStoreSpec, SparkYarnAppSpec.

JIRA: https://issues.apache.org/jira/browse/LIVY-1089

## How was this patch tested?

Compiled the server module and its reactor dependencies with
`mvn -pl server -am test-compile`, which succeeds (exit 0) and confirms
all migrated specs now compile under Mockito 3.4.6 - including
SparkYarnAppSpec, whose `import org.mockito.Matchers.any` would
otherwise fail to compile.

Also compiled the thriftserver modules with the profile enabled via
`mvn -Pthriftserver -pl thriftserver/server,thriftserver/session,thriftserver/client -am test-compile`,
which succeeds (exit 0) - its tests use org.mockito.Mockito mock/when,
which are unaffected by the migration.

Existing unit tests exercise the migrated mocks.

## Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 4.8)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@roczei

roczei commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Hi @gyogal,

This is a follow-up to LIVY-1066. In certain cases compilation errors may occur due to the older version of Mockito. Example error message:

repository/org/mockito/mockito-all/1.10.19/mockito-all-1.10.19.jar(/org/mockito/internal/matchers/LocalizedMatcher.java):16:7:  error: LocalizedMatcher is not abstract and does not override abstract method describeMismatch(Object,Description) in Matcher

The Difference Between mockito-core and mockito-all: https://www.baeldung.com/mockito-core-vs-mockito-all

The solution is to upgrade Mockito and replace mockito-all with mockito-core. Please approve this change.

This branch has not been deployed

No deployments
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