Skip to content

Commit

Permalink
Updated ChangeType to the latest version of rewrite.
Browse files Browse the repository at this point in the history
  • Loading branch information
traceyyoshima committed Feb 25, 2022
1 parent 90e2f6c commit 78bbbbc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionCon
J.CompilationUnit c = super.visitCompilationUnit(cu, executionContext);
doAfterVisit(new TestCaseVisitor());
// ChangeType for org.junit.Assert method invocations because TestCase extends org.junit.Assert
doAfterVisit(new ChangeType("junit.framework.TestCase", "org.junit.Assert"));
doAfterVisit(new ChangeType("junit.framework.TestCase", "org.junit.Assert", true));
doAfterVisit(new AssertToAssertions.AssertToAssertionsVisitor());
doAfterVisit(new UseStaticImport("org.junit.jupiter.api.Assertions assert*(..)"));
doAfterVisit(new UseStaticImport("org.junit.jupiter.api.Assertions fail*(..)"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static class TemporaryFolderToTempDirVisitor extends JavaVisitor<Executi
public J visitCompilationUnit(J.CompilationUnit cu, ExecutionContext executionContext) {
J.CompilationUnit c = (J.CompilationUnit) super.visitCompilationUnit(cu, executionContext);
if (c != cu) {
doAfterVisit(new ChangeType("org.junit.rules.TemporaryFolder", "java.io.File"));
doAfterVisit(new ChangeType("org.junit.rules.TemporaryFolder", "java.io.File", true));
maybeAddImport("java.io.File");
maybeAddImport("org.junit.jupiter.api.io.TempDir");
maybeRemoveImport("org.junit.ClassRule");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext execu
return mi;
}
});
doAfterVisit(new ChangeType("org.junit.rules.TestName", "String"));
doAfterVisit(new ChangeType("org.junit.Before", "org.junit.jupiter.api.BeforeEach"));
doAfterVisit(new ChangeType("org.junit.rules.TestName", "String", true));
doAfterVisit(new ChangeType("org.junit.Before", "org.junit.jupiter.api.BeforeEach", true));
return compilationUnit;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public static class UpdateBeforeAfterAnnotationsVisitor extends JavaIsoVisitor<E
public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) {
//This visitor handles changing the method visibility for any method annotated with one of the four before/after
//annotations. It registers visitors that will sweep behind it making the type changes.
doAfterVisit(new ChangeType("org.junit.Before", "org.junit.jupiter.api.BeforeEach"));
doAfterVisit(new ChangeType("org.junit.After", "org.junit.jupiter.api.AfterEach"));
doAfterVisit(new ChangeType("org.junit.BeforeClass", "org.junit.jupiter.api.BeforeAll"));
doAfterVisit(new ChangeType("org.junit.AfterClass", "org.junit.jupiter.api.AfterAll"));
doAfterVisit(new ChangeType("org.junit.Before", "org.junit.jupiter.api.BeforeEach", true));
doAfterVisit(new ChangeType("org.junit.After", "org.junit.jupiter.api.AfterEach", true));
doAfterVisit(new ChangeType("org.junit.BeforeClass", "org.junit.jupiter.api.BeforeAll", true));
doAfterVisit(new ChangeType("org.junit.AfterClass", "org.junit.jupiter.api.AfterAll", true));

return super.visitCompilationUnit(cu, ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected JavaVisitor<ExecutionContext> getVisitor() {
@Override
public J visitJavaSourceFile(JavaSourceFile cu, ExecutionContext context) {
doNext(new ChangeType("com.github.tomakehurst.wiremock.junit.WireMockRule",
"com.github.tomakehurst.wiremock.junit5.WireMockExtension"));
"com.github.tomakehurst.wiremock.junit5.WireMockExtension", true));
return super.visitJavaSourceFile(cu, context);
}

Expand All @@ -59,7 +59,7 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext executionContext) {
if (newWiremockRule.matches(n)) {
maybeAddImport("com.github.tomakehurst.wiremock.junit5.WireMockExtension");

doAfterVisit(new ChangeType("org.junit.Rule", "org.junit.jupiter.api.extension.RegisterExtension"));
doAfterVisit(new ChangeType("org.junit.Rule", "org.junit.jupiter.api.extension.RegisterExtension", true));

assert n.getArguments() != null;
Expression arg = n.getArguments().get(0);
Expand Down

0 comments on commit 78bbbbc

Please sign in to comment.