diff --git a/src/main/resources/META-INF/rewrite/no-guava.yml b/src/main/resources/META-INF/rewrite/no-guava.yml index f7fc849c8e..5a0fd006ee 100644 --- a/src/main/resources/META-INF/rewrite/no-guava.yml +++ b/src/main/resources/META-INF/rewrite/no-guava.yml @@ -161,6 +161,10 @@ tags: - guava - RSPEC-S4738 recipeList: + - org.openrewrite.java.ChangeMethodName: + methodPattern: com.google.common.base.Predicate apply(..) + newMethodName: test + matchOverrides: true - org.openrewrite.java.ChangeType: oldFullyQualifiedTypeName: com.google.common.base.Predicate newFullyQualifiedTypeName: java.util.function.Predicate diff --git a/src/test/java/org/openrewrite/java/migrate/guava/PreferJavaUtilPredicateTest.java b/src/test/java/org/openrewrite/java/migrate/guava/PreferJavaUtilPredicateTest.java new file mode 100644 index 0000000000..5728d44199 --- /dev/null +++ b/src/test/java/org/openrewrite/java/migrate/guava/PreferJavaUtilPredicateTest.java @@ -0,0 +1,70 @@ +/* + * Copyright 2024 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java.migrate.guava; + +import org.junit.jupiter.api.Test; +import org.openrewrite.DocumentExample; +import org.openrewrite.java.JavaParser; +import org.openrewrite.test.RecipeSpec; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.java.Assertions.java; + +class PreferJavaUtilPredicateTest implements RewriteTest { + @Override + public void defaults(RecipeSpec spec) { + spec.recipeFromResources("org.openrewrite.java.migrate.guava.PreferJavaUtilPredicate") + .parser(JavaParser.fromJavaVersion().classpath("guava")); + } + + @DocumentExample + @Test + void changeTypeAndMethodName() { + rewriteRun( + //language=java + java( + """ + import com.google.common.base.Predicate; + + class A { + public static Predicate makeStringPredicate() { + return new Predicate() { + @Override + public boolean apply(String input) { + return input.isEmpty(); + } + }; + } + } + """, + """ + import java.util.function.Predicate; + + class A { + public static Predicate makeStringPredicate() { + return new Predicate() { + @Override + public boolean test(String input) { + return input.isEmpty(); + } + }; + } + } + """ + ) + ); + } +}