Skip to content

Commit

Permalink
Unconditionally add the import for assertThrows, got a report where t…
Browse files Browse the repository at this point in the history
…he template adds the method successfully but with missing type attribution for assertThrows so the import was missing
  • Loading branch information
sambsnyd committed Nov 21, 2024
1 parent f9cc74c commit a530dbe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration methodDecl
m = m.withBody(m.getBody().withPrefix(thrown.get(0).getPrefix())).withThrows(Collections.emptyList());
}

maybeAddImport("org.junit.jupiter.api.Assertions", "assertThrows");
// Unconditionally add the import for assertThrows, got a report where the above template adds the method successfully
// but with missing type attribution for assertThrows so the import was missing
maybeAddImport("org.junit.jupiter.api.Assertions", "assertThrows", false);

if (expectMessageMethodInvocation != null && !isExpectMessageArgAMatcher && m.getBody() != null) {
m = JavaTemplate.builder("assertTrue(exception.getMessage().contains(#{any(java.lang.String)}));")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
.build()
.apply(updateCursor(m), m.getCoordinates().replaceBody(), cta.expectedException, lambda);
m = m.withThrows(Collections.emptyList());
maybeAddImport("org.junit.jupiter.api.Assertions", "assertThrows");
// Unconditionally add the import for assertThrows, got a report where the above template adds the method successfully
// but with missing type attribution for assertThrows so the import was missing
maybeAddImport("org.junit.jupiter.api.Assertions", "assertThrows", false);
}
}
if (cta.timeout != null) {
Expand Down

0 comments on commit a530dbe

Please sign in to comment.