diff --git a/src/main/resources/META-INF/rewrite/junit5.yml b/src/main/resources/META-INF/rewrite/junit5.yml
index e54d2acfa..2ed727614 100755
--- a/src/main/resources/META-INF/rewrite/junit5.yml
+++ b/src/main/resources/META-INF/rewrite/junit5.yml
@@ -102,21 +102,7 @@ recipeList:
- org.openrewrite.java.dependencies.RemoveDependency:
groupId: junit
artifactId: junit
- - org.openrewrite.maven.ExcludeDependency:
- groupId: junit
- artifactId: junit
- # Workaround for https://github.com/testcontainers/testcontainers-java/issues/970:
- - org.openrewrite.maven.RemoveExclusion:
- groupId: org.testcontainers
- artifactId: '*'
- exclusionGroupId: junit
- exclusionArtifactId: junit
- # Similar for https://github.com/openrewrite/rewrite-testing-frameworks/issues/477
- - org.openrewrite.maven.RemoveExclusion:
- groupId: org.springframework.boot
- artifactId: spring-boot-testcontainers
- exclusionGroupId: junit
- exclusionArtifactId: junit
+ - org.openrewrite.java.testing.junit5.ExcludeJUnit4UnlessUsingTestcontainers
- org.openrewrite.java.dependencies.RemoveDependency:
groupId: org.junit.vintage
artifactId: junit-vintage-engine
@@ -145,7 +131,19 @@ recipeList:
newFullyQualifiedTypeName: org.jbehave.core.junit.JupiterStories
- org.openrewrite.java.testing.arquillian.ArquillianJUnit4ToArquillianJUnit5
- org.openrewrite.java.testing.dbrider.MigrateDbRiderSpringToDbRiderJUnit5
-
+---
+type: specs.openrewrite.org/v1beta/recipe
+name: org.openrewrite.java.testing.junit5.ExcludeJUnit4UnlessUsingTestcontainers
+displayName: Exclude JUnit 4, unless Testcontainers is used
+description: Excludes JUnit 4, as it ought not to be necessary in a JUnit 5 project, unless Testcontainers is used.
+preconditions:
+ - org.openrewrite.maven.search.DoesNotIncludeDependency:
+ groupId: org.testcontainers
+ artifactId: '*'
+recipeList:
+ - org.openrewrite.maven.ExcludeDependency:
+ groupId: junit
+ artifactId: junit
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.testing.junit5.UseHamcrestAssertThat
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 586d9352b..aed1616df 100644
--- a/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java
+++ b/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java
@@ -157,95 +157,170 @@ void upgradeMavenPluginVersions() {
);
}
+ @Test
+ void excludeJunit4Dependency() {
+ // Just using play-test_2.13 as an example because it appears to still depend on junit.
+ // In practice, this would probably just break it, I assume.
+ //language=xml
+ rewriteRun(
+ pomXml(
+ """
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 3.2.1
+
+
+ dev.ted
+ needs-exclusion
+ 0.0.1
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ com.typesafe.play
+ play-test_2.13
+ 2.9.6
+ test
+
+
+
+ """,
+ """
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 3.2.1
+
+
+ dev.ted
+ needs-exclusion
+ 0.0.1
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ com.typesafe.play
+ play-test_2.13
+ 2.9.6
+ test
+
+
+ junit
+ junit
+
+
+
+
+
+ """
+ )
+ );
+ }
+
@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/429")
- void dontExcludeJunit4DependencyfromTestcontainers() {
+ void dontExcludeJunit4DependencyFromTestcontainers() {
//language=xml
- String before = """
-
- 4.0.0
- com.example.jackson
- test-plugins
- 1.0.0
-
-
- org.testcontainers
- testcontainers
- 1.18.3
- test
-
-
-
- """;
- // Output identical, but we want to make sure we don't exclude junit4 from testcontainers
- rewriteRun(pomXml(before, before));
+ rewriteRun(
+ pomXml(
+ """
+
+ 4.0.0
+ com.example.jackson
+ test-plugins
+ 1.0.0
+
+
+ org.testcontainers
+ testcontainers
+ 1.18.3
+ test
+
+
+
+ """
+ )
+ );
}
@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/429")
- void dontExcludeJunit4DependencyfromTestcontainersJupiter() {
+ 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));
+ rewriteRun(
+ pomXml(
+ """
+
+ 4.0.0
+ com.example.jackson
+ test-plugins
+ 1.0.0
+
+
+ org.testcontainers
+ junit-jupiter
+ 1.18.3
+ test
+
+
+
+ """
+ )
+ );
}
@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/477")
- void dontExcludeJunit4DependencyfromSpringBootTestcontainers() {
- //language=xml
- String before = """
-
- 4.0.0
-
- org.springframework.boot
- spring-boot-starter-parent
- 3.2.1
-
-
- dev.ted
- testcontainer-migrate
- 0.0.1
-
-
- org.springframework.boot
- spring-boot-starter
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
+ void dontExcludeJunit4DependencyFromSpringBootTestcontainers() {
+ rewriteRun(
+ //language=xml
+ pomXml(
+ """
+
+ 4.0.0
+
org.springframework.boot
- spring-boot-testcontainers
- test
-
-
- org.testcontainers
- junit-jupiter
- test
-
-
-
- """;
- // Output identical, but we want to make sure we don't exclude junit4 from testcontainers
- rewriteRun(pomXml(before, before));
+ spring-boot-starter-parent
+ 3.2.1
+
+
+ dev.ted
+ testcontainer-migrate
+ 0.0.1
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.boot
+ spring-boot-testcontainers
+ test
+
+
+ org.testcontainers
+ junit-jupiter
+ test
+
+
+
+ """
+ )
+ );
}
// edge case for deprecated use of assertEquals