Skip to content

Commit 53b65a2

Browse files
committed
Convert tests to Java
1 parent 9cb1fbf commit 53b65a2

File tree

115 files changed

+11379
-10398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+11379
-10398
lines changed

src/main/java/org/openrewrite/java/testing/junit5/AssertToAssertions.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class AssertToAssertions extends Recipe {
3636

3737
@Override
3838
public String getDisplayName() {
39-
return "JUnit4 Assert To JUnit Jupiter Assertions";
39+
return "JUnit4 `Assert` To JUnit Jupiter `Assertions`";
4040
}
4141

4242
@Override
@@ -55,16 +55,16 @@ protected TreeVisitor<?, ExecutionContext> getVisitor() {
5555
}
5656

5757
public static class AssertToAssertionsVisitor extends JavaIsoVisitor<ExecutionContext> {
58-
5958
private static final JavaType ASSERTION_TYPE = JavaType.buildType("org.junit.Assert");
6059

6160
private static final List<String> JUNIT_ASSERT_METHOD_NAMES = Arrays.asList(
6261
"assertArrayEquals", "assertEquals", "assertFalse", "assertNotEquals", "assertNotNull", "assertNotSame",
6362
"assertNull", "assertSame", "assertThrows", "assertTrue", "fail");
6463

65-
6664
@Override
6765
public JavaSourceFile visitJavaSourceFile(JavaSourceFile cu, ExecutionContext executionContext) {
66+
JavaSourceFile c = super.visitJavaSourceFile(cu, executionContext);
67+
6868
boolean hasWildcardAssertImport = false;
6969
for (J.Import imp : cu.getImports()) {
7070
if ("org.junit.Assert.*".equals(imp.getQualid().toString())) {
@@ -76,7 +76,10 @@ public JavaSourceFile visitJavaSourceFile(JavaSourceFile cu, ExecutionContext ex
7676
maybeAddImport("org.junit.jupiter.api.Assertions", "*", false);
7777
maybeRemoveImport("org.junit.Assert.*");
7878
}
79-
return super.visitJavaSourceFile(cu, executionContext);
79+
80+
maybeRemoveImport("org.junit.Assert");
81+
82+
return c;
8083
}
8184

8285
@Override
@@ -91,10 +94,10 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
9194
Expression firstArg = args.get(0);
9295
// Suppress arg-switching for Assertions.assertEquals(String, String)
9396
if (args.size() == 2) {
94-
if ("assertSame".equals(m.getSimpleName())
95-
|| "assertNotSame".equals(m.getSimpleName())
96-
|| "assertEquals".equals(m.getSimpleName())
97-
|| "assertNotEquals".equals(m.getSimpleName())) {
97+
if ("assertSame".equals(m.getSimpleName()) ||
98+
"assertNotSame".equals(m.getSimpleName()) ||
99+
"assertEquals".equals(m.getSimpleName()) ||
100+
"assertNotEquals".equals(m.getSimpleName())) {
98101
return m;
99102
}
100103
}
@@ -137,8 +140,8 @@ private static boolean isJunitAssertMethod(J.MethodInvocation method) {
137140
}
138141
}
139142

140-
@Override
141-
public Duration getEstimatedEffortPerOccurrence() {
142-
return Duration.ofMinutes(5);
143-
}
143+
@Override
144+
public Duration getEstimatedEffortPerOccurrence() {
145+
return Duration.ofMinutes(5);
146+
}
144147
}

0 commit comments

Comments
 (0)