Convert ArgumentMatcher anonymous class to lambda in Mockito migration#937
Merged
Convert ArgumentMatcher anonymous class to lambda in Mockito migration#937
Conversation
The Mockito1to3Migration recipe changes org.mockito.Matchers to org.mockito.ArgumentMatchers but does not update the matches(Object) method signature on ArgumentMatcher<T> implementations. This new recipe converts anonymous ArgumentMatcher<T> implementations to lambda expressions with the correct parameter type and removes unnecessary casts.
src/test/java/org/openrewrite/java/testing/mockito/ArgumentMatcherToLambdaTest.java
Show resolved
Hide resolved
Previously the recipe only converted anonymous classes where the matches parameter was Object. Now it also handles cases where the parameter is already correctly typed or where the type argument is Object, consistently collapsing to a lambda in all cases.
src/main/java/org/openrewrite/java/testing/mockito/ArgumentMatcherMatchesParameterType.java
Outdated
Show resolved
Hide resolved
Make the recipe class name more descriptive of what it actually does, so it is clearer when used from a declarative recipe setup.
steve-aom-elliott
approved these changes
Mar 24, 2026
Use J.Parentheses.unwrap() instead of manually extracting and re-prefixing the identifier.
timtebeek
approved these changes
Mar 24, 2026
Member
timtebeek
left a comment
There was a problem hiding this comment.
Thanks! Good to merge once CI passes.
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.
Summary
ArgumentMatcherMatchesParameterTyperecipe that converts anonymousArgumentMatcher<T>implementations withmatches(Object)to lambda expressions with the correct parameter typeMockito1to3Migrationafter theChangeTypefromorg.mockito.Matcherstoorg.mockito.ArgumentMatchers(String) argument) within the method body