Skip to content

Commit

Permalink
Also change Guava Predicate method name (#473)
Browse files Browse the repository at this point in the history
* Also change Guava Predicate method name

Fixes #435

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
timtebeek and github-actions[bot] authored May 6, 2024
1 parent c82c73a commit 3897b37
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/rewrite/no-guava.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2024 the original author or authors.
* <p>
* 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
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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<String> makeStringPredicate() {
return new Predicate<String>() {
@Override
public boolean apply(String input) {
return input.isEmpty();
}
};
}
}
""",
"""
import java.util.function.Predicate;
class A {
public static Predicate<String> makeStringPredicate() {
return new Predicate<String>() {
@Override
public boolean test(String input) {
return input.isEmpty();
}
};
}
}
"""
)
);
}
}

0 comments on commit 3897b37

Please sign in to comment.