Skip to content

Commit 66c9a80

Browse files
committed
Remove unused static import fail in RemoveTryCatchFailBlocks
1 parent fe49228 commit 66c9a80

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/main/java/org/openrewrite/java/testing/junit5/RemoveTryCatchFailBlocks.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ private J.MethodInvocation replaceWithAssertDoesNotThrowWithoutStringExpression(
127127
}
128128

129129
private void maybeRemoveCatchTypes(J.Try try_) {
130+
maybeRemoveImport("org.junit.jupiter.api.Assertions.fail");
130131
JavaType catchType = try_.getCatches().get(0).getParameter().getTree().getType();
131132
if (catchType != null) {
132133
Stream.of(catchType)

src/test/java/org/openrewrite/java/testing/junit5/RemoveTryCatchFailBlocksTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,44 @@ public void testMethod() {
7373
);
7474
}
7575

76+
@Test
77+
void removeStaticImportFail() {
78+
//language=java
79+
rewriteRun(
80+
java(
81+
"""
82+
import org.junit.jupiter.api.Test;
83+
84+
import static org.junit.jupiter.api.Assertions.fail;
85+
86+
class MyTest {
87+
@Test
88+
public void testMethod() {
89+
try {
90+
int divide = 50 / 0;
91+
} catch (ArithmeticException e) {
92+
fail(e.getMessage());
93+
}
94+
}
95+
}
96+
""",
97+
"""
98+
import org.junit.jupiter.api.Assertions;
99+
import org.junit.jupiter.api.Test;
100+
101+
class MyTest {
102+
@Test
103+
public void testMethod() {
104+
Assertions.assertDoesNotThrow(() -> {
105+
int divide = 50 / 0;
106+
});
107+
}
108+
}
109+
"""
110+
)
111+
);
112+
}
113+
76114
@Test
77115
void removeTryCatchBlockWithoutMessage() {
78116
//language=java

0 commit comments

Comments
 (0)