From 0061cdc05c5d913130ab628121c37ac239cfbeaf Mon Sep 17 00:00:00 2001 From: Thomas IAPICHINO Date: Mon, 24 Nov 2025 17:18:25 +0100 Subject: [PATCH 1/2] Revert Testcontainers 2 migration from JUnit 4 to 5 recipe (#850) --- src/main/resources/META-INF/rewrite/junit5.yml | 9 ++++----- .../testing/junit5/JUnit5MigrationTest.java | 18 ++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main/resources/META-INF/rewrite/junit5.yml b/src/main/resources/META-INF/rewrite/junit5.yml index 64da7c226..2a631f8e4 100755 --- a/src/main/resources/META-INF/rewrite/junit5.yml +++ b/src/main/resources/META-INF/rewrite/junit5.yml @@ -130,14 +130,13 @@ recipeList: --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.java.testing.junit5.ExcludeJUnit4UnlessUsingTestcontainers -displayName: Exclude JUnit 4, unless Spring Boot Testcontainers is used -description: Excludes JUnit 4, as it ought not to be necessary in a JUnit 5 project, unless Testcontainers 1.x is used. +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.springframework.boot - artifactId: spring-boot-testcontainers + groupId: org.testcontainers + artifactId: '*' recipeList: - - org.openrewrite.java.testing.testcontainers.Testcontainers2Migration - org.openrewrite.maven.ExcludeDependency: groupId: junit artifactId: junit 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 ce945b308..73bf8734f 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java @@ -229,9 +229,11 @@ void excludeJunit4Dependency() { } @Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/429") + @Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/850") @Test void dontExcludeJunit4DependencyFromTestcontainers() { rewriteRun( + // No changes expected when Testcontainers is present - JUnit 4 should not be excluded pomXml( //language=xml """ @@ -249,19 +251,17 @@ void dontExcludeJunit4DependencyFromTestcontainers() { - """, - spec -> spec.after(pom -> assertThat(pom) - .containsPattern("2.\\d+\\.\\d+") - .doesNotContain("") - .actual()) + """ ) ); } @Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/429") + @Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/850") @Test void dontExcludeJunit4DependencyFromTestcontainersJupiter() { rewriteRun( + // No changes expected when Testcontainers is present - JUnit 4 should not be excluded pomXml( //language=xml """ @@ -279,13 +279,7 @@ void dontExcludeJunit4DependencyFromTestcontainersJupiter() { - """, - spec -> spec.after(pom -> assertThat(pom) - .contains("testcontainers-junit-jupiter") - .containsPattern("2.\\d+\\.\\d+") - .doesNotContain(">junit-jupiter") - .doesNotContain("") - .actual()) + """ ) ); } From 7a661b27abd34b7a58dfde668849c8f3bb9669a6 Mon Sep 17 00:00:00 2001 From: Thomas IAPICHINO Date: Wed, 26 Nov 2025 11:00:20 +0100 Subject: [PATCH 2/2] Check for org.testcontainers:*:1.x instead of spring-boot-testcontainers --- src/main/resources/META-INF/rewrite/junit5.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/META-INF/rewrite/junit5.yml b/src/main/resources/META-INF/rewrite/junit5.yml index 2a631f8e4..8eec07968 100755 --- a/src/main/resources/META-INF/rewrite/junit5.yml +++ b/src/main/resources/META-INF/rewrite/junit5.yml @@ -136,6 +136,7 @@ preconditions: - org.openrewrite.maven.search.DoesNotIncludeDependency: groupId: org.testcontainers artifactId: '*' + version: 1.x recipeList: - org.openrewrite.maven.ExcludeDependency: groupId: junit