@@ -181,4 +181,112 @@ public Collection<String> filterCollection(Collection<String> input) {
181181 )
182182 );
183183 }
184+
185+ @ Test
186+ void doNotChangeWhenUsingIteratorsFilter () {
187+ // Iterators.filter requires Guava Predicate as last parameter
188+ rewriteRun (
189+ //language=java
190+ java (
191+ """
192+ import com.google.common.base.Predicate;
193+ import com.google.common.collect.Iterators;
194+
195+ import java.util.Iterator;
196+
197+ class Test {
198+ Predicate<Integer> isPositive = n -> n > 0;
199+
200+ public Iterator<Integer> filterPositive(Iterator<Integer> numbers) {
201+ return Iterators.filter(numbers, isPositive);
202+ }
203+ }
204+ """
205+ )
206+ );
207+ }
208+
209+ @ Test
210+ void doNotChangeWhenUsingIterablesAny () {
211+ // Iterables.any requires Guava Predicate as last parameter
212+ rewriteRun (
213+ //language=java
214+ java (
215+ """
216+ import com.google.common.base.Predicate;
217+ import com.google.common.collect.Iterables;
218+ import java.util.List;
219+
220+ class Test {
221+ public boolean any(List<Integer> input, Predicate<Integer> aPredicate) {
222+ return Iterables.any(input, aPredicate);
223+ }
224+ }
225+ """
226+ )
227+ );
228+ }
229+
230+ @ Test
231+ void doNotChangeWhenUsingMapsFilterEntries () {
232+ // Maps.filterEntries requires Guava Predicate as last parameter
233+ rewriteRun (
234+ //language=java
235+ java (
236+ """
237+ import com.google.common.base.Predicate;
238+ import com.google.common.collect.Maps;
239+ import java.util.Map;
240+
241+ class Test {
242+ public Map<String, String> filterMap(Map<String, String> input, Predicate<Map.Entry<String,String>> aPredicate) {
243+ return Maps.filterEntries(input, aPredicate);
244+ }
245+ }
246+ """
247+ )
248+ );
249+ }
250+
251+ @ Test
252+ void doNotChangeWhenUsingMapsFilterValues () {
253+ // Maps.filterValues requires Guava Predicate as last parameter
254+ rewriteRun (
255+ //language=java
256+ java (
257+ """
258+ import com.google.common.base.Predicate;
259+ import com.google.common.collect.Maps;
260+ import java.util.Map;
261+
262+ class Test {
263+ public Map<String, String> filterMap(Map<String, String> input, Predicate<String> aPredicate) {
264+ return Maps.filterValues(input, aPredicate);
265+ }
266+ }
267+ """
268+ )
269+ );
270+ }
271+
272+ @ Test
273+ void doNotChangeWhenUsingMapsFilterKeys () {
274+ // Maps.filterKeys requires Guava Predicate as last parameter
275+ rewriteRun (
276+ //language=java
277+ java (
278+ """
279+ import com.google.common.base.Predicate;
280+ import com.google.common.collect.Maps;
281+ import java.util.Map;
282+
283+ class Test {
284+ public Map<String, String> filterMap(Map<String, String> input, Predicate<String> aPredicate) {
285+ return Maps.filterKeys(input, aPredicate);
286+ }
287+ }
288+ """
289+ )
290+ );
291+ }
184292}
0 commit comments