From b4a894674b66210ff87797f5cad770aeead1b43d Mon Sep 17 00:00:00 2001 From: sullis Date: Sun, 15 Dec 2024 19:32:47 -0800 Subject: [PATCH] enhance UpgradeDependencyVersionTest --- .../gradle/UpgradeDependencyVersionTest.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpgradeDependencyVersionTest.java b/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpgradeDependencyVersionTest.java index 5e9ecf85f344..8801213daaee 100644 --- a/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpgradeDependencyVersionTest.java +++ b/rewrite-gradle/src/test/java/org/openrewrite/gradle/UpgradeDependencyVersionTest.java @@ -98,6 +98,62 @@ void guava() { ); } + @Test + void mockito() { + rewriteRun(recipeSpec -> { + recipeSpec.beforeRecipe(withToolingApi()) + .recipe(new UpgradeDependencyVersion("org.mockito", "*", "4.x", null)); + }, + buildGradle( + """ + plugins { + id 'java-library' + } + + repositories { + mavenCentral() + } + + dependencies { + testImplementation("org.mockito:mockito-junit-jupiter:3.12.4") + } + """, + """ + plugins { + id 'java-library' + } + + repositories { + mavenCentral() + } + + dependencies { + testImplementation("org.mockito:mockito-junit-jupiter:4.11.0") + } + """, + spec -> spec.afterRecipe(after -> { + Optional maybeGp = after.getMarkers().findFirst(GradleProject.class); + assertThat(maybeGp).isPresent(); + GradleProject gp = maybeGp.get(); + GradleDependencyConfiguration testCompileClasspath = gp.getConfiguration("testCompileClasspath"); + assertThat(testCompileClasspath).isNotNull(); + assertThat( + testCompileClasspath.getRequested().stream() + .filter(dep -> "org.mockito".equals(dep.getGroupId()) && "mockito-junit-jupiter".equals(dep.getArtifactId())) + .findAny()) + .as("GradleProject requested dependencies should have been updated with the new version of mockito") + .isPresent(); + assertThat( + testCompileClasspath.getResolved().stream() + .filter(dep -> "org.mockito".equals(dep.getGroupId()) && "mockito-junit-jupiter".equals(dep.getArtifactId()) && "4.11.0".equals(dep.getVersion())) + .findAny()) + .as("GradleProject requested dependencies should have been updated with the new version of guava") + .isPresent(); + }) + ) + ); + } + @Test void updateVersionInVariable() { rewriteRun(