File tree Expand file tree Collapse file tree 2 files changed +64
-1
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 +64
-1
lines changed Original file line number Diff line number Diff line change @@ -154,7 +154,6 @@ private J.MethodInvocation replaceWithAssertDoesNotThrowWithStringExpression(Exe
154154 maybeAddImport ("org.junit.jupiter.api.Assertions" );
155155 maybeRemoveCatchTypes (try_ );
156156 return JavaTemplate .builder ("Assertions.assertDoesNotThrow(() -> #{any()}, #{any(String)})" )
157- .contextSensitive ()
158157 .imports ("org.junit.jupiter.api.Assertions" )
159158 .javaParser (JavaParser .fromJavaVersion ().classpathFromResources (ctx , "junit-jupiter-api-5" ))
160159 .build ()
Original file line number Diff line number Diff line change @@ -688,4 +688,68 @@ String getBar(boolean b) {
688688 )
689689 );
690690 }
691+
692+ @ Test
693+ @ Issue ("https://github.com/openrewrite/rewrite-testing-frameworks/issues/732" )
694+ void substitutionFailure () {
695+ //language=java
696+ rewriteRun (
697+ java (
698+ """
699+ import org.junit.jupiter.api.Assertions;
700+ import org.junit.jupiter.api.Test;
701+
702+ class MyTest {
703+ @Test
704+ void testCheckRole() throws InterruptedException {
705+ executeTest(new Runnable() {
706+ public void run() {
707+ Integer number = Integer.valueOf("10");
708+ try {
709+ System.out.println(number / 0);
710+ } catch (ArithmeticException ae) {
711+ Assertions.fail("division by zero");
712+ }
713+ }
714+ });
715+ }
716+
717+ private void executeTest(Runnable runnable) throws InterruptedException {
718+ }
719+
720+ private class SubClass {
721+ public void xyz() {
722+ }
723+ }
724+ }
725+ """ ,
726+ """
727+ import org.junit.jupiter.api.Assertions;
728+ import org.junit.jupiter.api.Test;
729+
730+ class MyTest {
731+ @Test
732+ void testCheckRole() throws InterruptedException {
733+ executeTest(new Runnable() {
734+ public void run() {
735+ Integer number = Integer.valueOf("10");
736+ Assertions.assertDoesNotThrow(() -> {
737+ System.out.println(number / 0);
738+ }, "division by zero");
739+ }
740+ });
741+ }
742+
743+ private void executeTest(Runnable runnable) throws InterruptedException {
744+ }
745+
746+ private class SubClass {
747+ public void xyz() {
748+ }
749+ }
750+ }
751+ """
752+ )
753+ );
754+ }
691755}
You can’t perform that action at this time.
0 commit comments