diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/AddDependencyTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/AddDependencyTest.java
index a5286ae8a7a..51c730ababf 100644
--- a/rewrite-maven/src/test/java/org/openrewrite/maven/AddDependencyTest.java
+++ b/rewrite-maven/src/test/java/org/openrewrite/maven/AddDependencyTest.java
@@ -26,10 +26,7 @@
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
-import static org.openrewrite.java.Assertions.java;
-import static org.openrewrite.java.Assertions.mavenProject;
-import static org.openrewrite.java.Assertions.srcMainJava;
-import static org.openrewrite.java.Assertions.srcTestJava;
+import static org.openrewrite.java.Assertions.*;
import static org.openrewrite.maven.Assertions.pomXml;
import static org.openrewrite.test.RewriteTest.toRecipe;
@@ -384,6 +381,107 @@ void test() {}
);
}
+ @Test
+ void doNotAddBecauseAlreadyTransitiveNoCompileScope() {
+ rewriteRun(
+ spec -> spec.recipe(addDependency("org.junit.jupiter:junit-jupiter-api:5.10.3", null, true)),
+ mavenProject(
+ "project",
+ srcTestJava(
+ java(
+ """
+ class MyTest {
+ @org.junit.jupiter.api.Test
+ void test() {}
+ }
+ """
+ )
+ ),
+ pomXml(
+ """
+
+ com.mycompany.app
+ my-app
+ 1
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.7.1
+ test
+
+
+
+ """
+ )
+ )
+ );
+ }
+
+ @Test
+ void addDependencyAcceptsTransitiveAlreadyInTestScope() {
+ rewriteRun(
+ spec -> spec.recipe(addDependency("org.junit.jupiter:junit-jupiter-api:5.10.3", null, true)),
+ mavenProject(
+ "project",
+ srcMainJava(java("""
+ class MyClass {
+ void clz() {}
+ }
+ """
+ )
+ ),
+ srcTestJava(
+ java(
+ """
+ class MyTest {
+ @org.junit.jupiter.api.Test
+ void test() {}
+ }
+ """
+ )
+ ),
+ pomXml(
+ """
+
+ com.mycompany.app
+ my-app
+ 1
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.7.1
+ test
+
+
+
+ """,
+ """
+
+ com.mycompany.app
+ my-app
+ 1
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.10.3
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.7.1
+ test
+
+
+
+ """
+ )
+ )
+ );
+ }
+
@ParameterizedTest
@ValueSource(strings = {"com.google.common.math.*", "com.google.common.math.IntMath"})
void semverSelector(String onlyIfUsing) {
@@ -1047,35 +1145,35 @@ void noCompileScopeDependency() {
org.springframework.samples
spring-petclinic
2.7.3
-
+
org.springframework.boot
spring-boot-starter-parent
3.0.5
petclinic
-
+
5.0.0
-
+
17
UTF-8
UTF-8
-
+
5.1.3
4.7.0
-
+
0.8.8
-
+
-
+
org.springframework.boot
spring-boot-starter-data-jpa
-
+
""",
"""
@@ -1084,28 +1182,28 @@ void noCompileScopeDependency() {
org.springframework.samples
spring-petclinic
2.7.3
-
+
org.springframework.boot
spring-boot-starter-parent
3.0.5
petclinic
-
+
5.0.0
-
+
17
UTF-8
UTF-8
-
+
5.1.3
4.7.0
-
+
0.8.8
-
+
-
+
jakarta.xml.bind
@@ -1116,7 +1214,7 @@ void noCompileScopeDependency() {
spring-boot-starter-data-jpa
-
+
"""
)
@@ -1179,6 +1277,7 @@ void addDependenciesOnEmptyProject() {
);
}
+
private AddDependency addDependency(@SuppressWarnings("SameParameterValue") String gav) {
return addDependency(gav, null, null, null);
}