From 7ed5e3444466bc86efe0f4660da5c648b62a423d Mon Sep 17 00:00:00 2001 From: Laurent Redor Date: Sun, 26 Oct 2025 11:05:26 +0100 Subject: [PATCH] Add more tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the Sirius codebase, I had identified other errors of the same kind for which I hadn’t yet created an issue. I’ve added the corresponding cases to the NoGuavaPredicateTest tests. --- .../migrate/guava/NoGuavaPredicateTest.java | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/src/test/java/org/openrewrite/java/migrate/guava/NoGuavaPredicateTest.java b/src/test/java/org/openrewrite/java/migrate/guava/NoGuavaPredicateTest.java index 17b878562a..b621cd1ccd 100644 --- a/src/test/java/org/openrewrite/java/migrate/guava/NoGuavaPredicateTest.java +++ b/src/test/java/org/openrewrite/java/migrate/guava/NoGuavaPredicateTest.java @@ -181,4 +181,112 @@ public Collection filterCollection(Collection input) { ) ); } + + @Test + void doNotChangeWhenUsingIteratorsFilter() { + // Iterators.filter requires Guava Predicate as last parameter + rewriteRun( + //language=java + java( + """ + import com.google.common.base.Predicate; + import com.google.common.collect.Iterators; + + import java.util.Iterator; + + class Test { + Predicate isPositive = n -> n > 0; + + public Iterator filterPositive(Iterator numbers) { + return Iterators.filter(numbers, isPositive); + } + } + """ + ) + ); + } + + @Test + void doNotChangeWhenUsingIterablesAny() { + // Iterables.any requires Guava Predicate as last parameter + rewriteRun( + //language=java + java( + """ + import com.google.common.base.Predicate; + import com.google.common.collect.Iterables; + import java.util.List; + + class Test { + public boolean any(List input, Predicate aPredicate) { + return Iterables.any(input, aPredicate); + } + } + """ + ) + ); + } + + @Test + void doNotChangeWhenUsingMapsFilterEntries() { + // Maps.filterEntries requires Guava Predicate as last parameter + rewriteRun( + //language=java + java( + """ + import com.google.common.base.Predicate; + import com.google.common.collect.Maps; + import java.util.Map; + + class Test { + public Map filterMap(Map input, Predicate> aPredicate) { + return Maps.filterEntries(input, aPredicate); + } + } + """ + ) + ); + } + + @Test + void doNotChangeWhenUsingMapsFilterValues() { + // Maps.filterValues requires Guava Predicate as last parameter + rewriteRun( + //language=java + java( + """ + import com.google.common.base.Predicate; + import com.google.common.collect.Maps; + import java.util.Map; + + class Test { + public Map filterMap(Map input, Predicate aPredicate) { + return Maps.filterValues(input, aPredicate); + } + } + """ + ) + ); + } + + @Test + void doNotChangeWhenUsingMapsFilterKeys() { + // Maps.filterKeys requires Guava Predicate as last parameter + rewriteRun( + //language=java + java( + """ + import com.google.common.base.Predicate; + import com.google.common.collect.Maps; + import java.util.Map; + + class Test { + public Map filterMap(Map input, Predicate aPredicate) { + return Maps.filterKeys(input, aPredicate); + } + } + """ + ) + ); + } }