Skip to content

Commit

Permalink
Make MigrateHamcrestToAssertJTest robust against new releases
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Jan 4, 2024
1 parent 99d1529 commit dc61c73
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import java.util.regex.Pattern;
import java.util.stream.Stream;

import static org.openrewrite.gradle.Assertions.buildGradle;
Expand Down Expand Up @@ -537,7 +538,6 @@ void test() {
void assertjMavenDependencyAddedWithTestScope() {
rewriteRun(
mavenProject("project",
//language=java
srcTestJava(java(JAVA_BEFORE, JAVA_AFTER)),
//language=xml
pomXml("""
Expand All @@ -555,7 +555,8 @@ void assertjMavenDependencyAddedWithTestScope() {
</dependency>
</dependencies>
</project>
""", """
""",
sourceSpecs -> sourceSpecs.after(after -> """
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
Expand All @@ -565,7 +566,7 @@ void assertjMavenDependencyAddedWithTestScope() {
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<version>%s</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -576,17 +577,17 @@ void assertjMavenDependencyAddedWithTestScope() {
</dependency>
</dependencies>
</project>
""")));
""".formatted(Pattern.compile("<version>(3\\.2.*)</version>").matcher(after).results().findFirst().orElseThrow().group(1))))
)
);
}

@Test
void assertjGradleDependencyAddedWithTestScope() {
rewriteRun(
spec -> spec.beforeRecipe(withToolingApi()),
mavenProject("project",
//language=java
srcTestJava(java(JAVA_BEFORE, JAVA_AFTER)),
//language=groovy
buildGradle("""
plugins {
id "java-library"
Expand All @@ -599,7 +600,8 @@ void assertjGradleDependencyAddedWithTestScope() {
dependencies {
testImplementation "org.hamcrest:hamcrest:2.2"
}
""", """
""",
sourceSpecs -> sourceSpecs.after(after -> """
plugins {
id "java-library"
}
Expand All @@ -609,10 +611,15 @@ void assertjGradleDependencyAddedWithTestScope() {
}
dependencies {
testImplementation "org.assertj:assertj-core:3.24.2"
testImplementation "org.assertj:%s"
testImplementation "org.hamcrest:hamcrest:2.2"
}
""")));
"""
.formatted(Pattern.compile("(assertj-core:[^\"]*)").matcher(after).results().findFirst().orElseThrow().group(1))
)
)
)
);
}
}

Expand Down

0 comments on commit dc61c73

Please sign in to comment.