Skip to content

Commit 3da249e

Browse files
JohannisKtimtebeek
andauthored
Remove all PowerMock imports after migration (#770)
* Added Cleanup recipe to remove all PowerMock imports * format and license * Added jar for tests * Remove unnecessary modifiers * Inline inner class * Use a single parameterized test --------- Co-authored-by: Tim te Beek <[email protected]>
1 parent 3bb272b commit 3da249e

File tree

4 files changed

+210
-127
lines changed

4 files changed

+210
-127
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
* <p>
4+
* Licensed under the Moderne Source Available License (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://docs.moderne.io/licensing/moderne-source-available-license
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.java.testing.mockito;
17+
18+
import org.openrewrite.ExecutionContext;
19+
import org.openrewrite.Preconditions;
20+
import org.openrewrite.Recipe;
21+
import org.openrewrite.TreeVisitor;
22+
import org.openrewrite.java.JavaIsoVisitor;
23+
import org.openrewrite.java.search.UsesType;
24+
import org.openrewrite.java.tree.J;
25+
import org.openrewrite.java.tree.JavaSourceFile;
26+
27+
public class CleanupPowerMockImports extends Recipe {
28+
@Override
29+
public String getDisplayName() {
30+
return "Cleanup PowerMock imports";
31+
}
32+
33+
@Override
34+
public String getDescription() {
35+
return "Removes unused `org.powermock` import symbols.";
36+
}
37+
38+
@Override
39+
public TreeVisitor<?, ExecutionContext> getVisitor() {
40+
return Preconditions.check(
41+
new UsesType<>("org.powermock..*", false),
42+
new JavaIsoVisitor<ExecutionContext>() {
43+
@Override
44+
public J preVisit(J tree, ExecutionContext ctx) {
45+
stopAfterPreVisit();
46+
if (tree instanceof JavaSourceFile) {
47+
for (J.Import _import : ((JavaSourceFile) tree).getImports()) {
48+
if (_import.getPackageName().startsWith("org.powermock")) {
49+
maybeRemoveImport(_import.getPackageName() + "." + _import.getClassName());
50+
}
51+
}
52+
}
53+
return tree;
54+
}
55+
});
56+
}
57+
}

src/main/resources/META-INF/rewrite/powermockito.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ recipeList:
4343
fullyQualifiedTargetTypeName: org.mockito.Mockito
4444
- org.openrewrite.java.testing.mockito.PowerMockitoMockStaticToMockito
4545
- org.openrewrite.java.testing.mockito.PowerMockitoWhenNewToMockito
46+
- org.openrewrite.java.testing.mockito.CleanupPowerMockImports
4647
- org.openrewrite.java.dependencies.RemoveDependency:
4748
groupId: org.powermock
4849
artifactId: powermock-api-mockito*

0 commit comments

Comments
 (0)