Skip to content

Commit 1a882f4

Browse files
authored
Upgrade testcontainers for the JUnit 5 migration (#833)
* Upgrade testcontainers for the JUnit 5 migration * Upgrade before exclude * Reformat
1 parent be5cbb3 commit 1a882f4

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

src/main/resources/META-INF/rewrite/junit5.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,14 @@ recipeList:
130130
---
131131
type: specs.openrewrite.org/v1beta/recipe
132132
name: org.openrewrite.java.testing.junit5.ExcludeJUnit4UnlessUsingTestcontainers
133-
displayName: Exclude JUnit 4, unless Testcontainers is used
134-
description: Excludes JUnit 4, as it ought not to be necessary in a JUnit 5 project, unless Testcontainers is used.
133+
displayName: Exclude JUnit 4, unless Spring Boot Testcontainers is used
134+
description: Excludes JUnit 4, as it ought not to be necessary in a JUnit 5 project, unless Testcontainers 1.x is used.
135135
preconditions:
136136
- org.openrewrite.maven.search.DoesNotIncludeDependency:
137-
groupId: org.testcontainers
138-
artifactId: '*'
137+
groupId: org.springframework.boot
138+
artifactId: spring-boot-testcontainers
139139
recipeList:
140+
- org.openrewrite.java.testing.testcontainers.Testcontainers2Migration
140141
- org.openrewrite.maven.ExcludeDependency:
141142
groupId: junit
142143
artifactId: junit

src/main/resources/META-INF/rewrite/testcontainers.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@ displayName: Testcontainers best practices
2121
description: Apply best practices to Testcontainers usage.
2222
recipeList:
2323
- org.openrewrite.java.testing.testcontainers.Testcontainers2Migration
24+
---
25+
type: specs.openrewrite.org/v1beta/recipe
26+
name: org.openrewrite.java.testing.testcontainers.Testcontainers2Migration
27+
displayName: Migrate to testcontainers-java 2.x
28+
description: Change dependencies and types to migrate to testcontainers-java 2.x.
29+
recipeList:
2430
- org.openrewrite.java.testing.testcontainers.ExplicitContainerImages
2531
- org.openrewrite.java.testing.testcontainers.GetHostMigration
2632
- org.openrewrite.java.ChangeType:
2733
oldFullyQualifiedTypeName: org.testcontainers.containers.DockerComposeContainer
2834
newFullyQualifiedTypeName: org.testcontainers.containers.ComposeContainer
35+
- org.openrewrite.java.testing.testcontainers.Testcontainers2Dependencies
36+
- org.openrewrite.java.testing.testcontainers.Testcontainers2ContainerClasses
2937
---
3038
type: specs.openrewrite.org/v1beta/recipe
3139
name: org.openrewrite.java.testing.testcontainers.GetHostMigration
@@ -123,14 +131,6 @@ recipeList:
123131
parseImage: true
124132
---
125133
type: specs.openrewrite.org/v1beta/recipe
126-
name: org.openrewrite.java.testing.testcontainers.Testcontainers2Migration
127-
displayName: Migrate to testcontainers-java 2.x
128-
description: Change dependencies and types to migrate to testcontainers-java 2.x.
129-
recipeList:
130-
- org.openrewrite.java.testing.testcontainers.Testcontainers2Dependencies
131-
- org.openrewrite.java.testing.testcontainers.Testcontainers2ContainerClasses
132-
---
133-
type: specs.openrewrite.org/v1beta/recipe
134134
name: org.openrewrite.java.testing.testcontainers.Testcontainers2Dependencies
135135
displayName: Rename Testcontainers dependencies
136136
description: Change Testcontainers dependencies to adopt the new consistent `testcontainers-` prefix.

src/test/java/org/openrewrite/java/testing/junit5/JUnit5MigrationTest.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,22 @@ void dontExcludeJunit4DependencyFromTestcontainers() {
249249
</dependency>
250250
</dependencies>
251251
</project>
252+
""",
253+
"""
254+
<project>
255+
<modelVersion>4.0.0</modelVersion>
256+
<groupId>com.example.jackson</groupId>
257+
<artifactId>test-plugins</artifactId>
258+
<version>1.0.0</version>
259+
<dependencies>
260+
<dependency>
261+
<groupId>org.testcontainers</groupId>
262+
<artifactId>testcontainers</artifactId>
263+
<version>2.0.1</version>
264+
<scope>test</scope>
265+
</dependency>
266+
</dependencies>
267+
</project>
252268
"""
253269
)
254270
);
@@ -275,6 +291,22 @@ void dontExcludeJunit4DependencyFromTestcontainersJupiter() {
275291
</dependency>
276292
</dependencies>
277293
</project>
294+
""",
295+
"""
296+
<project>
297+
<modelVersion>4.0.0</modelVersion>
298+
<groupId>com.example.jackson</groupId>
299+
<artifactId>test-plugins</artifactId>
300+
<version>1.0.0</version>
301+
<dependencies>
302+
<dependency>
303+
<groupId>org.testcontainers</groupId>
304+
<artifactId>testcontainers-junit-jupiter</artifactId>
305+
<version>2.0.1</version>
306+
<scope>test</scope>
307+
</dependency>
308+
</dependencies>
309+
</project>
278310
"""
279311
)
280312
);
@@ -512,7 +544,9 @@ void removeJunitVintageEngineFromGradleBuild() {
512544
}
513545
"""
514546
),
515-
srcTestJava(java("""
547+
srcTestJava(
548+
java(
549+
"""
516550
import org.junit.Test;
517551
518552
public class MyTest {
@@ -521,7 +555,7 @@ public void hello() {
521555
}
522556
}
523557
""",
524-
"""
558+
"""
525559
import org.junit.jupiter.api.Test;
526560
527561
public class MyTest {
@@ -530,7 +564,8 @@ public void hello() {
530564
}
531565
}
532566
"""
533-
))
567+
)
568+
)
534569
);
535570
}
536571

0 commit comments

Comments
 (0)