Skip to content

Fix PowerMockRunner removal leaving @Mock fields uninitialized#942

Merged
timtebeek merged 1 commit intomainfrom
bmuschko/powermock-to-mockito-runner
Mar 26, 2026
Merged

Fix PowerMockRunner removal leaving @Mock fields uninitialized#942
timtebeek merged 1 commit intomainfrom
bmuschko/powermock-to-mockito-runner

Conversation

@bmuschko
Copy link
Copy Markdown
Contributor

@bmuschko bmuschko commented Mar 25, 2026

Summary

  • Mockito1to3Migration removed @RunWith(PowerMockRunner.class) without adding a replacement runner, leaving @Mock fields null at runtime
  • Root cause: ReplacePowerMockito ran after AddMockitoExtensionIfAnnotationsUsed in the recipe chain, so the latter saw the existing @RunWith and skipped the class
  • Fix: move ReplacePowerMockito before MockitoJUnitToMockitoExtension and AddMockitoExtensionIfAnnotationsUsed so the runner gap is detected and filled with @RunWith(MockitoJUnitRunner.class) (JUnit 4) or @ExtendWith(MockitoExtension.class) (JUnit 5)

…nner

ReplacePowerMockito was ordered after AddMockitoExtensionIfAnnotationsUsed,
so the latter would see @RunWith(PowerMockRunner.class) and skip the class.
Then ReplacePowerMockito would remove it, leaving @mock fields uninitialized.

Move ReplacePowerMockito before AddMockitoExtensionIfAnnotationsUsed so the
runner gap is detected and filled with MockitoJUnitRunner or MockitoExtension.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Mar 25, 2026
@bmuschko bmuschko added the bug Something isn't working label Mar 25, 2026
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Mar 26, 2026
@timtebeek timtebeek merged commit a72d7b1 into main Mar 26, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Mar 26, 2026
@timtebeek timtebeek deleted the bmuschko/powermock-to-mockito-runner branch March 26, 2026 08:10
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

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants