@@ -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