Skip to content

Commit

Permalink
Light polish to reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Dec 23, 2024
1 parent 2d0703e commit 261cf00
Showing 1 changed file with 24 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.gradle.Assertions.buildGradle;
import static org.openrewrite.gradle.toolingapi.Assertions.withToolingApi;
import static org.openrewrite.java.Assertions.java;


class Mockito1to5MigrationTest implements RewriteTest {

@Override
Expand All @@ -46,47 +42,30 @@ public void defaults(RecipeSpec spec) {
@Test
void modifyMockitoDependencies() {
rewriteRun(
//language=groovy
buildGradle(
//language=groovy
"""
plugins {
id 'java-library'
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.apache.commons:commons-lang3:3.17.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.4")
testImplementation("org.mockito:mockito-core:3.12.4")
testImplementation("org.mockito:mockito-junit-jupiter:3.12.4")
}
test {
useJUnitPlatform()
}
""",
spec -> spec.after(buildGradleAfter -> {
Matcher artifactMatcher = Pattern.compile("org\\.mockito:[\\D]+:(?<version>5\\.\\d+\\.\\d+)").matcher(buildGradleAfter);
assertThat(artifactMatcher.find()).describedAs("Expected 5.x.y in %s", buildGradleAfter).isTrue();
String versionNumber = artifactMatcher.group("version");
return """
plugins {
id 'java-library'
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.apache.commons:commons-lang3:3.17.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.4")
testImplementation("org.mockito:mockito-core:%s")
testImplementation("org.mockito:mockito-junit-jupiter:%s")
}
test {
useJUnitPlatform()
}
""".formatted(versionNumber, versionNumber);
})),
plugins {
id 'java-library'
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.apache.commons:commons-lang3:3.17.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.4")
testImplementation("org.mockito:mockito-core:3.12.4")
testImplementation("org.mockito:mockito-junit-jupiter:3.12.4")
}
test {
useJUnitPlatform()
}
""",
spec -> spec.after(buildGradleAfter -> assertThat(buildGradleAfter)
.containsPattern("org.apache.commons:commons-lang3:3.17.0")
.containsPattern("org.junit.jupiter:junit-jupiter-api:5.11.4")
.containsPattern("org\\.mockito:[\\D]+:(?<version>5\\.\\d+\\.\\d+)")
.actual())),
//language=java
java(
"""
Expand All @@ -97,9 +76,9 @@ void modifyMockitoDependencies() {
import java.util.List;
@ExtendWith(MockitoExtension.class)
public class MyTest {
class MyTest {
@Test
public void test() {
void test() {
List<String> list = Mockito.mock(List.class);
}
}
Expand Down

0 comments on commit 261cf00

Please sign in to comment.