Skip to content

Pin bare mockito-core type table lookups to a single Mockito major - #1255

Merged
timtebeek merged 2 commits into
mainfrom
qualify-mockito-core-lookups
Oct 27, 2026
Merged

timtebeek merged 2 commits into
mainfrom
qualify-mockito-core-lookups

Conversation

@timtebeek

Copy link
Copy Markdown
Member

A bare "mockito-core" type table lookup matches both mockito-core-3.12.4 and mockito-core-5.24.0, so each of these tests parsed against whichever one the lookup happened to pick. This PR qualifies the 20 table lookups in 14 test classes so each one matches exactly one entry. No dependency jar on the test runtime classpath ships a Mockito type table, so the repo's own tables are the only candidates.

All tests pass with either version, so the choice is based on what each test exercises:

  • mockito-core-3 is used for recipes in Mockito1to3Migration/Mockito1to4Migration (AddMockitoExtensionIfAnnotationsUsed, ThenThrowCheckedExceptionToRuntimeException, AddMockitoJupiterDependency, RemoveInitMocksIfRunnersSpecified, ReplaceInitMockToOpenMock), for the JUnit 4 initMocks integration test, for the PowerMock runner test, and for Mockito1to4MigrationTest, Mockito1to5MigrationTest and MockitoBestPracticesTest. The last three migrate a build that declares mockito-core:3.12.4, so their source should be parsed against 3.
  • mockito-core-5 is used for the stand-alone best-practice recipes SimplifyMockitoVerifyWhenGiven, RemoveTimesZeroAndOne, RemoveDoNothingForDefaultMocks and RemoveMockitoSettings. SimplifyMockitoVerifyWhenGivenTest already uses mockito-core-5 in its per-test overrides.

CleanupMockitoImportsTest keeps KotlinParser.builder().classpath("mockito-core", ...). That lookup uses the runtime classpath, which contains only mockito-core-5.12.0, so it isn't ambiguous.

To verify, I ran the 15 affected classes (the 14 changed ones plus CleanupMockitoImportsTest) with ./gradlew --max-workers=2 test --tests ... on main, on this branch, and with every lookup forced to 3 and then to 5. All four runs gave 148 passed and 4 failed, and the per-test results on main and this branch were identical. The 4 failures (AddMockitoJupiterDependencyTest.addsMockitoJupiterDependencyWhenMockUsedInJUnit5, Mockito1to4MigrationTest.modifyMockitoDependencies, Mockito1to5MigrationTest.modifyMockitoDependencies, MockitoBestPracticesTest.mockito5) happen in the Gradle tooling API: Maven Central returned HTTP 429 while resolving org.openrewrite.gradle.tooling:plugin. They are unrelated to this change, and CI should exercise them.

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Oct 27, 2026
@timtebeek
timtebeek enabled auto-merge (squash) October 27, 2026 20:13
@timtebeek
timtebeek merged commit 95f20eb into main Oct 27, 2026
1 check passed
@timtebeek
timtebeek deleted the qualify-mockito-core-lookups branch October 27, 2026 20:29
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant