Skip to content

Mockito1to3Migration: rename anyXOf matchers called through org.mockito.Mockito - #1130

Merged
timtebeek merged 4 commits into
openrewrite:mainfrom
mohitduhan19:fix-1115-mockito-anyxof-via-mockito
Sep 28, 2026
Merged

timtebeek merged 4 commits into
openrewrite:mainfrom
mohitduhan19:fix-1115-mockito-anyxof-via-mockito

Conversation

@mohitduhan19

@mohitduhan19 mohitduhan19 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What's changed?

In Mockito 1.x Mockito extends Matchers, so matchers used through org.mockito.Mockito (typically via import static org.mockito.Mockito.*) are attributed to Mockito, not Matchers. The ChangeType from Matchers to ArgumentMatchers and the renames keyed on ArgumentMatchers therefore skip them, which leaves calls like anyListOf(String.class) uncompilable on Mockito 5.

What's your motivation?

Checklist

  • Added handlesAnyXOfFromMockitoWildCardImport, which fails without the change and passes with it.
  • Mockito1to3MigrationTest passes locally.

@timtebeek
timtebeek self-requested a review September 28, 2026 16:43
@timtebeek timtebeek added recipe Recipe request mockito bug Something isn't working labels Sep 28, 2026
…d static imports

Calls through static imports of Mockito or BDDMockito are attributed to that class,
so key the matcher renames on org.mockito.* instead of duplicating them per class.
CleanupMockitoImports now takes a static import's owner from the typed import target,
as J.Import#getTypeName() fails to find methods inherited from Matchers once that type
is changed to ArgumentMatchers, which removed still used static imports.

@timtebeek timtebeek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot for the help here @mohitduhan19 ! I've made some small adjustments to pick up additional migrations. Should make it into the next release, but you can already build from source to use the snapshot.

@timtebeek
timtebeek merged commit 384e31f into openrewrite:main Sep 28, 2026
@mohitduhan19

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for extending the fix to cover the additional migrations, @timtebeek! Much appreciated, and glad to see this in main. Looking forward to contributing more.

@mohitduhan19
mohitduhan19 deleted the fix-1115-mockito-anyxof-via-mockito branch September 28, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working mockito recipe Recipe request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Mockito1to5Migration leaves anyListOf uncompilable when matchers are reached through import static org.mockito.Mockito.*

2 participants