Skip to content

Commit 31e8bba

Browse files
committed
Comment out Maven visitors that do not currently compose well together
1 parent 2392cc5 commit 31e8bba

File tree

3 files changed

+120
-9
lines changed

3 files changed

+120
-9
lines changed

src/main/java/org/openrewrite/java/testing/junit5/TemporaryFolderToTempDir.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ public J.ClassDecl visitClassDecl(J.ClassDecl cd) {
252252
}
253253

254254
/**
255-
* Adds a method like this one to the target class:
255+
* JUnit4 TemporaryFolder has a method called newFolder which returns a new folder located within a particular root directory.
256+
* There is no direct JUnit5 analogue for TemporaryFolder or its newFolder method.
257+
* This visitor adds a function called newFolder() to the test class it visits which provides the same functionality:
256258
*
257259
* private static File newFolder(File root, String ... folders) throws IOException {
258260
* File result = new File(root, String.join("/", folders));

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,30 @@ visitors:
5252
- org.openrewrite.maven.RemoveDependency:
5353
groupId: junit
5454
artifactId: junit
55-
---
56-
type: specs.openrewrite.org/v1beta/visitor
57-
name: org.openrewrite.java.testing.junit5.ExcludeJUnitVintageEngine
58-
visitors:
59-
- org.openrewrite.maven.ExcludeDependency:
60-
groupId: org.junit.vintage
61-
artifactId: junit-vintage-engine
55+
# Uncomment when a version of rewrite-maven has been published that has the fix for this issue:
56+
# https://github.com/openrewrite/rewrite/issues/92
57+
#---
58+
#type: specs.openrewrite.org/v1beta/visitor
59+
#name: org.openrewrite.java.testing.junit5.ExcludeJUnitVintageEngine
60+
#visitors:
61+
# - org.openrewrite.maven.ExcludeDependency:
62+
# groupId: org.junit.vintage
63+
# artifactId: junit-vintage-engine
64+
#---
65+
#type: specs.openrewrite.org/v1beta/visitor
66+
#name: org.openrewrite.java.testing.junit5.AddJunit5Dependency
67+
#visitors:
68+
# - org.openrewrite.maven.AddDependency:
69+
# groupId: org.junit.jupiter
70+
# artifactId: junit-jupiter-api
71+
# version: 5.7.0
72+
# scope: test
73+
# skipIfPresent: true
74+
# - org.openrewrite.maven.AddDependency:
75+
# groupId: org.junit.jupiter
76+
# artifactId: junit-jupiter-engine
77+
# version: 5.x
78+
# scope: test
6279
---
6380
type: specs.openrewrite.org/v1beta/recipe
6481
name: org.openrewrite.java.testing.JUnit5Migration

src/test/kotlin/org/openrewrite/java/testing/mockito/JunitMockitoUpgradeIntegrationTest.kt

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
*/
1616
package org.openrewrite.java.testing.mockito
1717

18+
import org.junit.jupiter.api.Assertions.assertEquals
19+
import org.junit.jupiter.api.Disabled
1820
import org.junit.jupiter.api.Test
1921
import org.openrewrite.*
2022
import org.openrewrite.java.JavaParser
21-
import org.openrewrite.java.OrderImports
2223
import org.openrewrite.java.tree.J
24+
import org.openrewrite.maven.MavenParser
2325

2426
/**
2527
* Validates the recipes related to upgrading from Mockito 1 to Mockito 3
@@ -454,4 +456,94 @@ class JunitMockitoUpgradeIntegrationTest : RefactorVisitorTestForParser<J.Compil
454456
}
455457
"""
456458
)
459+
460+
@Disabled("https://github.com/openrewrite/rewrite/issues/92")
461+
@Test
462+
fun upgradesPom() {
463+
val pom = MavenParser.builder().build().parse("""
464+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
465+
<modelVersion>4.0.0</modelVersion>
466+
467+
<groupId>org.openrewrite.example</groupId>
468+
<artifactId>integration-testing</artifactId>
469+
<version>1.0</version>
470+
<name>integration-testing</name>
471+
472+
<properties>
473+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
474+
<java.version>1.8</java.version>
475+
</properties>
476+
477+
<dependencies>
478+
<dependency>
479+
<groupId>junit</groupId>
480+
<artifactId>junit</artifactId>
481+
<version>4.12</version>
482+
<scope>test</scope>
483+
</dependency>
484+
</dependencies>
485+
486+
<build>
487+
<plugins>
488+
<plugin>
489+
<groupId>org.apache.maven.plugins</groupId>
490+
<artifactId>maven-surefire-plugin</artifactId>
491+
<version>3.0.0-M5</version>
492+
</plugin>
493+
</plugins>
494+
</build>
495+
</project>
496+
""".trimIndent())
497+
498+
val fixed = Refactor(true)
499+
.visit(visitors)
500+
.fix(pom)
501+
.first()
502+
.fixed!!
503+
.printTrimmed()
504+
505+
val expected = """
506+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
507+
<modelVersion>4.0.0</modelVersion>
508+
509+
<groupId>org.openrewrite.example</groupId>
510+
<artifactId>integration-testing</artifactId>
511+
<version>1.0</version>
512+
<name>integration-testing</name>
513+
514+
<properties>
515+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
516+
<java.version>1.8</java.version>
517+
</properties>
518+
519+
<dependencies>
520+
<dependency>
521+
<groupId>org.junit.jupiter</groupId>
522+
<artifactId>junit-jupiter-api</artifactId>
523+
<version>5.7.0</version>
524+
<scope>test</scope>
525+
</dependency>
526+
<dependency>
527+
<groupId>org.junit.jupiter</groupId>
528+
<artifactId>junit-jupiter-engine</artifactId>
529+
<version>5.7.0</version>
530+
<scope>test</scope>
531+
</dependency>
532+
</dependencies>
533+
534+
<build>
535+
<plugins>
536+
<plugin>
537+
<groupId>org.apache.maven.plugins</groupId>
538+
<artifactId>maven-surefire-plugin</artifactId>
539+
<version>3.0.0-M5</version>
540+
</plugin>
541+
</plugins>
542+
</build>
543+
</project>
544+
""".trimIndent()
545+
546+
assertEquals(expected, fixed)
547+
}
548+
457549
}

0 commit comments

Comments
 (0)