Skip to content

Commit

Permalink
Update dependency handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Aug 20, 2021
1 parent c962c90 commit 713fb1c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 153 deletions.
4 changes: 1 addition & 3 deletions src/main/resources/META-INF/rewrite/assertj.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,4 @@ recipeList:
groupId: org.assertj
artifactId: assertj-core
version: 3.x
scope: test
onlyIfUsing:
- org.assertj.core.api.Assertions
onlyIfUsing: org.assertj.core.api.Assertions
4 changes: 1 addition & 3 deletions src/main/resources/META-INF/rewrite/hamcrest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ recipeList:
groupId: org.hamcrest
artifactId: hamcrest
version: 2.x
scope: test
onlyIfUsing:
- org.hamcrest.Matchers
onlyIfUsing: org.hamcrest.Matchers
48 changes: 21 additions & 27 deletions src/main/resources/META-INF/rewrite/junit5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,27 @@ recipeList:
- org.openrewrite.maven.RemoveDependency:
groupId: junit
artifactId: junit
# - org.openrewrite.maven.ExcludeDependency:
# groupId: org.junit.vintage
# artifactId: junit-vintage-engine
# - org.openrewrite.maven.ExcludeDependency:
# groupId: junit
# artifactId: junit
# - org.openrewrite.maven.AddDependency:
# groupId: org.junit.jupiter
# artifactId: junit-jupiter-api
# version: 5.x
# scope: test
# onlyIfUsing:
# - org.junit.jupiter.api.Test
# - org.openrewrite.maven.AddDependency:
# groupId: org.junit.jupiter
# artifactId: junit-jupiter-engine
# version: 5.x
# scope: test
# onlyIfUsing:
# - org.junit.jupiter.api.Test
# - org.openrewrite.maven.AddDependency:
# groupId: org.junit.jupiter
# artifactId: junit-jupiter-params
# version: 5.x
# scope: test
# onlyIfUsing:
# - org.junit.jupiter.params.ParameterizedTest
- org.openrewrite.maven.ExcludeDependency:
groupId: org.junit.vintage
artifactId: junit-vintage-engine
- org.openrewrite.maven.ExcludeDependency:
groupId: junit
artifactId: junit
- org.openrewrite.maven.AddDependency:
groupId: org.junit.jupiter
artifactId: junit-jupiter-api
version: 5.x
onlyIfUsing: org.junit.jupiter.api.Test
- org.openrewrite.maven.AddDependency:
groupId: org.junit.jupiter
artifactId: junit-jupiter-engine
version: 5.x
onlyIfUsing: org.junit.jupiter.api.Test
- org.openrewrite.maven.AddDependency:
groupId: org.junit.jupiter
artifactId: junit-jupiter-params
version: 5.x
onlyIfUsing: org.junit.jupiter.params.ParameterizedTest

---
type: specs.openrewrite.org/v1beta/recipe
Expand Down
4 changes: 1 addition & 3 deletions src/main/resources/META-INF/rewrite/mockito.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,4 @@ recipeList:
groupId: org.mockito
artifactId: mockito-junit-jupiter
version: 3.x
scope: test
onlyIfUsing:
- org.mockito.junit.jupiter.MockitoExtension
onlyIfUsing: org.mockito.junit.jupiter.MockitoExtension
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ package org.openrewrite.java.testing.junit5
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.openrewrite.Issue
import org.openrewrite.Parser
import org.openrewrite.Recipe
import org.openrewrite.java.JavaParser
import org.openrewrite.java.JavaRecipeTest
import org.openrewrite.java.tree.J

class UpdateTestAnnotationTest : JavaRecipeTest {
override val parser: JavaParser = JavaParser.fromJavaVersion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,119 +262,4 @@ class JunitMockitoUpgradeIntegrationTest : JavaRecipeTest {
public class ExampleTest { }
"""
)

@Test
@Disabled("Temporarily disable this test")
fun junitJupiterMavenDependenciesAreUpdated() {
val javaSource = parser.parse("""
package org.openrewrite.java.testing.junit5;
import org.junit.jupiter.api.*;
import java.util.List;
import static org.mockito.Mockito.*;
public class ExampleJunitTestClass {
@Mock
List<String> mockedList;
public void initMocks() {
MockitoAnnotations.initMocks(this);
}
@Test
void usingAnnotationBasedMock() {
mockedList.add("one");
mockedList.clear();
verify(mockedList).add("one");
verify(mockedList).clear();
}
}
""".trimIndent())[0]
val mavenSource = MavenParser.builder().build().parse(
"""
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.openrewrite.example</groupId>
<artifactId>integration-testing</artifactId>
<version>1.0</version>
<name>integration-testing</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>
""".trimIndent()
)[0]

val sources: List<SourceFile> = listOf(javaSource, mavenSource)

val results = recipe.run(sources, InMemoryExecutionContext { error: Throwable -> throw error })

val mavenResult = results.find { it.before === mavenSource }
assertThat(mavenResult).isNotNull

assertThat(mavenResult?.after?.print()).isEqualTo(
"""
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.openrewrite.example</groupId>
<artifactId>integration-testing</artifactId>
<version>1.0</version>
<name>integration-testing</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""".trimIndent()
)
}

}

0 comments on commit 713fb1c

Please sign in to comment.