Skip to content

Commit 07afa11

Browse files
committed
Minor polish
1 parent 942e67c commit 07afa11

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaCollections2Filter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public Set<String> getTags() {
5050
@Override
5151
public TreeVisitor<?, ExecutionContext> getVisitor() {
5252
return Preconditions.check(
53-
new UsesMethod<>("com.google.common.collect.Collections2 filter(java.util.Collection, com.google.common.base.Predicate)"),
53+
new UsesMethod<>(COLLECTIONS2_FILTER),
5454
new JavaIsoVisitor<ExecutionContext>() {
5555
@Override
5656
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {

src/test/java/org/openrewrite/java/migrate/guava/NoGuavaCollections2FilterTest.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 the original author or authors.
2+
* Copyright 2025 the original author or authors.
33
* <p>
44
* Licensed under the Moderne Source Available License (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,37 +35,29 @@ public void defaults(RecipeSpec spec) {
3535

3636
@DocumentExample
3737
@Test
38-
void replaceSetsFilter() {
38+
void replaceCollections2Filter() {
3939
//language=java
4040
rewriteRun(
4141
java(
4242
"""
43-
import java.util.ArrayList;
4443
import java.util.Collection;
45-
import java.util.Objects;
4644
4745
import com.google.common.base.Predicate;
4846
import com.google.common.collect.Collections2;
4947
5048
class Test {
51-
public static Collection<Object> test() {
52-
Collection<Object> collection = new ArrayList<>();
53-
Predicate<Object> isNotNull = Objects::nonNull;
49+
Collection<Object> test(Collection<Object> collection, Predicate<Object> isNotNull) {
5450
return Collections2.filter(collection, isNotNull);
5551
}
5652
}
5753
""",
5854
"""
59-
import java.util.ArrayList;
6055
import java.util.Collection;
61-
import java.util.Objects;
6256
6357
import com.google.common.base.Predicate;
6458
6559
class Test {
66-
public static Collection<Object> test() {
67-
Collection<Object> collection = new ArrayList<>();
68-
Predicate<Object> isNotNull = Objects::nonNull;
60+
Collection<Object> test(Collection<Object> collection, Predicate<Object> isNotNull) {
6961
return collection.stream().filter(isNotNull).toList();
7062
}
7163
}

0 commit comments

Comments
 (0)