Skip to content

Commit fc5a0ae

Browse files
committed
Add visitor that updates junit 4 assumptions to junit 5 assumptions
1 parent e7320c8 commit fc5a0ae

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.openrewrite.java.AddImport;
1919
import org.openrewrite.java.AutoFormat;
2020
import org.openrewrite.java.ChangeType;
21+
import org.openrewrite.java.JavaIsoRefactorVisitor;
2122
import org.openrewrite.java.JavaRefactorVisitor;
2223
import org.openrewrite.java.tree.*;
2324

@@ -31,13 +32,13 @@
3132
import static org.openrewrite.Formatting.format;
3233
import static org.openrewrite.Tree.randomId;
3334

34-
public class ChangeTestAnnotation extends JavaRefactorVisitor {
35+
public class ChangeTestAnnotation extends JavaIsoRefactorVisitor {
3536
public ChangeTestAnnotation() {
3637
setCursoringOn();
3738
}
3839

3940
@Override
40-
public J visitCompilationUnit(J.CompilationUnit cu) {
41+
public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu) {
4142
ChangeType changeType = new ChangeType();
4243
changeType.setType("org.junit.Test");
4344
changeType.setTargetType("org.junit.jupiter.api.Test");
@@ -47,8 +48,8 @@ public J visitCompilationUnit(J.CompilationUnit cu) {
4748
}
4849

4950
@Override
50-
public J visitMethod(J.MethodDecl method) {
51-
J.MethodDecl m = refactor(method, super::visitMethod);
51+
public J.MethodDecl visitMethod(J.MethodDecl method) {
52+
J.MethodDecl m = super.visitMethod(method);
5253

5354
boolean changed = false;
5455
List<J.Annotation> annotations = new ArrayList<>(m.getAnnotations());

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ visitors:
3232
- org.openrewrite.java.ChangeType:
3333
type: org.junit.Ignore
3434
targetType: org.junit.jupiter.api.Disabled
35+
- org.openrewrite.java.ChangeType:
36+
type: org.junit.Assume
37+
targetType: org.junit.jupiter.api.Assumptions
3538
---
3639
type: specs.openrewrite.org/v1beta/recipe
3740
name: org.openrewrite.java.testing.junit5.migration

0 commit comments

Comments
 (0)