Skip to content

Commit

Permalink
Fix some failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Jan 19, 2024
1 parent a426e40 commit 249d6d9
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.Arrays;
import java.util.UUID;

import static java.util.Collections.singletonList;

@RequiredArgsConstructor
public class ExplicitContainerImage extends Recipe {
@Option(displayName = "Container class",
Expand Down Expand Up @@ -66,8 +68,12 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
@Override
public J.NewClass visitNewClass(J.NewClass newClass, ExecutionContext ctx) {
J.NewClass nc = super.visitNewClass(newClass, ctx);
if (methodMatcher.matches(newClass)) {
return nc.withArguments(Arrays.asList(getConstructorArgument(newClass)));
if (methodMatcher.matches(nc)) {
Expression constructorArgument = getConstructorArgument(nc);
return nc.withArguments(Arrays.asList(constructorArgument))
.withMethodType(nc.getMethodType()
.withParameterTypes(singletonList(constructorArgument.getType()))
.withParameterNames(singletonList("image")));
}
return nc;
}
Expand All @@ -80,7 +86,7 @@ private Expression getConstructorArgument(J.NewClass newClass) {
.imports("org.testcontainers.utility.DockerImageName")
.javaParser(JavaParser.fromJavaVersion().classpath("testcontainers"))
.build()
.apply(getCursor(), newClass.getArguments().get(0).getCoordinates().replace())
.apply(getCursor(), newClass.getCoordinates().replace())
.withPrefix(Space.EMPTY);
}
return new J.Literal(UUID.randomUUID(), Space.EMPTY, Markers.EMPTY, image, "\"" + image + "\"", null, JavaType.Primitive.String);
Expand Down

0 comments on commit 249d6d9

Please sign in to comment.