Skip to content

Commit

Permalink
No second cycle in removal of mockito-inline (#470)
Browse files Browse the repository at this point in the history
* Add parameter names and types in ExplicitContainerImage

* First rename dependency then bump version

* Switch to static imports last

* Improve message when after is null

* Apply suggestions from code review

* Apply suggestions from code review

* Update ExplicitContainerImage.java

* Apply suggestions from code review

* Remove need for second cycle
  • Loading branch information
timtebeek authored Jan 23, 2024
1 parent bfcb7d2 commit 6b5fd4f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import org.openrewrite.java.tree.Space;
import org.openrewrite.marker.Markers;

import java.util.Arrays;
import java.util.UUID;

import static java.util.Collections.singletonList;

Expand Down Expand Up @@ -70,7 +68,7 @@ public J.NewClass visitNewClass(J.NewClass newClass, ExecutionContext ctx) {
J.NewClass nc = super.visitNewClass(newClass, ctx);
if (methodMatcher.matches(nc)) {
Expression constructorArgument = getConstructorArgument(nc);
return nc.withArguments(Arrays.asList(constructorArgument))
return nc.withArguments(singletonList(constructorArgument))
.withMethodType(nc.getMethodType()
.withParameterTypes(singletonList(constructorArgument.getType()))
.withParameterNames(singletonList("image")));
Expand All @@ -89,7 +87,7 @@ private Expression getConstructorArgument(J.NewClass newClass) {
.apply(getCursor(), newClass.getCoordinates().replace())
.withPrefix(Space.EMPTY);
}
return new J.Literal(UUID.randomUUID(), Space.EMPTY, Markers.EMPTY, image, "\"" + image + "\"", null, JavaType.Primitive.String);
return new J.Literal(Tree.randomId(), Space.EMPTY, Markers.EMPTY, image, "\"" + image + "\"", null, JavaType.Primitive.String);
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/META-INF/rewrite/mockito.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ tags:
- mockito
recipeList:
- org.openrewrite.java.testing.mockito.Mockito1to4Migration
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: org.mockito
artifactId: "*"
newVersion: 5.x
- org.openrewrite.java.dependencies.ChangeDependency:
oldGroupId: org.mockito
oldArtifactId: mockito-inline
newArtifactId: mockito-core
- org.openrewrite.java.dependencies.UpgradeDependencyVersion:
groupId: org.mockito
artifactId: "*"
newVersion: 5.x
- org.openrewrite.maven.RemoveDuplicateDependencies

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.regex.Pattern;
import java.util.stream.Stream;

import static java.util.Objects.requireNonNull;
import static org.openrewrite.gradle.Assertions.buildGradle;
import static org.openrewrite.gradle.Assertions.withToolingApi;
import static org.openrewrite.java.Assertions.*;
Expand Down Expand Up @@ -579,7 +580,7 @@ void assertjMavenDependencyAddedWithTestScope() {
</dependency>
</dependencies>
</project>
""".formatted(Pattern.compile("<version>(3\\.2.*)</version>").matcher(after).results().findFirst().orElseThrow().group(1))))
""".formatted(Pattern.compile("<version>(3\\.2.*)</version>").matcher(requireNonNull(after)).results().findFirst().orElseThrow().group(1))))
)
);
}
Expand Down Expand Up @@ -617,7 +618,7 @@ void assertjGradleDependencyAddedWithTestScope() {
testImplementation "org.hamcrest:hamcrest:2.2"
}
"""
.formatted(Pattern.compile("(assertj-core:[^\"]*)").matcher(after).results().findFirst().orElseThrow().group(1))
.formatted(Pattern.compile("(assertj-core:[^\"]*)").matcher(requireNonNull(after)).results().findFirst().orElseThrow().group(1))
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public void defaults(RecipeSpec spec) {
@Test
void inlineToCore() {
rewriteRun(
spec -> spec.expectedCyclesThatMakeChanges(2),
//language=xml
pomXml(
"""
Expand Down

0 comments on commit 6b5fd4f

Please sign in to comment.