Skip to content

Commit 249d6d9

Browse files
committed
Fix some failing tests
See: openrewrite/rewrite#3921
1 parent a426e40 commit 249d6d9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main/java/org/openrewrite/java/testing/testcontainers/ExplicitContainerImage.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.Arrays;
3333
import java.util.UUID;
3434

35+
import static java.util.Collections.singletonList;
36+
3537
@RequiredArgsConstructor
3638
public class ExplicitContainerImage extends Recipe {
3739
@Option(displayName = "Container class",
@@ -66,8 +68,12 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
6668
@Override
6769
public J.NewClass visitNewClass(J.NewClass newClass, ExecutionContext ctx) {
6870
J.NewClass nc = super.visitNewClass(newClass, ctx);
69-
if (methodMatcher.matches(newClass)) {
70-
return nc.withArguments(Arrays.asList(getConstructorArgument(newClass)));
71+
if (methodMatcher.matches(nc)) {
72+
Expression constructorArgument = getConstructorArgument(nc);
73+
return nc.withArguments(Arrays.asList(constructorArgument))
74+
.withMethodType(nc.getMethodType()
75+
.withParameterTypes(singletonList(constructorArgument.getType()))
76+
.withParameterNames(singletonList("image")));
7177
}
7278
return nc;
7379
}
@@ -80,7 +86,7 @@ private Expression getConstructorArgument(J.NewClass newClass) {
8086
.imports("org.testcontainers.utility.DockerImageName")
8187
.javaParser(JavaParser.fromJavaVersion().classpath("testcontainers"))
8288
.build()
83-
.apply(getCursor(), newClass.getArguments().get(0).getCoordinates().replace())
89+
.apply(getCursor(), newClass.getCoordinates().replace())
8490
.withPrefix(Space.EMPTY);
8591
}
8692
return new J.Literal(UUID.randomUUID(), Space.EMPTY, Markers.EMPTY, image, "\"" + image + "\"", null, JavaType.Primitive.String);

0 commit comments

Comments
 (0)