File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
main/java/org/openrewrite/java/testing/junit5
test/java/org/openrewrite/java/testing/junit5 Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments