Skip to content

Commit

Permalink
Add test on RemoveMethodInvocationsVisitor to remove static method
Browse files Browse the repository at this point in the history
  • Loading branch information
dralagen authored and jevanlingen committed Dec 10, 2024
1 parent 1095923 commit 3aae7a2
Showing 1 changed file with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Object> 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<Object> emptyList = Collections.emptyList();
}
}
""",
"""
class Test {
void method() {
}
}
"""
)
);
}
}

0 comments on commit 3aae7a2

Please sign in to comment.