diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThat.java index f5dfa646b..f949d0b10 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertArrayEqualsToAssertThat.java @@ -57,7 +57,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport(JUNIT); - maybeAddImport(ASSERTJ, "assertThat", false); + maybeAddImport(ASSERTJ, "assertThat"); List args = md.getArguments(); Expression expected = args.get(0); @@ -79,7 +79,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu .apply(getCursor(), md.getCoordinates().replace(), actual, message, expected); } - maybeAddImport(ASSERTJ, "within", false); + maybeAddImport(ASSERTJ, "within"); Expression delta = args.get(2); if (args.size() == 3) { return JavaTemplate.builder("assertThat(#{anyArray()}).containsExactly(#{anyArray()}, within(" + widenedTo(deltaType, delta) + "));") diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThat.java index 637e553ea..aa8f3392d 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertEqualsToAssertThat.java @@ -59,7 +59,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport(JUNIT); - maybeAddImport(ASSERTJ, "assertThat", false); + maybeAddImport(ASSERTJ, "assertThat"); List args = mi.getArguments(); Expression expected = args.get(0); @@ -96,7 +96,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu .build() .apply(getCursor(), mi.getCoordinates().replace(), actual, expected); } - maybeAddImport(ASSERTJ, "within", false); + maybeAddImport(ASSERTJ, "within"); return JavaTemplate.builder("assertThat(" + widenedTo(deltaType, actual) + ").isCloseTo(#{any()}, within(" + widenedTo(deltaType, delta) + "));") .staticImports(ASSERTJ + ".assertThat", ASSERTJ + ".within") .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")) @@ -113,7 +113,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu .build() .apply(getCursor(), mi.getCoordinates().replace(), actual, message, expected); } - maybeAddImport(ASSERTJ, "within", false); + maybeAddImport(ASSERTJ, "within"); return JavaTemplate.builder("assertThat(" + widenedTo(deltaType, actual) + ").as(#{any()}).isCloseTo(#{any()}, within(" + widenedTo(deltaType, delta) + "));") .staticImports(ASSERTJ + ".assertThat", ASSERTJ + ".within") .imports("java.util.function.Supplier") diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertFalseToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertFalseToAssertThat.java index 7dad38703..2f339a3c5 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertFalseToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertFalseToAssertThat.java @@ -51,7 +51,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport("org.junit.jupiter.api.Assertions"); - maybeAddImport("org.assertj.core.api.Assertions", "assertThat", false); + maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); List args = mi.getArguments(); Expression actual = args.get(0); diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertInstanceOfToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertInstanceOfToAssertThat.java index c67493171..dbc8c4723 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertInstanceOfToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertInstanceOfToAssertThat.java @@ -50,7 +50,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport("org.junit.jupiter.api.Assertions"); - maybeAddImport("org.assertj.core.api.Assertions", "assertThat", false); + maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); Expression expected = mi.getArguments().get(0); Expression actual = mi.getArguments().get(1); diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThat.java index c22715966..089dd5838 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotEqualsToAssertThat.java @@ -57,7 +57,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport(JUNIT); - maybeAddImport(ASSERTJ, "assertThat", false); + maybeAddImport(ASSERTJ, "assertThat"); List args = mi.getArguments(); Expression expected = args.get(0); @@ -84,7 +84,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu .apply(getCursor(), mi.getCoordinates().replace(), actual, message, expected); } - maybeAddImport(ASSERTJ, "within", false); + maybeAddImport(ASSERTJ, "within"); Expression delta = args.get(2); if (args.size() == 3) { return JavaTemplate.builder("assertThat(" + widenedTo(deltaType, actual) + ").isNotCloseTo(#{any()}, within(" + widenedTo(deltaType, delta) + "));") diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotNullToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotNullToAssertThat.java index 690f27c62..6fe506047 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotNullToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNotNullToAssertThat.java @@ -51,7 +51,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport("org.junit.jupiter.api.Assertions"); - maybeAddImport("org.assertj.core.api.Assertions", "assertThat", false); + maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); List args = mi.getArguments(); Expression actual = args.get(0); diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNullToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNullToAssertThat.java index b032c4a5e..1cc603e0b 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNullToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertNullToAssertThat.java @@ -51,7 +51,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport("org.junit.jupiter.api.Assertions"); - maybeAddImport("org.assertj.core.api.Assertions", "assertThat", false); + maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); List args = mi.getArguments(); Expression actual = args.get(0); diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertSameToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertSameToAssertThat.java index 9c7fb5aa1..e5a4dcc49 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertSameToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertSameToAssertThat.java @@ -51,7 +51,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport("org.junit.jupiter.api.Assertions"); - maybeAddImport("org.assertj.core.api.Assertions", "assertThat", false); + maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); List args = mi.getArguments(); Expression expected = args.get(0); diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertTrueToAssertThat.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertTrueToAssertThat.java index 3bedf1e47..01fd16eef 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertTrueToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitAssertTrueToAssertThat.java @@ -51,7 +51,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport("org.junit.jupiter.api.Assertions"); - maybeAddImport("org.assertj.core.api.Assertions", "assertThat", false); + maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); List args = mi.getArguments(); Expression actual = args.get(0); diff --git a/src/main/java/org/openrewrite/java/testing/assertj/JUnitFailToAssertJFail.java b/src/main/java/org/openrewrite/java/testing/assertj/JUnitFailToAssertJFail.java index 602de2670..8bd8502e9 100644 --- a/src/main/java/org/openrewrite/java/testing/assertj/JUnitFailToAssertJFail.java +++ b/src/main/java/org/openrewrite/java/testing/assertj/JUnitFailToAssertJFail.java @@ -97,7 +97,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport(JUNIT + ".fail"); - maybeAddImport(ASSERTJ, "fail", false); + maybeAddImport(ASSERTJ, "fail"); List arguments = mi.getArguments(); String anyArgs = String.join(",", nCopies(arguments.size(), "#{any()}")); diff --git a/src/main/java/org/openrewrite/java/testing/jmockit/JMockitBlockRewriter.java b/src/main/java/org/openrewrite/java/testing/jmockit/JMockitBlockRewriter.java index 615b35e98..e6d7ee1d1 100644 --- a/src/main/java/org/openrewrite/java/testing/jmockit/JMockitBlockRewriter.java +++ b/src/main/java/org/openrewrite/java/testing/jmockit/JMockitBlockRewriter.java @@ -315,9 +315,7 @@ private void rewriteResult(J.MethodInvocation invocation, List resul } setNextStatementCoordinates(++numStatementsAdded); - // do this last making sure rewrite worked and specify onlyifReferenced=false because framework cannot find static - // reference for when method invocation when another static mockit reference is added - visitor.maybeAddImport(MOCKITO_IMPORT_FQN_PREFX, "when", false); + visitor.maybeAddImport(MOCKITO_IMPORT_FQN_PREFX, "when"); if (lenient) { visitor.maybeAddImport(MOCKITO_IMPORT_FQN_PREFX, "lenient"); } @@ -431,7 +429,7 @@ private void rewriteVerify(J.MethodInvocation invocation, @Nullable Expression t setNextStatementCoordinates(++numStatementsAdded); } - visitor.maybeAddImport(MOCKITO_IMPORT_FQN_PREFX, "verify", false); + visitor.maybeAddImport(MOCKITO_IMPORT_FQN_PREFX, "verify"); if (!verificationMode.isEmpty()) { visitor.maybeAddImport(MOCKITO_IMPORT_FQN_PREFX, verificationMode); } @@ -439,7 +437,7 @@ private void rewriteVerify(J.MethodInvocation invocation, @Nullable Expression t private void rewriteFullVerify(List mocks) { if (rewriteMultipleMocks(mocks, VERIFY_NO_INTERACTIONS_TEMPLATE_PREFIX)) { // verifyNoMoreInteractions(mock1, mock2 ... - visitor.maybeAddImport(MOCKITO_IMPORT_FQN_PREFX, "verifyNoMoreInteractions", false); + visitor.maybeAddImport(MOCKITO_IMPORT_FQN_PREFX, "verifyNoMoreInteractions"); } } @@ -450,7 +448,7 @@ private void rewriteInOrderVerify(List mocks) { } sb.append(VERIFY_IN_ORDER_TEMPLATE_PREFIX_2); // InOrder inOrder1 = inOrder( if (rewriteMultipleMocks(mocks, sb.toString())) { // InOrder inOrder = inOrder(mock1, mock2 ..) - visitor.maybeAddImport(MOCKITO_IMPORT_FQN_PREFX, "inOrder", false); + visitor.maybeAddImport(MOCKITO_IMPORT_FQN_PREFX, "inOrder"); visitor.maybeAddImport(IN_ORDER_IMPORT_FQN); } } diff --git a/src/main/java/org/openrewrite/java/testing/jmockit/JMockitMockUpToMockito.java b/src/main/java/org/openrewrite/java/testing/jmockit/JMockitMockUpToMockito.java index cb7357b08..8214d604b 100644 --- a/src/main/java/org/openrewrite/java/testing/jmockit/JMockitMockUpToMockito.java +++ b/src/main/java/org/openrewrite/java/testing/jmockit/JMockitMockUpToMockito.java @@ -261,8 +261,8 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration methodDecl } maybeAddImport(MOCKITO_CONSTRUCTION_IMPORT); - maybeAddImport("org.mockito.Answers", "CALLS_REAL_METHODS", false); - maybeAddImport("org.mockito.AdditionalAnswers", "delegatesTo", false); + maybeAddImport("org.mockito.Answers", "CALLS_REAL_METHODS"); + maybeAddImport("org.mockito.AdditionalAnswers", "delegatesTo"); } List statements = md.getBody().getStatements(); @@ -300,7 +300,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration methodDecl maybeRemoveImport(JMOCKIT_MOCK_IMPORT); maybeRemoveImport(JMOCKIT_MOCKUP_IMPORT); - maybeAddImport(MOCKITO_ALL_IMPORT.replace(".*", ""), "*", false); + maybeAddImport(MOCKITO_ALL_IMPORT.replace(".*", ""), "*"); doAfterVisit(new LambdaBlockToExpression().getVisitor()); doAfterVisit(ShortenFullyQualifiedTypeReferences.modifyOnly(md)); @@ -308,7 +308,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration methodDecl } private String getMatcher(JavaType s) { - maybeAddImport(MOCKITO_MATCHER_IMPORT.replace(".*", ""), "*", false); + maybeAddImport(MOCKITO_MATCHER_IMPORT.replace(".*", ""), "*"); if (s instanceof JavaType.Primitive) { switch (s.toString()) { case "int": diff --git a/src/main/java/org/openrewrite/java/testing/junit5/AssertThrowsOnLastStatement.java b/src/main/java/org/openrewrite/java/testing/junit5/AssertThrowsOnLastStatement.java index b9614b01b..cac453b5a 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/AssertThrowsOnLastStatement.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/AssertThrowsOnLastStatement.java @@ -194,17 +194,17 @@ private Statement extractExpressionArguments(J.Block body, Statement lambdaState // TODO look into possibly employing `TypeUtils.toString()` here, possibly with some changes upstream allowing for non-fully-qualified names variableTypeShort = buildParameterizedTypeName(paramType); variableTypeFqn = paramType; - maybeAddImport(paramType.getFullyQualifiedName(), false); + maybeAddImport(paramType.getFullyQualifiedName()); for (JavaType typeParam : paramType.getTypeParameters()) { if (typeParam instanceof JavaType.FullyQualified) { - maybeAddImport(((JavaType.FullyQualified) typeParam).getFullyQualifiedName(), false); + maybeAddImport(((JavaType.FullyQualified) typeParam).getFullyQualifiedName()); } } } else if (type instanceof JavaType.FullyQualified) { JavaType.FullyQualified aClass = (JavaType.FullyQualified) type; variableTypeShort = aClass.getClassName(); variableTypeFqn = aClass; - maybeAddImport(aClass.getFullyQualifiedName(), false); + maybeAddImport(aClass.getFullyQualifiedName()); } Cursor blockCursor = new Cursor(getCursor(), body); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java b/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java index 342175024..fb1d38f7c 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java @@ -206,7 +206,7 @@ public J.Block visitBlock(J.Block block, ExecutionContext ctx) { exceptionClass = "Exception.class"; } - maybeAddImport("org.junit.jupiter.api.Assertions", "assertThrows", false); + maybeAddImport("org.junit.jupiter.api.Assertions", "assertThrows"); Statement firstExpectedExceptionMethodInvocation = getCursor().getMessage(FIRST_EXPECTED_EXCEPTION_METHOD_INVOCATION); String templateString = exceptionClass instanceof String ? "#{}assertThrows(#{}, () -> #{any()});" : "#{}assertThrows(#{any()}, () -> #{any()});"; b = JavaTemplate.builder(templateString) diff --git a/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java b/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java index d9b3b44e2..4729ec554 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/UpdateTestAnnotation.java @@ -151,9 +151,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex .apply(updateCursor(m), m.getCoordinates().replaceBody(), cta.expectedException, lambda); // Only remove the throws clause for the specific exception being tested m = removeSpecificThrowsClause(m, cta.expectedException); - // 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); + maybeAddImport("org.junit.jupiter.api.Assertions", "assertThrows"); } } if (cta.timeout != null) { diff --git a/src/main/java/org/openrewrite/java/testing/mockito/AnyStringToNullable.java b/src/main/java/org/openrewrite/java/testing/mockito/AnyStringToNullable.java index 8c6388f6a..1db090e2f 100644 --- a/src/main/java/org/openrewrite/java/testing/mockito/AnyStringToNullable.java +++ b/src/main/java/org/openrewrite/java/testing/mockito/AnyStringToNullable.java @@ -52,7 +52,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu J.MethodInvocation mi = super.visitMethodInvocation(method, ctx); if (ANY_STRING.matches(mi)) { maybeRemoveImport("org.mockito.Mockito.anyString"); - maybeAddImport("org.mockito.ArgumentMatchers", "nullable", false); + maybeAddImport("org.mockito.ArgumentMatchers", "nullable"); return JavaTemplate.builder("nullable(String.class)") .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "mockito-core-3.12")) .staticImports("org.mockito.ArgumentMatchers.nullable") diff --git a/src/main/java/org/openrewrite/java/testing/mockito/MockitoWhenOnStaticToMockStatic.java b/src/main/java/org/openrewrite/java/testing/mockito/MockitoWhenOnStaticToMockStatic.java index 80ec1b193..be050e517 100644 --- a/src/main/java/org/openrewrite/java/testing/mockito/MockitoWhenOnStaticToMockStatic.java +++ b/src/main/java/org/openrewrite/java/testing/mockito/MockitoWhenOnStaticToMockStatic.java @@ -238,8 +238,11 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex J.ClassDeclaration after = JavaTemplate .builder(String.format("private%s MockedStatic<%s> %s;", staticSetup ? " static" : "", className, variableName)) .contextSensitive() + .imports("org.mockito.MockedStatic") + .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "mockito-core-5")) .build() .apply(updateCursor(classDecl), classDecl.getBody().getCoordinates().firstStatement()); + maybeAddImport("org.mockito.MockedStatic"); List afterStatements = after.getBody().getStatements(); AnnotationMatcher specificBeforeMatcher = new AnnotationMatcher(matchedAnnotation); @@ -298,7 +301,7 @@ private JavaTemplate javaTemplateMockStatic(J.MethodInvocation stubbing, String if (((J.MethodInvocation) requireNonNull(stubbing.getSelect())).getSelect() != null) { maybeRemoveImport("org.mockito.Mockito"); } - maybeAddImport("org.mockito.MockedStatic", false); + maybeAddImport("org.mockito.MockedStatic"); maybeAddImport("org.mockito.Mockito", "mockStatic"); return JavaTemplate.builder(code) .contextSensitive() diff --git a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsDeepToAssertThat.java b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsDeepToAssertThat.java index dee4d9e58..07c75f607 100644 --- a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsDeepToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsDeepToAssertThat.java @@ -59,7 +59,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport("org.testng.Assert"); - maybeAddImport(ASSERTJ, "assertThat", false); + maybeAddImport(ASSERTJ, "assertThat"); List args = method.getArguments(); Expression actual = args.get(0); diff --git a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsNoOrderToAssertThat.java b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsNoOrderToAssertThat.java index 58e928ed7..b4a2a1e69 100644 --- a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsNoOrderToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsNoOrderToAssertThat.java @@ -54,7 +54,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport("org.testng.Assert"); - maybeAddImport("org.assertj.core.api.Assertions", "assertThat", false); + maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); List args = method.getArguments(); Expression actual = args.get(0); diff --git a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsToAssertThat.java b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsToAssertThat.java index 3fb075410..add13afd9 100644 --- a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertEqualsToAssertThat.java @@ -60,7 +60,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu JavaType actualType = actual.getType(); maybeRemoveImport("org.testng.Assert"); - maybeAddImport(ASSERTJ, "assertThat", false); + maybeAddImport(ASSERTJ, "assertThat"); if (TypeUtils.asArray(actualType) != null) { return arrayAssertion(method, args, actual, expected, ctx); @@ -89,7 +89,7 @@ private J.MethodInvocation arrayAssertion(J.MethodInvocation method, List args = method.getArguments(); Expression list = args.get(0); diff --git a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertNotEqualsToAssertThat.java b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertNotEqualsToAssertThat.java index 870c649ae..6e3b70aa5 100644 --- a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertNotEqualsToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertNotEqualsToAssertThat.java @@ -64,7 +64,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport("org.testng.Assert"); - maybeAddImport(ASSERTJ, "assertThat", false); + maybeAddImport(ASSERTJ, "assertThat"); if (args.size() == 2) { method = JavaTemplate.builder("assertThat(#{any()}).isNotEqualTo(#{any()});") @@ -87,7 +87,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu .build() .apply(getCursor(), method.getCoordinates().replace(), actual, expected); } else { - maybeAddImport(ASSERTJ, "within", false); + maybeAddImport(ASSERTJ, "within"); method = JavaTemplate.builder("assertThat(#{any()}).isNotCloseTo(#{any()}, within(#{any()}));") .staticImports(ASSERTJ + ".assertThat", ASSERTJ + ".within") .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")) @@ -103,7 +103,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu .build() .apply(getCursor(), method.getCoordinates().replace(), actual, message, expected); } else { - maybeAddImport(ASSERTJ, "within", false); + maybeAddImport(ASSERTJ, "within"); method = JavaTemplate.builder("assertThat(#{any()}).as(#{any(String)}).isNotCloseTo(#{any()}, within(#{any()}));") .staticImports(ASSERTJ + ".assertThat", ASSERTJ + ".within") .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")) diff --git a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertNotSameToAssertThat.java b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertNotSameToAssertThat.java index b2b005c89..9fe4873e1 100644 --- a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertNotSameToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertNotSameToAssertThat.java @@ -51,7 +51,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport("org.testng.Assert"); - maybeAddImport("org.assertj.core.api.Assertions", "assertThat", false); + maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); List args = method.getArguments(); Expression actual = args.get(0); diff --git a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertSameToAssertThat.java b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertSameToAssertThat.java index f0d666fe2..c09429825 100644 --- a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertSameToAssertThat.java +++ b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertSameToAssertThat.java @@ -51,7 +51,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } maybeRemoveImport("org.testng.Assert"); - maybeAddImport("org.assertj.core.api.Assertions", "assertThat", false); + maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); List args = method.getArguments(); Expression actual = args.get(0); diff --git a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertionToAssertJ.java b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertionToAssertJ.java index 4673a93f2..2fdc89ab2 100644 --- a/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertionToAssertJ.java +++ b/src/main/java/org/openrewrite/java/testing/testng/TestNgAssertionToAssertJ.java @@ -140,11 +140,11 @@ private J.MethodInvocation equals(J.MethodInvocation method, ExecutionContext ct private J.MethodInvocation apply(J.MethodInvocation method, ExecutionContext ctx, String template, boolean usesWithin, Object... params) { - maybeAddImport("org.assertj.core.api.Assertions", "assertThat", false); + maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); JavaTemplate.Builder builder = JavaTemplate.builder(template) .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")); if (usesWithin) { - maybeAddImport("org.assertj.core.api.Assertions", "within", false); + maybeAddImport("org.assertj.core.api.Assertions", "within"); builder = builder.staticImports("org.assertj.core.api.Assertions.assertThat", "org.assertj.core.api.Assertions.within"); } else { builder = builder.staticImports("org.assertj.core.api.Assertions.assertThat"); @@ -169,7 +169,7 @@ private J.MethodInvocation binary(J.MethodInvocation method, ExecutionContext ct } private J.MethodInvocation fail(J.MethodInvocation method, ExecutionContext ctx, List args) { - maybeAddImport("org.assertj.core.api.Assertions", "fail", false); + maybeAddImport("org.assertj.core.api.Assertions", "fail"); // A no-arg `fail()` call carries a single J.Empty argument (not an empty list). AssertJ's no-arg // static fail() does not resolve through the template classpath, so emit an empty message, matching // JUnitFailToAssertJFail's convention for the message-less case. diff --git a/src/main/java/org/openrewrite/java/testing/testng/TestNgSoftAssertToAssertJ.java b/src/main/java/org/openrewrite/java/testing/testng/TestNgSoftAssertToAssertJ.java index bb9d40081..2a1bea693 100644 --- a/src/main/java/org/openrewrite/java/testing/testng/TestNgSoftAssertToAssertJ.java +++ b/src/main/java/org/openrewrite/java/testing/testng/TestNgSoftAssertToAssertJ.java @@ -137,7 +137,7 @@ private J.MethodInvocation apply(J.MethodInvocation method, ExecutionContext ctx .javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx, "assertj-core-3")); if (usesWithin) { builder.staticImports("org.assertj.core.api.Assertions.within"); - maybeAddImport("org.assertj.core.api.Assertions", "within", false); + maybeAddImport("org.assertj.core.api.Assertions", "within"); } return builder.build().apply(getCursor(), method.getCoordinates().replace(), params); } diff --git a/src/main/java/org/openrewrite/java/testing/truth/TruthAssertWithMessageToAssertJ.java b/src/main/java/org/openrewrite/java/testing/truth/TruthAssertWithMessageToAssertJ.java index ec9d66804..23858059e 100644 --- a/src/main/java/org/openrewrite/java/testing/truth/TruthAssertWithMessageToAssertJ.java +++ b/src/main/java/org/openrewrite/java/testing/truth/TruthAssertWithMessageToAssertJ.java @@ -63,7 +63,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu maybeRemoveImport("com.google.common.truth.Truth"); maybeRemoveImport("com.google.common.truth.Truth.assertWithMessage"); - maybeAddImport("org.assertj.core.api.Assertions", "assertThat", false); + maybeAddImport("org.assertj.core.api.Assertions", "assertThat"); if (messageArgs.size() == 1) { // Simple message