Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate mockito library upgrade #131

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ void upgradeGuavaInGradleProject() {
plugins {
id 'java-library'
}

repositories {
mavenCentral()
}

dependencies {
compileOnly 'com.google.guava:guava:29.0-jre'
runtimeOnly ('com.google.guava:guava:29.0-jre')
Expand All @@ -58,11 +58,11 @@ void upgradeGuavaInGradleProject() {
plugins {
id 'java-library'
}

repositories {
mavenCentral()
}

dependencies {
compileOnly 'com.google.guava:guava:30.1.1-jre'
runtimeOnly ('com.google.guava:guava:30.1.1-jre')
Expand Down Expand Up @@ -91,6 +91,62 @@ void upgradeGuavaInGradleProject() {
);
}

@Test
void upgradeMockitoInGradleProject() {
rewriteRun(recipeSpec -> {
recipeSpec.beforeRecipe(withToolingApi())
.recipe(new UpgradeDependencyVersion("org.mockito", "*", "4.x", null, null, 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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has mockito completely stopped putting out 4.x releases? I'd think so given that 4.11 stems from December 2022, but figured to check since we wouldn't want to update the test output if there's a newer release.

}
""",
spec -> spec.afterRecipe(after -> {
Optional<GradleProject> 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 resolved dependencies should have been updated with the new version of mockito")
.isPresent();
})
)
);
}

@DocumentExample("Upgrade maven dependency version")
@Test
void updateManagedDependencyVersion() {
Expand Down
Loading