Skip to content

Commit

Permalink
Remove unused static import fail in RemoveTryCatchFailBlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Mar 2, 2024
1 parent fe49228 commit 66c9a80
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ private J.MethodInvocation replaceWithAssertDoesNotThrowWithoutStringExpression(
}

private void maybeRemoveCatchTypes(J.Try try_) {
maybeRemoveImport("org.junit.jupiter.api.Assertions.fail");
JavaType catchType = try_.getCatches().get(0).getParameter().getTree().getType();
if (catchType != null) {
Stream.of(catchType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,44 @@ public void testMethod() {
);
}

@Test
void removeStaticImportFail() {
//language=java
rewriteRun(
java(
"""
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
class MyTest {
@Test
public void testMethod() {
try {
int divide = 50 / 0;
} catch (ArithmeticException e) {
fail(e.getMessage());
}
}
}
""",
"""
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class MyTest {
@Test
public void testMethod() {
Assertions.assertDoesNotThrow(() -> {
int divide = 50 / 0;
});
}
}
"""
)
);
}

@Test
void removeTryCatchBlockWithoutMessage() {
//language=java
Expand Down

0 comments on commit 66c9a80

Please sign in to comment.