Skip to content

Use mockito-inline instead of mockito-core where applicable#923

Merged
timtebeek merged 4 commits intomainfrom
bmuschko/junit4-mockito-ext
Mar 2, 2026
Merged

Use mockito-inline instead of mockito-core where applicable#923
timtebeek merged 4 commits intomainfrom
bmuschko/junit4-mockito-ext

Conversation

@bmuschko
Copy link
Contributor

@bmuschko bmuschko commented Feb 28, 2026

Summary

  • Changes the ReplacePowerMockito recipe to replace PowerMock dependencies with mockito-inline instead of mockito-core for Mockito 3.x/4.x

  • PowerMock features (static mocking, constructor mocking, final class mocking) require the inline mock maker, which is only bundled in mockito-inline for Mockito 3.x/4.x — mockito-core alone causes runtime failures

  • Closes https://github.com/moderneinc/customer-requests/issues/1934

Mockito 5.x

Mockito 5.x makes mockito-inline obsolete. All you need with that version forward is mockito-core. This has already been covered in the org.openrewrite.java.testing.mockito.Mockito4to5Only recipe.

recipeList:
  - org.openrewrite.java.testing.mockito.Mockito1to4Migration
  - org.openrewrite.java.dependencies.ChangeDependency:
      oldGroupId: org.mockito
      oldArtifactId: mockito-inline
      newArtifactId: mockito-core

PowerMock features (static mocking, constructor mocking, final class
mocking) require the inline mock maker, which is only bundled in
mockito-inline for Mockito 3.x/4.x. Using mockito-core alone causes
runtime failures when the migrated code calls Mockito.mockStatic().
…ine (#1934)

Replace hardcoded mockito-inline dependency with a ScanningRecipe that
detects mockStatic(), whenNew(), or @PrepareForTest usage and selects
mockito-inline only when needed, falling back to mockito-core otherwise.
@bmuschko bmuschko marked this pull request as ready for review February 28, 2026 23:51
@bmuschko bmuschko added the bug Something isn't working label Feb 28, 2026
@bmuschko bmuschko changed the title ReplacePowerMockito: use mockito-inline instead of mockito-core Use mockito-inline instead of mockito-core Feb 28, 2026
@bmuschko bmuschko changed the title Use mockito-inline instead of mockito-core Use mockito-inline instead of mockito-core where applicable Feb 28, 2026
@steve-aom-elliott steve-aom-elliott self-requested a review March 2, 2026 16:08
@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Mar 2, 2026
Use Map<JavaProject, Boolean> in the accumulator so each sub-module
gets mockito-inline or mockito-core based on its own usage patterns.
@timtebeek timtebeek merged commit f1b202d into main Mar 2, 2026
1 check passed
@timtebeek timtebeek deleted the bmuschko/junit4-mockito-ext branch March 2, 2026 18:41
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants