Skip to content

Commit 1dc63f6

Browse files
committed
CleanupJUnitImports should exclude JUnit 4 from any dependencies that bring it in transitively. Closes #36
1 parent 7529d4d commit 1dc63f6

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
* Orders imports and removes unused imports from classes which import symbols from the "org.junit" package.
2727
*/
2828
public class CleanupJUnitImports extends Recipe {
29-
3029
@Override
3130
protected TreeVisitor<?, ExecutionContext> getVisitor() {
3231
return new CleanupJUnitImportsVisitor();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ recipeList:
2929
- org.openrewrite.maven.ExcludeDependency:
3030
groupId: org.junit.vintage
3131
artifactId: junit-vintage-engine
32+
- org.openrewrite.maven.ExcludeDependency:
33+
groupId: junit
34+
artifactId: junit
3235
- org.openrewrite.java.testing.junit5.AssertToAssertions
3336
- org.openrewrite.java.testing.junit5.CategoryToTag
3437
- org.openrewrite.java.testing.junit5.CleanupJUnitImports

src/test/kotlin/org/openrewrite/java/testing/junit5/CleanupJUnitImportsTest.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.openrewrite.java.testing.junit5
1717

1818
import org.junit.jupiter.api.Test
19-
import org.openrewrite.Recipe
2019
import org.openrewrite.java.JavaRecipeTest
2120
import org.openrewrite.java.JavaParser
2221

@@ -25,8 +24,7 @@ class CleanupJUnitImportsTest : JavaRecipeTest {
2524
.classpath("junit")
2625
.build()
2726

28-
override val recipe: Recipe
29-
get() = CleanupJUnitImports()
27+
override val recipe = CleanupJUnitImports()
3028

3129
@Test
3230
fun removesUnusedImport() = assertChanged(

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,11 @@ class JunitMockitoUpgradeIntegrationTest : JavaRecipeTest {
476476
<version>4.12</version>
477477
<scope>test</scope>
478478
</dependency>
479+
<dependency>
480+
<groupId>com.googlecode.json-simple</groupId>
481+
<artifactId>json-simple</artifactId>
482+
<version>1.1.1</version>
483+
</dependency>
479484
</dependencies>
480485
</project>
481486
""".trimIndent())[0]
@@ -513,6 +518,17 @@ class JunitMockitoUpgradeIntegrationTest : JavaRecipeTest {
513518
<version>5.7.1</version>
514519
<scope>test</scope>
515520
</dependency>
521+
<dependency>
522+
<groupId>com.googlecode.json-simple</groupId>
523+
<artifactId>json-simple</artifactId>
524+
<version>1.1.1</version>
525+
<exclusions>
526+
<exclusion>
527+
<groupId>junit</groupId>
528+
<artifactId>junit</artifactId>
529+
</exclusion>
530+
</exclusions>
531+
</dependency>
516532
</dependencies>
517533
</project>
518534
""".trimIndent())

0 commit comments

Comments
 (0)