Skip to content

Only remove a direct PowerMockTestCase or PowerMockConfiguration superclass in RemovePowerMockClassExtensions - #1224

Merged
timtebeek merged 1 commit into
mainfrom
tim/powermock-class-extension-exact-type
Oct 24, 2026
Merged

timtebeek merged 1 commit into
mainfrom
tim/powermock-class-extension-exact-type

Conversation

@timtebeek

Copy link
Copy Markdown
Member

RemovePowerMockClassExtensions matched the extends clause with TypeUtils.isAssignableTo, so it also stripped the superclass from subclasses of a user's own PowerMock base class. With abstract class MyBaseTest extends PowerMockTestCase, the recipe correctly turned that into abstract class MyBaseTest, but it also turned class FooTest extends MyBaseTest into class FooTest, so FooTest lost every inherited helper and no longer compiled.

The recipe now uses TypeUtils.isOfClassType, so it only removes an extends clause whose type is exactly PowerMockTestCase or PowerMockConfiguration. The base class is still unwrapped and its subclasses keep extends MyBaseTest. A new regression test, subclassOfOwnBaseClassKeepsExtension, fails on main and passes with this change.

Verified with ./gradlew test --tests 'org.openrewrite.java.testing.mockito.*': 466 tests, 0 failures, 2 skipped. That run includes RemovePowerMockClassExtensionsTest (3) and the ReplacePowerMockitoIntegrationTest composite (58).

Fixes item F1 of #1211.

…superclass in `RemovePowerMockClassExtensions`

The recipe checked the `extends` clause with `TypeUtils.isAssignableTo`, so a test such as `class FooTest extends MyBaseTest`, where the user's own `MyBaseTest` extends `PowerMockTestCase`, also lost its superclass and with it every inherited helper, leaving code that no longer compiles. Matching the exact type with `TypeUtils.isOfClassType` unwraps only the base class that extends PowerMock directly and keeps subclasses of it intact.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Oct 24, 2026
@timtebeek
timtebeek merged commit 300bfba into main Oct 24, 2026
2 checks passed
@timtebeek
timtebeek deleted the tim/powermock-class-extension-exact-type branch October 24, 2026 13:45
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Oct 24, 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