From 34fde92454f821e23343476859f7ccecf866e94b Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 25 Oct 2026 14:09:37 +0100 Subject: [PATCH] Remove stale `@Disabled` tests, `//noinspection` lines and restating comments --- .../cleanup/AssertionsArgumentOrder.java | 1 - .../testing/cleanup/RemoveEmptyTests.java | 1 - .../testing/cleanup/RemoveTestPrefix.java | 8 -------- .../JMockitAnnotatedArgumentToMockito.java | 5 ----- .../CleanupKotlinJUnit5AssertionImports.java | 10 ---------- .../junit5/CsvSourceToValueSource.java | 5 ----- .../testing/junit5/EnvironmentVariables.java | 19 +++++-------------- .../ExpectedExceptionToAssertThrows.java | 13 +------------ .../junit5/HandleExternalResourceRules.java | 7 +------ .../JUnitParamsRunnerToParameterized.java | 11 ++--------- .../testing/junit5/MigrateJUnitTestCase.java | 1 - .../MockitoJUnitToMockitoExtension.java | 15 +-------------- .../testing/junit5/RemoveObsoleteRunners.java | 1 - .../testing/junit5/RunnerToExtension.java | 1 - .../junit5/TemporaryFolderToTempDir.java | 1 - .../testing/junit5/TestRuleToTestInfo.java | 2 -- .../junit5/TimeoutRuleToClassAnnotation.java | 1 - .../testing/junit5/UseTestMethodOrder.java | 1 - .../testing/mockito/AnyStringToNullable.java | 3 --- .../mockito/CloseUnclosedStaticMocks.java | 6 ------ .../MockConstructionToTryWithResources.java | 4 ---- .../AddTestcontainersAnnotations.java | 8 -------- .../truth/TruthThrowableAssertions.java | 7 ------- .../wiremock/ReplaceSettersWithTransform.java | 2 -- .../JMockitExpectationsToMockitoTest.java | 2 +- .../testing/junit5/AddMissingNestedTest.java | 3 --- .../AssumeNotNullToAssumptionsTest.java | 4 +--- .../UpdateBeforeAfterAnnotationsTest.java | 2 +- 28 files changed, 13 insertions(+), 131 deletions(-) diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/AssertionsArgumentOrder.java b/src/main/java/org/openrewrite/java/testing/cleanup/AssertionsArgumentOrder.java index a38c2ae2f..6c01dfff0 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/AssertionsArgumentOrder.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/AssertionsArgumentOrder.java @@ -97,7 +97,6 @@ public class AssertionsArgumentOrder extends Recipe { matchers.add(JUPITER_ASSERT_ITERABLE_EQUALS_MATCHER); matchers.add(JUPITER_ASSERT_NULL_MATCHER); matchers.addAll(Arrays.asList(TESTNG_MATCHERS)); - //noinspection unchecked PRECONDITION = Preconditions.or(matchers.stream().map(UsesMethod::new).toArray(TreeVisitor[]::new)); } diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/RemoveEmptyTests.java b/src/main/java/org/openrewrite/java/testing/cleanup/RemoveEmptyTests.java index 8473c73a1..87e8bd87b 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/RemoveEmptyTests.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/RemoveEmptyTests.java @@ -60,7 +60,6 @@ public TreeVisitor getVisitor() { maybeRemoveImport(type); } } - //noinspection ConstantConditions return null; } return super.visitMethodDeclaration(method, ctx); diff --git a/src/main/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefix.java b/src/main/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefix.java index d875d10fe..73e9ae74c 100644 --- a/src/main/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefix.java +++ b/src/main/java/org/openrewrite/java/testing/cleanup/RemoveTestPrefix.java @@ -93,7 +93,6 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, ExecutionContext ctx) { J.MethodDeclaration m = super.visitMethodDeclaration(method, ctx); - // Quickly reject invalid methods String simpleName = method.getSimpleName(); int nameLength = simpleName.length(); if (nameLength < 5 || @@ -104,7 +103,6 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, return m; } - // Reject invalid start character boolean snakecase = simpleName.charAt(4) == '_' && 5 < nameLength && Character.isAlphabetic(simpleName.charAt(5)); @@ -112,7 +110,6 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, return m; } - // Avoid reserved keywords String newMethodName = snakecase ? NameCaseConvention.format(NameCaseConvention.LOWER_UNDERSCORE, simpleName.substring(5)) : NameCaseConvention.format(NameCaseConvention.LOWER_CAMEL, simpleName.substring(4)); @@ -120,7 +117,6 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, return m; } - // Prevent conflicts with existing methods JavaType.Method type = m.getMethodType(); if (type == null || methodExists(type, newMethodName)) { return m; @@ -141,12 +137,10 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, for (JavaType.Method declaredMethod : declaringType.getMethods()) { if (declaredMethod.getName().equals(simpleName) && declaredMethod.hasFlags(Flag.Static)) { - // Check for conflict with source method's new name if (TypeUtils.findDeclaredMethod(declaringType, newMethodName, declaredMethod.getParameterTypes()).isPresent()) { return m; } - // Rename the source method too doAfterVisit(new ChangeMethodName( MethodMatcher.methodPattern(declaredMethod), newMethodName, false, false).getVisitor()); @@ -156,7 +150,6 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, } } - // Skip when there's a conflicting static import if (getCursor().getNearestMessage(STATIC_IMPORTS, new HashSet<>()).contains(newMethodName)) { return m; } @@ -176,7 +169,6 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Atomi return m; } - // Rename method and return doAfterVisit(new ChangeMethodName(MethodMatcher.methodPattern(m), newMethodName, false, false).getVisitor()); return m; } diff --git a/src/main/java/org/openrewrite/java/testing/jmockit/JMockitAnnotatedArgumentToMockito.java b/src/main/java/org/openrewrite/java/testing/jmockit/JMockitAnnotatedArgumentToMockito.java index 48f68988f..83ac2bdc0 100644 --- a/src/main/java/org/openrewrite/java/testing/jmockit/JMockitAnnotatedArgumentToMockito.java +++ b/src/main/java/org/openrewrite/java/testing/jmockit/JMockitAnnotatedArgumentToMockito.java @@ -60,14 +60,11 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration methodDecl maybeRemoveImport("mockit.Mocked"); maybeAddImport("org.mockito.Mockito"); - // Create lists to store the mocked parameters and the new type parameters List mockedParameter = new ArrayList<>(); - // Remove any mocked parameters from the method declaration md = md.withParameters(ListUtils.map(parameters, parameter -> { if (parameter instanceof J.VariableDeclarations) { J.VariableDeclarations variableDeclarations = (J.VariableDeclarations) parameter; - // Check if the parameter has the annotation "mockit.Mocked or mockit.Injectable" if (!FindAnnotations.find(variableDeclarations, "mockit.Injectable").isEmpty() || !FindAnnotations.find(variableDeclarations, "mockit.Mocked").isEmpty() ) { mockedParameter.add(variableDeclarations); @@ -77,7 +74,6 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration methodDecl return parameter; })); - // Add mocked parameters as statements to the method declaration if (!mockedParameter.isEmpty()) { JavaTemplate addStatementsTemplate = JavaTemplate.builder("#{} #{} = Mockito.mock(#{}.class);\n") .javaParser(getJavaParser(ctx)) @@ -87,7 +83,6 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration methodDecl // Retain argument order by iterating in reverse for (int i = mockedParameter.size() - 1; i >= 0; i--) { J.VariableDeclarations variableDeclarations = mockedParameter.get(i); - // Apply the template and update the method declaration md = addStatementsTemplate.apply(updateCursor(md), md.getBody().getCoordinates().firstStatement(), variableDeclarations.getTypeExpression().toString(), diff --git a/src/main/java/org/openrewrite/java/testing/junit5/CleanupKotlinJUnit5AssertionImports.java b/src/main/java/org/openrewrite/java/testing/junit5/CleanupKotlinJUnit5AssertionImports.java index 2b0b4ecd6..c3d3eb0a1 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/CleanupKotlinJUnit5AssertionImports.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/CleanupKotlinJUnit5AssertionImports.java @@ -27,16 +27,6 @@ import static java.util.stream.Collectors.toList; -/** - * In Kotlin files, when both {@code import org.junit.jupiter.api.*} and static imports from - * {@code org.junit.jupiter.api.Assertions} are present, the Kotlin compiler cannot resolve - * which assertion method to use due to ambiguity between the Java static methods and the - * Kotlin extension functions. - *

- * This recipe removes the static Assertions imports in Kotlin files when the wildcard import - * {@code org.junit.jupiter.api.*} is present, allowing the Kotlin extension functions to be - * used instead. The Kotlin extensions have better nullability handling for Kotlin code. - */ public class CleanupKotlinJUnit5AssertionImports extends Recipe { @Getter diff --git a/src/main/java/org/openrewrite/java/testing/junit5/CsvSourceToValueSource.java b/src/main/java/org/openrewrite/java/testing/junit5/CsvSourceToValueSource.java index fb88e1582..d7038599c 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/CsvSourceToValueSource.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/CsvSourceToValueSource.java @@ -66,7 +66,6 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex J.MethodDeclaration m = super.visitMethodDeclaration(method, ctx); boolean kotlin = getCursor().firstEnclosing(K.CompilationUnit.class) != null; - // Check if method has exactly one parameter if (m.getParameters().size() != 1 || m.getParameters().get(0) instanceof J.Empty) { return m; } @@ -78,11 +77,9 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex return m; } - // Find @CsvSource annotation for (J.Annotation annotation : m.getLeadingAnnotations()) { Optional annotated = new Annotated.Matcher(CSV_SOURCE_MATCHER).get(annotation, getCursor()); if (annotated.isPresent() && annotation.getArguments() != null && annotation.getArguments().size() == 1) { - // Get the parameter type String paramType = getParameterType((J.VariableDeclarations) m.getParameters().get(0)); if (paramType == null) { return m; @@ -134,13 +131,11 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex } } - // Build a new ValueSource annotation String valueSourceAnnotationTemplate = buildValueSourceAnnotation(paramType, values, fromTextBlock, kotlin); if (valueSourceAnnotationTemplate == null) { return m; } - // Replace the annotation maybeRemoveImport("org.junit.jupiter.params.provider.CsvSource"); maybeAddImport("org.junit.jupiter.params.provider.ValueSource"); J.MethodDeclaration replaced = applyValueSourceTemplate(valueSourceAnnotationTemplate, annotation, kotlin, ctx); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/EnvironmentVariables.java b/src/main/java/org/openrewrite/java/testing/junit5/EnvironmentVariables.java index 223265a1c..39e68a4bc 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/EnvironmentVariables.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/EnvironmentVariables.java @@ -16,7 +16,6 @@ package org.openrewrite.java.testing.junit5; import lombok.Getter; -import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Preconditions; @@ -52,11 +51,10 @@ public class EnvironmentVariables extends Recipe { "library."; @Override - public @NonNull TreeVisitor getVisitor() { + public TreeVisitor getVisitor() { return Preconditions.check(new UsesType<>(ENVIRONMENT_VARIABLES, false), new JavaVisitor() { @Override - public @NonNull J visitCompilationUnit( - J.@NonNull CompilationUnit cu, @NonNull ExecutionContext ctx) { + public J visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) { maybeRemoveImport(RULE); maybeRemoveImport(CLASS_RULE); maybeRemoveImport(ENVIRONMENT_VARIABLES); @@ -69,23 +67,20 @@ public class EnvironmentVariables extends Recipe { } @Override - public @NonNull J visitClassDeclaration( - J.@NonNull ClassDeclaration classDecl, @NonNull ExecutionContext ctx) { + public J visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { J.ClassDeclaration cd = (J.ClassDeclaration) super.visitClassDeclaration(classDecl, ctx); Boolean hasEnvVarRule = getCursor().getMessage(HAS_ENV_VAR_RULE); if (!Boolean.TRUE.equals(hasEnvVarRule)) { return cd; } - // Add @ExtendWith(SystemStubsExtension.class) annotation to class. return systemStubExtensionTemplate(ctx).apply( updateCursor(cd), cd.getCoordinates().addAnnotation(comparing(J.Annotation::getSimpleName))); } @Override - public @NonNull J visitVariableDeclarations( - J.@NonNull VariableDeclarations variableDecls, @NonNull ExecutionContext ctx) { + public J visitVariableDeclarations(J.VariableDeclarations variableDecls, ExecutionContext ctx) { // missing type attribution, possibly parsing error. if (variableDecls.getType() == null || !TypeUtils.isAssignableTo(ENVIRONMENT_VARIABLES, variableDecls.getType())) { return variableDecls; @@ -100,7 +95,6 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct .visit(variableDecls, ctx, getCursor().getParentOrThrow()); if (variableDecls != vd) { - // put message to first enclosing ClassDeclaration, to inform that we have an env var rule. getCursor() .dropParentUntil(J.ClassDeclaration.class::isInstance) .putMessage(HAS_ENV_VAR_RULE, true); @@ -110,11 +104,8 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct } @Override - public @Nullable J visitMethodInvocation( - J.@NonNull MethodInvocation method, @NonNull ExecutionContext ctx) { - + public @Nullable J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) { J.MethodInvocation m = (J.MethodInvocation) super.visitMethodInvocation(method, ctx); - // Replace EnvironmentVariables.clear() with EnvironmentVariables.remove() if (ENV_VAR_CLEAR.matches(method) && m.getSelect() != null /* NullAway */) { int argCount = argCount(m); J j = 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..6d0a8fac1 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/ExpectedExceptionToAssertThrows.java @@ -40,18 +40,7 @@ import static java.util.Collections.emptyList; import static org.openrewrite.Tree.randomId; -/** - * Replace usages of JUnit 4's @Rule ExpectedException with JUnit 5 Assertions. - *

- * Supported ExpectedException methods: - * expect(java.lang.Class) - * expect(org.hamcrest.Matcher) - * expectMessage(java.lang.String) - * expectMessage(org.hamcrest.Matcher) - * expectCause(org.hamcrest.Matcher) - *

- * Does not currently support migration of ExpectedException.isAnyExceptionExpected(). - */ +// ExpectedException.isAnyExceptionExpected() is not migrated. public class ExpectedExceptionToAssertThrows extends Recipe { @Getter diff --git a/src/main/java/org/openrewrite/java/testing/junit5/HandleExternalResourceRules.java b/src/main/java/org/openrewrite/java/testing/junit5/HandleExternalResourceRules.java index bc3ffbe41..b01ff327b 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/HandleExternalResourceRules.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/HandleExternalResourceRules.java @@ -34,12 +34,7 @@ import static java.lang.String.format; import static java.util.Comparator.comparing; -/** - * A recipe that handles the usage of the junit-4 ExternalResourceRule's by adding - * the @ExtendWith(ExternalResourceSupport.class) annotation to the test class. - * In declarative recipe list, this should be the last recipe, to handle any junit4 ExternalResourceRules, which - * are not explicitly handled. - */ +// Run this last in a declarative recipe list, so it only handles the ExternalResource rules no other recipe migrated. public class HandleExternalResourceRules extends Recipe { private static final AnnotationMatcher ANY_RULE_ANNOTATION_MATCHER = new AnnotationMatcher("@org.junit.*Rule", true); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java b/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java index ae8a11053..fb9f9da75 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/JUnitParamsRunnerToParameterized.java @@ -32,15 +32,8 @@ import static java.util.Collections.emptyList; import static java.util.stream.Collectors.joining; -/** - * Converts Pragmatists JUnitParamsRunner tests to their JUnit 5 ParameterizedTest and associated MethodSource equivalent - * ... - * Supports the following conversions - * `@Parameters` annotation without arguments and default `parametersFor...` init-method exists - * `@Parameters(method = "...")` annotation with defined method references - * `@Parameters(named = "...")` and associated `@NamedParameter` init-method - * Unsupported tests are identified with a comment on the associated `@Parameters(...)` annotation. - */ +// Converts `@Parameters` without arguments (with a `parametersFor...` method), `@Parameters(method = "...")` and `@Parameters(named = "...")` with a `@NamedParameter` method. +// Other `@Parameters(...)` annotations get a comment marking the test as unsupported. public class JUnitParamsRunnerToParameterized extends Recipe { private static final AnnotationMatcher RUN_WITH_JUNIT_PARAMS_ANNOTATION_MATCHER = new AnnotationMatcher("@org.junit.runner.RunWith(junitparams.JUnitParamsRunner.class)"); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java b/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java index bd1d84c1d..56c841b15 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/MigrateJUnitTestCase.java @@ -196,7 +196,6 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex // If the class no longer extends TestCase there should no longer be calls to TestCase.super() // Plenty of edge cases around classes which extend classes which extend TestCase this doesn't account for if (TEST_CASE_SUPER_MATCHER.matches(method)) { - //noinspection DataFlowIssue return null; } return super.visitMethodInvocation(method, ctx); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/MockitoJUnitToMockitoExtension.java b/src/main/java/org/openrewrite/java/testing/junit5/MockitoJUnitToMockitoExtension.java index eb0f22252..1d0519591 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/MockitoJUnitToMockitoExtension.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/MockitoJUnitToMockitoExtension.java @@ -41,20 +41,7 @@ import static java.util.Comparator.comparing; import static java.util.stream.Collectors.toList; -/** - * Replaces JUnit 4 MockitoJUnit rules with JUnit MockitoExtension. - *

- * Supported MockitoJUnit methods: - * #rule() - * #testRule() - *

- * Does not currently support @Incubating MockitoJUnit.collector(). - * - * @implNote collector() is designed to aggregate multiple verifications into a single output. - * Refactoring the method may be fairly complex and would likely benefit from being a separate recipe. - *

- * Must be run in the JUnit 5 suite. - */ +// MockitoJUnit.collector() is not migrated: it aggregates verifications into a single report, which would need a recipe of its own. public class MockitoJUnitToMockitoExtension extends Recipe { @Getter diff --git a/src/main/java/org/openrewrite/java/testing/junit5/RemoveObsoleteRunners.java b/src/main/java/org/openrewrite/java/testing/junit5/RemoveObsoleteRunners.java index d5debcdfd..4540cc7e0 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/RemoveObsoleteRunners.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/RemoveObsoleteRunners.java @@ -50,7 +50,6 @@ public class RemoveObsoleteRunnersVisitor extends JavaIsoVisitor { if (statement instanceof J.VariableDeclarations) { - //noinspection ConstantConditions if (TypeUtils.isOfClassType(((J.VariableDeclarations) statement).getTypeExpression().getType(), "org.junit.rules.Timeout")) { List variables = ((J.VariableDeclarations) statement).getVariables(); diff --git a/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java b/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java index 862148d18..c6f517c90 100644 --- a/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java +++ b/src/main/java/org/openrewrite/java/testing/junit5/UseTestMethodOrder.java @@ -45,7 +45,6 @@ public TreeVisitor getVisitor() { public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { J.ClassDeclaration cd = classDecl; - //noinspection DataFlowIssue Set methodOrders = FindAnnotations.find(cd.withBody(null), "@org.junit.FixMethodOrder"); if (!methodOrders.isEmpty()) { 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..42ba7c65d 100644 --- a/src/main/java/org/openrewrite/java/testing/mockito/AnyStringToNullable.java +++ b/src/main/java/org/openrewrite/java/testing/mockito/AnyStringToNullable.java @@ -29,9 +29,6 @@ import java.time.Duration; -/** - * Replace Mockito 1.x `anyString()` with `nullable(String.class)` - */ public class AnyStringToNullable extends Recipe { private static final MethodMatcher ANY_STRING = new MethodMatcher("org.mockito.Mockito anyString()"); diff --git a/src/main/java/org/openrewrite/java/testing/mockito/CloseUnclosedStaticMocks.java b/src/main/java/org/openrewrite/java/testing/mockito/CloseUnclosedStaticMocks.java index ef9338807..42cf4d4a8 100644 --- a/src/main/java/org/openrewrite/java/testing/mockito/CloseUnclosedStaticMocks.java +++ b/src/main/java/org/openrewrite/java/testing/mockito/CloseUnclosedStaticMocks.java @@ -38,12 +38,6 @@ import static org.openrewrite.java.VariableNameUtils.GenerationStrategy.INCREMENT_NUMBER; import static org.openrewrite.java.VariableNameUtils.generateVariableName; -/** - * Ensures that all mockStatic calls are properly closed. - * If mockStatic is in lifecycle methods like @BeforeEach or @BeforeAll, - * creates a class variable and closes it in @AfterEach or @AfterAll. - * If mockStatic is inside a test method, wraps it in a try-with-resources block. - */ public class CloseUnclosedStaticMocks extends Recipe { private static final MethodMatcher MOCKED_STATIC_CLOSE_MATCHER = new MethodMatcher("org.mockito.ScopedMock close*(..)"); diff --git a/src/main/java/org/openrewrite/java/testing/mockito/MockConstructionToTryWithResources.java b/src/main/java/org/openrewrite/java/testing/mockito/MockConstructionToTryWithResources.java index 8fa8c340e..5d1a1e5ef 100644 --- a/src/main/java/org/openrewrite/java/testing/mockito/MockConstructionToTryWithResources.java +++ b/src/main/java/org/openrewrite/java/testing/mockito/MockConstructionToTryWithResources.java @@ -38,10 +38,6 @@ import static java.util.stream.Collectors.toSet; import static org.openrewrite.Tree.randomId; -/** - * Wraps `MockedConstruction` variable declarations with explicit `.close()` calls - * into try-with-resources blocks, removing the explicit close call. - */ public class MockConstructionToTryWithResources extends Recipe { private static final MethodMatcher MOCK_CONSTRUCTION_MATCHER = new MethodMatcher("org.mockito.Mockito mockConstruction(..)"); diff --git a/src/main/java/org/openrewrite/java/testing/testcontainers/AddTestcontainersAnnotations.java b/src/main/java/org/openrewrite/java/testing/testcontainers/AddTestcontainersAnnotations.java index 7ef30ad6a..149eae3af 100644 --- a/src/main/java/org/openrewrite/java/testing/testcontainers/AddTestcontainersAnnotations.java +++ b/src/main/java/org/openrewrite/java/testing/testcontainers/AddTestcontainersAnnotations.java @@ -31,11 +31,6 @@ import static java.util.Comparator.comparing; -/** - * An OpenRewrite recipe that migrates JUnit 4 Testcontainers {@code @Rule} or {@code @ClassRule} - * fields to JUnit 5's {@code @Container} and adds the {@code @Testcontainers} annotation to the - * class if necessary. - */ public class AddTestcontainersAnnotations extends Recipe { private static final String CLASS_RULE_FQN = "org.junit.ClassRule"; private static final String RULE_FQN = "org.junit.Rule"; @@ -70,7 +65,6 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDeclarat return cd; } - // Add class level annotation maybeAddImport(TESTCONTAINERS_FQN); return JavaTemplate.builder("@Testcontainers") .imports(TESTCONTAINERS_FQN) @@ -89,7 +83,6 @@ public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations v return varDecls; } - // Remove ClassRule/Rule annotations J.VariableDeclarations vd = varDecls.withLeadingAnnotations(ListUtils.filter(varDecls.getLeadingAnnotations(), ann -> !TypeUtils.isAssignableTo(RULE_FQN, ann.getType()) && !TypeUtils.isAssignableTo(CLASS_RULE_FQN, ann.getType()))); @@ -97,7 +90,6 @@ public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations v return vd; } - // Add field level annotation maybeAddImport(CONTAINER_FQN); return JavaTemplate.builder("@Container") .imports(CONTAINER_FQN) diff --git a/src/main/java/org/openrewrite/java/testing/truth/TruthThrowableAssertions.java b/src/main/java/org/openrewrite/java/testing/truth/TruthThrowableAssertions.java index 6522250cb..e8bcaa4c1 100644 --- a/src/main/java/org/openrewrite/java/testing/truth/TruthThrowableAssertions.java +++ b/src/main/java/org/openrewrite/java/testing/truth/TruthThrowableAssertions.java @@ -64,7 +64,6 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu } J.MethodInvocation assertThat = (J.MethodInvocation) hasMethod.getSelect(); - // Handle hasMessageThat().contains(text) if (CONTAINS.matches(mi) && HAS_MESSAGE_THAT.matches(hasMethod)) { maybeRemoveImport("com.google.common.truth.Truth"); maybeRemoveImport("com.google.common.truth.Truth.assertThat"); @@ -79,7 +78,6 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu mi.getArguments().get(0)); } - // Handle hasMessageThat().containsMatch(regex) if (CONTAINS_MATCH.matches(mi) && HAS_MESSAGE_THAT.matches(hasMethod)) { maybeRemoveImport("com.google.common.truth.Truth"); maybeRemoveImport("com.google.common.truth.Truth.assertThat"); @@ -94,7 +92,6 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu mi.getArguments().get(0)); } - // Handle hasMessageThat().doesNotContain(text) if (DOES_NOT_CONTAIN.matches(mi) && HAS_MESSAGE_THAT.matches(hasMethod)) { maybeRemoveImport("com.google.common.truth.Truth"); maybeRemoveImport("com.google.common.truth.Truth.assertThat"); @@ -109,7 +106,6 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu mi.getArguments().get(0)); } - // Handle hasMessageThat().startsWith(prefix) if (STARTS_WITH.matches(mi) && HAS_MESSAGE_THAT.matches(hasMethod)) { maybeRemoveImport("com.google.common.truth.Truth"); maybeRemoveImport("com.google.common.truth.Truth.assertThat"); @@ -124,7 +120,6 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu mi.getArguments().get(0)); } - // Handle hasMessageThat().endsWith(suffix) if (ENDS_WITH.matches(mi) && HAS_MESSAGE_THAT.matches(hasMethod)) { maybeRemoveImport("com.google.common.truth.Truth"); maybeRemoveImport("com.google.common.truth.Truth.assertThat"); @@ -139,7 +134,6 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu mi.getArguments().get(0)); } - // Handle hasMessageThat().isEqualTo(text) if (IS_EQUAL_TO.matches(mi) && HAS_MESSAGE_THAT.matches(hasMethod)) { maybeRemoveImport("com.google.common.truth.Truth"); maybeRemoveImport("com.google.common.truth.Truth.assertThat"); @@ -154,7 +148,6 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu mi.getArguments().get(0)); } - // Handle hasCauseThat().isInstanceOf(type) if (IS_INSTANCE_OF.matches(mi) && HAS_CAUSE_THAT.matches(hasMethod)) { maybeRemoveImport("com.google.common.truth.Truth"); maybeRemoveImport("com.google.common.truth.Truth.assertThat"); diff --git a/src/main/java/org/openrewrite/java/testing/wiremock/ReplaceSettersWithTransform.java b/src/main/java/org/openrewrite/java/testing/wiremock/ReplaceSettersWithTransform.java index ddf547d0d..302992058 100644 --- a/src/main/java/org/openrewrite/java/testing/wiremock/ReplaceSettersWithTransform.java +++ b/src/main/java/org/openrewrite/java/testing/wiremock/ReplaceSettersWithTransform.java @@ -126,7 +126,6 @@ public J.Block visitBlock(J.Block block, ExecutionContext ctx) { continue; } - // Collect the longest run of setter calls on the same receiver that can be chained List run = new ArrayList<>(); run.add(first); int next = i + 1; @@ -151,7 +150,6 @@ public J.Block visitBlock(J.Block block, ExecutionContext ctx) { return changed ? b.withStatements(rewritten) : b; } - // Returns the setter call this recipe can rewrite, or null if the statement is to be left alone private @Nullable SetterCall asConvertibleSetterCall(Statement statement) { if (!(statement instanceof J.MethodInvocation)) { return null; diff --git a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java index 43e5f6861..bfdaccb68 100644 --- a/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java +++ b/src/test/java/org/openrewrite/java/testing/jmockit/JMockitExpectationsToMockitoTest.java @@ -1608,7 +1608,7 @@ void test() { ); } - @Disabled // comment migration not supported yet + @Disabled("Comments inside an `Expectations` block are not migrated yet") @Test void whenComments() { //language=java diff --git a/src/test/java/org/openrewrite/java/testing/junit5/AddMissingNestedTest.java b/src/test/java/org/openrewrite/java/testing/junit5/AddMissingNestedTest.java index 27b2b34e6..9e927d617 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/AddMissingNestedTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/AddMissingNestedTest.java @@ -15,7 +15,6 @@ */ package org.openrewrite.java.testing.junit5; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; import org.openrewrite.InMemoryExecutionContext; @@ -619,7 +618,6 @@ public void test() { ); } - @Disabled("Should be enabled when Preconditions.not(new KotlinFileChecker<>()) is removed from the recipe") @Test void doesNotAnnotateKotlinObject() { //language=kotlin @@ -640,7 +638,6 @@ fun test() { ); } - @Disabled("Should be enabled when Preconditions.not(new KotlinFileChecker<>()) is removed from the recipe") @Test void doesNotAnnotateKotlinCompanionObject() { //language=kotlin diff --git a/src/test/java/org/openrewrite/java/testing/junit5/AssumeNotNullToAssumptionsTest.java b/src/test/java/org/openrewrite/java/testing/junit5/AssumeNotNullToAssumptionsTest.java index 954b7b8a8..20281f72a 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/AssumeNotNullToAssumptionsTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/AssumeNotNullToAssumptionsTest.java @@ -15,7 +15,6 @@ */ package org.openrewrite.java.testing.junit5; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openrewrite.InMemoryExecutionContext; import org.openrewrite.Issue; @@ -62,7 +61,6 @@ void test(Object object) { ); } - @Disabled("Refaster fails to match multiple arguments into varargs for now") @Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/886") @Test void twoArgs() { @@ -74,7 +72,7 @@ void twoArgs() { class Test { void test(Object object1, Object object2) { - Assume.assumeNotNull(new Object(), new Object()); + Assume.assumeNotNull(object1, object2); } } """, diff --git a/src/test/java/org/openrewrite/java/testing/junit5/UpdateBeforeAfterAnnotationsTest.java b/src/test/java/org/openrewrite/java/testing/junit5/UpdateBeforeAfterAnnotationsTest.java index 7d581500e..b2a852784 100644 --- a/src/test/java/org/openrewrite/java/testing/junit5/UpdateBeforeAfterAnnotationsTest.java +++ b/src/test/java/org/openrewrite/java/testing/junit5/UpdateBeforeAfterAnnotationsTest.java @@ -177,7 +177,7 @@ void afterClass() { ); } - @Disabled + @Disabled("`UpdateBeforeAfterAnnotations` keeps the `public` modifier and leaves the trailing comment on the annotation") @Issue("https://github.com/openrewrite/rewrite/issues/150") @Test void convertsToPackageVisibility() {