Skip to content

Commit 90e2f6c

Browse files
refactor: Format Java code (#189)
null Co-authored-by: Moderne <[email protected]> Co-authored-by: Moderne <[email protected]>
1 parent eb1bc3f commit 90e2f6c

File tree

8 files changed

+47
-45
lines changed

8 files changed

+47
-45
lines changed

src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThat.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public static class AssertArrayEqualsToAssertThatVisitor extends JavaIsoVisitor<
5959
private static final MethodMatcher JUNIT_ASSERT_EQUALS = new MethodMatcher(JUNIT_QUALIFIED_ASSERTIONS_CLASS_NAME + " assertArrayEquals(..)");
6060
private static final Supplier<JavaParser> ASSERTIONS_PARSER = () -> JavaParser.fromJavaVersion()
6161
.dependsOn(Parser.Input.fromResource("/META-INF/rewrite/AssertJAssertions.java", "---")).build();
62+
6263
@Override
6364
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
6465
if (!JUNIT_ASSERT_EQUALS.matches(method)) {

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,27 @@ protected TreeVisitor<?, ExecutionContext> getVisitor() {
6868
public static class ExpectedExceptionToAssertThrowsVisitor extends JavaIsoVisitor<ExecutionContext> {
6969
private static final Supplier<JavaParser> ASSERTIONS_PARSER = () ->
7070
JavaParser.fromJavaVersion().dependsOn(
71-
Stream.concat(
72-
Parser.Input.fromResource("/META-INF/rewrite/JupiterAssertions.java", "---").stream(),
73-
Stream.of(
74-
Parser.Input.fromString(
75-
"package org.junit.jupiter.api.function;" +
76-
"public interface Executable {" +
77-
"void execute() throws Throwable;" +
78-
"}"),
79-
Parser.Input.fromString(
80-
"package org.hamcrest;\n" +
81-
"public interface Matcher<T> {\n" +
82-
" boolean matches(Object var1);\n" +
83-
"}"),
84-
Parser.Input.fromString(
85-
"package org.hamcrest;\n" +
86-
"public class MatcherAssert {\n" +
87-
" public static <T> void assertThat(T actual, Matcher<? super T> matcher) {}\n" +
88-
" public static <T> void assertThat(String reason, T actual, Matcher<? super T> matcher) {}\n" +
89-
" public static void assertThat(String reason, boolean assertion) {}\n" +
90-
"}"))
91-
).collect(Collectors.toList())
71+
Stream.concat(
72+
Parser.Input.fromResource("/META-INF/rewrite/JupiterAssertions.java", "---").stream(),
73+
Stream.of(
74+
Parser.Input.fromString(
75+
"package org.junit.jupiter.api.function;" +
76+
"public interface Executable {" +
77+
"void execute() throws Throwable;" +
78+
"}"),
79+
Parser.Input.fromString(
80+
"package org.hamcrest;\n" +
81+
"public interface Matcher<T> {\n" +
82+
" boolean matches(Object var1);\n" +
83+
"}"),
84+
Parser.Input.fromString(
85+
"package org.hamcrest;\n" +
86+
"public class MatcherAssert {\n" +
87+
" public static <T> void assertThat(T actual, Matcher<? super T> matcher) {}\n" +
88+
" public static <T> void assertThat(String reason, T actual, Matcher<? super T> matcher) {}\n" +
89+
" public static void assertThat(String reason, boolean assertion) {}\n" +
90+
"}"))
91+
).collect(Collectors.toList())
9292
).build();
9393

9494
@Override

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ private J.MethodDeclaration updateMethodDeclarationAnnotationAndModifier(J.Metho
148148
if (FindAnnotations.find(methodDeclaration.withBody(null), "@" + fullyQualifiedAnnotation).isEmpty()) {
149149
md = methodDeclaration.withTemplate(JavaTemplate.builder(this::getCursor, annotation)
150150
.javaParser(() -> JavaParser.fromJavaVersion()
151-
.dependsOn(Collections.singletonList(Parser.Input.fromString(
152-
"package org.junit.jupiter.api;\n" +
153-
"public @interface Test {}\n" +
154-
"public @interface AfterEach {}\n" +
155-
"public @interface BeforeEach {}")))
156-
.build())
151+
.dependsOn(Collections.singletonList(Parser.Input.fromString(
152+
"package org.junit.jupiter.api;\n" +
153+
"public @interface Test {}\n" +
154+
"public @interface AfterEach {}\n" +
155+
"public @interface BeforeEach {}")))
156+
.build())
157157
.imports(fullyQualifiedAnnotation).build(),
158158
methodDeclaration.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName)));
159159
md = maybeAddPublicModifier(md);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
257257
cd.getBody().getCoordinates().lastStatement()));
258258
cd = cd.withBody(cd.getBody().withStatements(ListUtils.map(cd.getBody().getStatements(), stmt -> {
259259
if (stmt instanceof J.MethodDeclaration) {
260-
J.MethodDeclaration md = (J.MethodDeclaration)stmt;
260+
J.MethodDeclaration md = (J.MethodDeclaration) stmt;
261261
if (md.getName().getSimpleName().equals(initMethodName)) {
262262
return md.withParameters(parameterizedTestMethodParameters);
263263
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ public String getDescription() {
8686
protected TreeVisitor<?, ExecutionContext> getVisitor() {
8787
return new JavaIsoVisitor<ExecutionContext>() {
8888
private final JavaType.Class extensionType = JavaType.Class.build(extension);
89-
@Nullable private JavaTemplate extendsWithTemplate;
89+
@Nullable
90+
private JavaTemplate extendsWithTemplate;
9091
private JavaTemplate getExtendsWithTemplate() {
91-
if(extendsWithTemplate == null) {
92+
if (extendsWithTemplate == null) {
9293
extendsWithTemplate = JavaTemplate.builder(this::getCursor, "@ExtendWith(#{}.class)")
9394
.javaParser(() -> JavaParser.fromJavaVersion().dependsOn(Arrays.asList(
9495
fromString("package org.junit.jupiter.api.extension;\n" +

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
186186

187187
// Make sure the testName is initialized first in case any other piece of the method body references it
188188
assert md.getBody() != null;
189-
if(md.getBody().getStatements().size() > 2) {
189+
if (md.getBody().getStatements().size() > 2) {
190190
List<Statement> statements = md.getBody().getStatements();
191191
List<Statement> reorderedStatements = new ArrayList<>(statements.size());
192192
reorderedStatements.addAll(statements.subList(statements.size() - 2, statements.size()));

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
6161
m = (J.MethodDeclaration) new ChangeMethodAccessLevelVisitor<ExecutionContext>(new MethodMatcher(m), null)
6262
.visitNonNull(m, ctx, getCursor().getParentOrThrow());
6363
}
64-
if(cta.expectedException != null) {
64+
if (cta.expectedException != null) {
6565
m = m.withTemplate(JavaTemplate.builder(this::getCursor, "Object o = () -> #{}").build(),
6666
m.getCoordinates().replaceBody(),
6767
m.getBody());
@@ -74,7 +74,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
7474
lambda = lambda.withType(JavaType.Class.build("org.junit.jupiter.api.function.Executable"));
7575

7676
m = m.withTemplate(JavaTemplate.builder(this::getCursor,
77-
"assertThrows(#{any(java.lang.Class)}, #{any(org.junit.jupiter.api.function.Executable)});")
77+
"assertThrows(#{any(java.lang.Class)}, #{any(org.junit.jupiter.api.function.Executable)});")
7878
.javaParser(() -> JavaParser.fromJavaVersion()
7979
.dependsOn(
8080
"package org.junit.jupiter.api.function;" +
@@ -96,7 +96,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
9696
cta.expectedException, lambda);
9797
maybeAddImport("org.junit.jupiter.api.Assertions", "assertThrows");
9898
}
99-
if(cta.timeout != null) {
99+
if (cta.timeout != null) {
100100
m = m.withTemplate(
101101
JavaTemplate.builder(this::getCursor, "@Timeout(#{any(long)})")
102102
.javaParser(() -> JavaParser.fromJavaVersion()
@@ -137,7 +137,7 @@ public J.Annotation visitAnnotation(J.Annotation a, ExecutionContext context) {
137137
// While unlikely, it's possible that a method has an inner class/lambda/etc. with methods that have test annotations
138138
// Avoid considering any but the first test annotation found
139139
found = true;
140-
if(a.getArguments() != null) {
140+
if (a.getArguments() != null) {
141141
for (Expression arg : a.getArguments()) {
142142
if (!(arg instanceof J.Assignment)) {
143143
continue;

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext executionContext) {
6666

6767
Supplier<JavaParser> wiremockParser = () -> JavaParser.fromJavaVersion()
6868
.dependsOn("" +
69-
"package com.github.tomakehurst.wiremock.junit5;" +
70-
"import com.github.tomakehurst.wiremock.core.Options;" +
71-
"public class WireMockExtension {" +
72-
" public native static Builder newInstance();" +
73-
" public static class Builder {" +
74-
" public native Builder options(Options options);" +
75-
" public native Builder failOnUnmatchedRequests(boolean failOnUnmatched);" +
76-
" public native WireMockExtension build();" +
77-
" }" +
78-
"}",
69+
"package com.github.tomakehurst.wiremock.junit5;" +
70+
"import com.github.tomakehurst.wiremock.core.Options;" +
71+
"public class WireMockExtension {" +
72+
" public native static Builder newInstance();" +
73+
" public static class Builder {" +
74+
" public native Builder options(Options options);" +
75+
" public native Builder failOnUnmatchedRequests(boolean failOnUnmatched);" +
76+
" public native WireMockExtension build();" +
77+
" }" +
78+
"}",
7979
"" +
8080
"package com.github.tomakehurst.wiremock.core;" +
8181
"public class WireMockConfiguration implements Options {" +

0 commit comments

Comments
 (0)