Skip to content

Migrate Whitebox and remove PowerMock plumbing when replacing PowerMockito - #1337

Merged
timtebeek merged 11 commits into
mainfrom
powermock-hardening/E
Nov 19, 2026
Merged

timtebeek merged 11 commits into
mainfrom
powermock-hardening/E

Conversation

@timtebeek

Copy link
Copy Markdown
Member

What's changed?

  • Whitebox.getInternalState/setInternalState/invokeMethod/getField/getMethod now handle class-literal and static targets, the where overload, varargs, explicit type arguments, returned values and lambdas; Whitebox.getInnerClassType is covered too. Whitebox.setInternalState(X.class, ..) used to produce silently wrong code (X.class.getClass()) and no longer does.
  • MockRepository.*, PowerMockAgent.initializeIfNeeded, leftover PowerMockRunner and PowerMockObjectFactory (with its TestNG @ObjectFactory method) are removed.
  • Static methods inherited by a mockStatic type, such as Inet4Address.getByName, are retargeted to the declaring class instead of disabling the test.
  • PowerMock.createMock/createNiceMock/createStrictMock/replay/verify become EasyMock calls and then go through EasyMockCodeToMockito.

What's your motivation?

A run of ReplacePowerMockito over 190 open-source repositories (https://dev.moderne.io/results/ALL/20261118221102-P76NN) disabled 1202 tests in 84 of them.

Anything in particular you'd like reviewers to focus on?

Across 12 synced repos, added @Disabled went from 15 to 1 (aws-xray-sdk-java 6 to 0, checkstyle-lgtm 9 to 1; the one left relies on private members). The EasyMock route leaves Mockito.verify(mock); for a verify with no recorded expectations, which compiles, and EasyMockVerifyToMockitoVerify generates calls without type attribution, so a test relaxes methodInvocations validation. System/Thread static mocks and verifyPrivate stay flagged. The patched aws-xray-sdk-java was not compiled (errorprone javac jar would not resolve); the mockito test suite passes.

Part of a series hardening ReplacePowerMockito, one PR per family of gaps.

@timtebeek
timtebeek merged commit 82a538e into main Nov 19, 2026
1 check passed
@timtebeek
timtebeek deleted the powermock-hardening/E branch November 19, 2026 16:17
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Nov 19, 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