Skip to content

Commit 7574b2f

Browse files
refactor: Use method references in lambda
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.staticanalysis.ReplaceLambdaWithMethodReference?organizationId=T3BlblJld3JpdGU%3D Co-authored-by: Moderne <[email protected]>
1 parent 7ba17bb commit 7574b2f

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Atomi
165165
}
166166

167167
private boolean methodInvocationInBodyContainsAssertion() {
168-
J.ClassDeclaration classDeclaration = getCursor().dropParentUntil(is -> is instanceof J.ClassDeclaration).getValue();
168+
J.ClassDeclaration classDeclaration = getCursor().dropParentUntil(org.openrewrite.java.tree.J.ClassDeclaration.class::isInstance).getValue();
169169

170170
JavaIsoVisitor<Set<MethodMatcher>> findMethodDeclarationsVisitor = new JavaIsoVisitor<Set<MethodMatcher>>() {
171171
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ public ClassDeclaration visitClassDeclaration(ClassDeclaration classDecl, Execut
8787
&& c.getModifiers().stream().noneMatch(mod -> mod.getType() == Type.Abstract)) {
8888

8989
boolean hasTestMethods = c.getBody().getStatements().stream()
90-
.filter(statement -> statement instanceof J.MethodDeclaration)
90+
.filter(org.openrewrite.java.tree.J.MethodDeclaration.class::isInstance)
9191
.map(J.MethodDeclaration.class::cast)
9292
.anyMatch(this::hasJUnit5MethodAnnotation);
9393

9494
boolean hasPublicNonTestMethods = c.getBody().getStatements().stream()
95-
.filter(statement -> statement instanceof J.MethodDeclaration)
95+
.filter(org.openrewrite.java.tree.J.MethodDeclaration.class::isInstance)
9696
.map(J.MethodDeclaration.class::cast)
9797
.filter(m -> m.getModifiers().stream().anyMatch(mod -> mod.getType() == J.Modifier.Type.Public))
9898
.anyMatch(method -> !hasJUnit5MethodAnnotation(method));
9999

100100
boolean hasPublicVariableDeclarations = c.getBody().getStatements().stream()
101-
.filter(statement -> statement instanceof J.VariableDeclarations)
101+
.filter(org.openrewrite.java.tree.J.VariableDeclarations.class::isInstance)
102102
.map(J.VariableDeclarations.class::cast)
103103
.anyMatch(m -> m.getModifiers().stream().anyMatch(mod -> mod.getType() == J.Modifier.Type.Public));
104104

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
7171
String initMethodName = "init" + cd.getSimpleName();
7272

7373
// Constructor Injected Test
74-
if (parametersMethodName != null && constructorParams != null && constructorParams.stream().anyMatch(p -> p instanceof J.VariableDeclarations)) {
74+
if (parametersMethodName != null && constructorParams != null && constructorParams.stream().anyMatch(org.openrewrite.java.tree.J.VariableDeclarations.class::isInstance)) {
7575
doAfterVisit(new ParameterizedRunnerToParameterizedTestsVisitor(classDecl, parametersMethodName, initMethodName, parametersAnnotationArguments, constructorParams, true, ctx));
7676
}
7777

0 commit comments

Comments
 (0)