diff --git a/src/main/resources/META-INF/rewrite/junit5.yml b/src/main/resources/META-INF/rewrite/junit5.yml index b4a71a983..481a4d71d 100755 --- a/src/main/resources/META-INF/rewrite/junit5.yml +++ b/src/main/resources/META-INF/rewrite/junit5.yml @@ -106,7 +106,7 @@ recipeList: # Workaround for https://github.com/testcontainers/testcontainers-java/issues/970: - org.openrewrite.maven.RemoveExclusion: groupId: org.testcontainers - artifactId: testcontainers + artifactId: '*' exclusionGroupId: junit exclusionArtifactId: junit # Similar for https://github.com/openrewrite/rewrite-testing-frameworks/issues/477 diff --git a/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java b/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java index 17478e64c..71752bbb3 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java @@ -55,7 +55,7 @@ void classReference() { java( """ import org.junit.Test; - + public class Sample { void method() { Class c = Test.class; @@ -64,7 +64,7 @@ void method() { """, """ import org.junit.jupiter.api.Test; - + public class Sample { void method() { Class c = Test.class; @@ -85,10 +85,10 @@ void assertThatReceiver() { """ import org.junit.Assert; import org.junit.Test; - + import static java.util.Arrays.asList; import static org.hamcrest.Matchers.containsInAnyOrder; - + public class SampleTest { @SuppressWarnings("ALL") @Test @@ -100,11 +100,11 @@ public void filterShouldRemoveUnusedConfig() { """, """ import org.junit.jupiter.api.Test; - + import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; - + public class SampleTest { @SuppressWarnings("ALL") @Test @@ -178,6 +178,30 @@ void dontExcludeJunit4DependencyfromTestcontainers() { rewriteRun(pomXml(before, before)); } + @Test + @Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/429") + void dontExcludeJunit4DependencyfromTestcontainersJupiter() { + //language=xml + String before = """ + + 4.0.0 + com.example.jackson + test-plugins + 1.0.0 + + + org.testcontainers + junit-jupiter + 1.18.3 + test + + + + """; + // Output identical, but we want to make sure we don't exclude junit4 from testcontainers + rewriteRun(pomXml(before, before)); + } + @Test @Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/477") void dontExcludeJunit4DependencyfromSpringBootTestcontainers() { @@ -231,7 +255,7 @@ void assertEqualsWithArrayArgumentToAssertArrayEquals() { java( """ import org.junit.Assert; - + class MyTest { void test() { Assert.assertEquals(new Object[1], new Object[1]); @@ -240,7 +264,7 @@ void test() { """, """ import org.junit.jupiter.api.Assertions; - + class MyTest { void test() { Assertions.assertArrayEquals(new Object[1], new Object[1]); @@ -261,16 +285,16 @@ void migrateInheritedTestBeforeAfterAnnotations() { import org.junit.After; import org.junit.Before; import org.junit.Test; - + public class AbstractTest { @Before public void before() { } - + @After public void after() { } - + @Test public void test() { } @@ -280,16 +304,16 @@ public void test() { import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - + public class AbstractTest { @BeforeEach public void before() { } - + @AfterEach public void after() { } - + @Test public void test() { } @@ -301,10 +325,10 @@ public void test() { public class A extends AbstractTest { public void before() { } - + public void after() { } - + public void test() { } } @@ -313,16 +337,16 @@ public void test() { import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; - + public class A extends AbstractTest { @BeforeEach public void before() { } - + @AfterEach public void after() { } - + @Test public void test() { }