Skip to content

Commit

Permalink
feat: Add tests for AddDependency already in test scope
Browse files Browse the repository at this point in the history
  • Loading branch information
pstreef committed Aug 5, 2024
1 parent 2b3291e commit 2e8b9af
Showing 1 changed file with 119 additions and 20 deletions.
139 changes: 119 additions & 20 deletions rewrite-maven/src/test/java/org/openrewrite/maven/AddDependencyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
"""
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
"""
)
)
);
}

@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(
"""
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""",
"""
<project>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
"""
)
)
);
}

@ParameterizedTest
@ValueSource(strings = {"com.google.common.math.*", "com.google.common.math.IntMath"})
void semverSelector(String onlyIfUsing) {
Expand Down Expand Up @@ -1047,35 +1145,35 @@ void noCompileScopeDependency() {
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic</artifactId>
<version>2.7.3</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
</parent>
<name>petclinic</name>
<properties>
<jakarta-servlet.version>5.0.0</jakarta-servlet.version>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<webjars-bootstrap.version>5.1.3</webjars-bootstrap.version>
<webjars-font-awesome.version>4.7.0</webjars-font-awesome.version>
<jacoco.version>0.8.8</jacoco.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
</project>
""",
"""
Expand All @@ -1084,28 +1182,28 @@ void noCompileScopeDependency() {
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic</artifactId>
<version>2.7.3</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.5</version>
</parent>
<name>petclinic</name>
<properties>
<jakarta-servlet.version>5.0.0</jakarta-servlet.version>
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<webjars-bootstrap.version>5.1.3</webjars-bootstrap.version>
<webjars-font-awesome.version>4.7.0</webjars-font-awesome.version>
<jacoco.version>0.8.8</jacoco.version>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
Expand All @@ -1116,7 +1214,7 @@ void noCompileScopeDependency() {
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
</dependencies>
</project>
"""
)
Expand Down Expand Up @@ -1179,6 +1277,7 @@ void addDependenciesOnEmptyProject() {
);
}


private AddDependency addDependency(@SuppressWarnings("SameParameterValue") String gav) {
return addDependency(gav, null, null, null);
}
Expand Down

0 comments on commit 2e8b9af

Please sign in to comment.