Skip to content

Commit 3ef1f2c

Browse files
refactor: format java code (#161)
Co-authored-by: Moderne <[email protected]> Co-authored-by: Moderne <[email protected]>
1 parent ebb5471 commit 3ef1f2c

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/main/java/org/openrewrite/java/testing/cleanup/TestsShouldNotBePublic.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,23 @@ public ClassDeclaration visitClassDeclaration(ClassDeclaration classDecl, Execut
5757
ClassDeclaration c = super.visitClassDeclaration(classDecl, executionContext);
5858

5959
if (c.getModifiers().stream().anyMatch(mod -> mod.getType() == J.Modifier.Type.Public)
60-
&& c.getModifiers().stream().noneMatch(mod -> mod.getType() == Type.Abstract)) {
60+
&& c.getModifiers().stream().noneMatch(mod -> mod.getType() == Type.Abstract)) {
6161

6262
boolean hasTestMethods = c.getBody().getStatements().stream()
63-
.filter(statement -> statement instanceof J.MethodDeclaration)
64-
.map(J.MethodDeclaration.class::cast)
65-
.anyMatch(this::hasJUnit5MethodAnnotation);
63+
.filter(statement -> statement instanceof J.MethodDeclaration)
64+
.map(J.MethodDeclaration.class::cast)
65+
.anyMatch(this::hasJUnit5MethodAnnotation);
6666

6767
boolean hasPublicNonTestMethods = c.getBody().getStatements().stream()
68-
.filter(statement -> statement instanceof J.MethodDeclaration)
69-
.map(J.MethodDeclaration.class::cast)
70-
.filter(m -> m.getModifiers().stream().anyMatch(mod -> mod.getType() == J.Modifier.Type.Public))
71-
.anyMatch(method -> !hasJUnit5MethodAnnotation(method));
68+
.filter(statement -> statement instanceof J.MethodDeclaration)
69+
.map(J.MethodDeclaration.class::cast)
70+
.filter(m -> m.getModifiers().stream().anyMatch(mod -> mod.getType() == J.Modifier.Type.Public))
71+
.anyMatch(method -> !hasJUnit5MethodAnnotation(method));
7272

7373
boolean hasPublicVariableDeclarations = c.getBody().getStatements().stream()
74-
.filter(statement -> statement instanceof J.VariableDeclarations)
75-
.map(J.VariableDeclarations.class::cast)
76-
.anyMatch(m -> m.getModifiers().stream().anyMatch(mod -> mod.getType() == J.Modifier.Type.Public));
74+
.filter(statement -> statement instanceof J.VariableDeclarations)
75+
.map(J.VariableDeclarations.class::cast)
76+
.anyMatch(m -> m.getModifiers().stream().anyMatch(mod -> mod.getType() == J.Modifier.Type.Public));
7777

7878
if (hasTestMethods && !hasPublicNonTestMethods && !hasPublicVariableDeclarations) {
7979
// Remove public modifier and move associated comment
@@ -107,7 +107,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
107107
J.MethodDeclaration m = super.visitMethodDeclaration(method, executionContext);
108108

109109
if (m.getModifiers().stream().anyMatch(mod -> mod.getType() == J.Modifier.Type.Public)
110-
&& hasJUnit5MethodAnnotation(m)) {
110+
&& hasJUnit5MethodAnnotation(m)) {
111111
// remove public modifier
112112
doAfterVisit(new ChangeMethodAccessLevelVisitor<>(new MethodMatcher(method), null));
113113
}
@@ -118,11 +118,11 @@ && hasJUnit5MethodAnnotation(m)) {
118118
private boolean hasJUnit5MethodAnnotation(MethodDeclaration method) {
119119
for (J.Annotation a : method.getLeadingAnnotations()) {
120120
if (TypeUtils.isOfClassType(a.getType(), "org.junit.jupiter.api.Test")
121-
|| TypeUtils.isOfClassType(a.getType(), "org.junit.jupiter.api.RepeatedTest")
122-
|| TypeUtils.isOfClassType(a.getType(), "org.junit.jupiter.params.ParameterizedTest")
123-
|| TypeUtils.isOfClassType(a.getType(), "org.junit.jupiter.api.TestFactory")
124-
|| TypeUtils.isOfClassType(a.getType(), "org.junit.jupiter.api.AfterEach")
125-
|| TypeUtils.isOfClassType(a.getType(), "org.junit.jupiter.api.BeforeEach")) {
121+
|| TypeUtils.isOfClassType(a.getType(), "org.junit.jupiter.api.RepeatedTest")
122+
|| TypeUtils.isOfClassType(a.getType(), "org.junit.jupiter.params.ParameterizedTest")
123+
|| TypeUtils.isOfClassType(a.getType(), "org.junit.jupiter.api.TestFactory")
124+
|| TypeUtils.isOfClassType(a.getType(), "org.junit.jupiter.api.AfterEach")
125+
|| TypeUtils.isOfClassType(a.getType(), "org.junit.jupiter.api.BeforeEach")) {
126126
return true;
127127
}
128128
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public ParameterizedRunnerToParameterizedTestsVisitor(String parametersMethodNam
211211
@Override
212212
public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext executionContext) {
213213
J.CompilationUnit c = super.visitCompilationUnit(cu, executionContext);
214-
if(c != cu) {
214+
if (c != cu) {
215215
doAfterVisit(new RemoveAnnotationVisitor(PARAMETERS));
216216
doAfterVisit(new RemoveAnnotationVisitor(PARAMETER));
217217
doAfterVisit(new RemoveAnnotationVisitor(RUN_WITH_PARAMETERS));

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

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
168168
}).map(J.MethodDeclaration::getType).findAny().orElse(null);
169169

170170
if (newFolderMethodDeclaration == null) {
171-
cd = cd.withTemplate(JavaTemplate.builder(this::getCursor,
171+
cd = cd.withTemplate(JavaTemplate.builder(this::getCursor,
172172
"private static File newFolder(File root, String... subDirs) throws IOException {\n" +
173173
" String subFolder = String.join(\"/\", subDirs);\n" +
174174
" File result = new File(root, subFolder);\n" +

0 commit comments

Comments
 (0)