File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
main/java/org/openrewrite/java/testing/junit5
test/java/org/openrewrite/java/testing/junit5 Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 2929
3030import java .time .Duration ;
3131import java .util .Comparator ;
32+ import java .util .Set ;
3233
3334public class UpdateTestAnnotation extends Recipe {
3435
@@ -61,6 +62,13 @@ private static class UpdateTestAnnotationVisitor extends JavaIsoVisitor<Executio
6162 @ Override
6263 public J .CompilationUnit visitCompilationUnit (J .CompilationUnit cu , ExecutionContext executionContext ) {
6364 J .CompilationUnit c = super .visitCompilationUnit (cu , executionContext );
65+ Set <NameTree > nameTreeSet = c .findType ("org.junit.Test" );
66+ if (!nameTreeSet .isEmpty ()) {
67+ // Update other references like `Test.class`.
68+ c = (J .CompilationUnit ) new ChangeType ("org.junit.Test" , "org.junit.jupiter.api.Test" , true )
69+ .getVisitor ().visit (cu , executionContext );
70+ }
71+
6472 maybeRemoveImport ("org.junit.Test" );
6573 doAfterVisit (new JavaIsoVisitor <ExecutionContext >() {
6674 @ Override
Original file line number Diff line number Diff line change @@ -37,6 +37,33 @@ public void defaults(RecipeSpec spec) {
3737 .activateRecipes ("org.openrewrite.java.testing.junit5.JUnit4to5Migration" ));
3838 }
3939
40+ @ Issue ("https://github.com/openrewrite/rewrite-testing-frameworks/issues/284" )
41+ @ Test
42+ void classReference () {
43+ rewriteRun (
44+ java (
45+ """
46+ import org.junit.Test;
47+
48+ public class Sample {
49+ void method() {
50+ Class<Test> c = Test.class;
51+ }
52+ }
53+ """ ,
54+ """
55+ import org.junit.jupiter.api.Test;
56+
57+ public class Sample {
58+ void method() {
59+ Class<Test> c = Test.class;
60+ }
61+ }
62+ """
63+ )
64+ );
65+ }
66+
4067 @ Test
4168 @ Issue ("https://github.com/openrewrite/rewrite-testing-frameworks/issues/145" )
4269 void assertThatReceiver () {
You can’t perform that action at this time.
0 commit comments