From 8e001a92c6c9097494db3ac21d70474dcfd2f7ca Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 18 Aug 2024 12:03:49 +0200 Subject: [PATCH] Do not register a conflict for qualified method calls --- .../testing/cleanup/RemoveTestPrefix.java | 2 +- .../testing/cleanup/RemoveTestPrefixTest.java | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefix.java b/src/main/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefix.java index 2cb18b734..30142e99f 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefix.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefix.java @@ -127,7 +127,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, new JavaIsoVisitor() { @Override public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, AtomicBoolean atomicBoolean) { - if (method.getName().getSimpleName().equals(newMethodName)) { + if (method.getName().getSimpleName().equals(newMethodName) && method.getSelect() == null) { skip.set(true); } return super.visitMethodInvocation(method, atomicBoolean); diff --git a/src/test/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefixTest.java b/src/test/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefixTest.java index 6cdeae91a..aa7e8e238 100644 --- a/src/test/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefixTest.java +++ b/src/test/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefixTest.java @@ -327,7 +327,7 @@ void tests() { @Test @Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/258") - void removeTestPrefixWithClashingMethod() { + void ignoreWhenStaticImportConflicts() { rewriteRun( //language=java java( @@ -345,4 +345,36 @@ void testOf() { ) ); } + + @Test + @Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/258") + void removeOnQualifiedMethodDespiteConflict() { + rewriteRun( + //language=java + java( + """ + import org.junit.jupiter.api.Test; + import java.util.List; + + class FooTest { + @Test + void testOf() { + List.of(); + } + } + """, + """ + import org.junit.jupiter.api.Test; + import java.util.List; + + class FooTest { + @Test + void of() { + List.of(); + } + } + """ + ) + ); + } }