From 3aae7a2cc06722559d8fc9600bbcce7b7ab9af50 Mon Sep 17 00:00:00 2001 From: dralagen Date: Fri, 6 Dec 2024 15:52:32 +0100 Subject: [PATCH] Add test on RemoveMethodInvocationsVisitor to remove static method --- .../RemoveMethodInvocationsVisitorTest.java | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/rewrite-java/src/test/java/org/openrewrite/java/RemoveMethodInvocationsVisitorTest.java b/rewrite-java/src/test/java/org/openrewrite/java/RemoveMethodInvocationsVisitorTest.java index c94f455eb16..07d3c75d1b9 100644 --- a/rewrite-java/src/test/java/org/openrewrite/java/RemoveMethodInvocationsVisitorTest.java +++ b/rewrite-java/src/test/java/org/openrewrite/java/RemoveMethodInvocationsVisitorTest.java @@ -15,13 +15,14 @@ */ package org.openrewrite.java; +import java.util.List; + import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.ExpectedToFail; import org.openrewrite.DocumentExample; import org.openrewrite.Recipe; import org.openrewrite.test.RewriteTest; -import java.util.List; import static org.openrewrite.java.Assertions.java; import static org.openrewrite.test.RewriteTest.toRecipe; @@ -492,4 +493,54 @@ public void method() { ) ); } + + @Test + void removeStaticMethodFromImport() { + rewriteRun( + spec -> spec.recipe(createRemoveMethodsRecipe("java.util.Collections emptyList()")), + // language=java + java( + """ + import static java.util.Collections.emptyList; + + class Test { + void method() { + List emptyList = emptyList(); + } + } + """, + """ + class Test { + void method() { + } + } + """ + ) + ); + } + + @Test + void removeStaticMethod() { + rewriteRun( + spec -> spec.recipe(createRemoveMethodsRecipe("java.util.Collections emptyList()")), + // language=java + java( + """ + import java.util.Collections; + + class Test { + void method() { + List emptyList = Collections.emptyList(); + } + } + """, + """ + class Test { + void method() { + } + } + """ + ) + ); + } }