diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9b5fd3cd1caa..c6edc767c406 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -89,6 +89,19 @@ Eclipse settings. It is forbidden to use _wildcard imports_ (e.g., `import static org.junit.jupiter.api.Assertions.*;`) in Java code. +### 🚀 Code Transformation & Automated Rewriting +*(Advanced Refactoring, Modernization, and Bulk Code Changes)* + +#### 🔧 Automated rewriting of source code to +- **Refactor** safely (e.g., rename methods, migrate APIs) +- **Modernize** (e.g., Java 8 → Java 17 features) +- **Fix anti-patterns** (e.g., replace `Vector` with `ArrayList`) +- **Enforce conventions** (e.g., JUnit's naming rules) + +The build system incorporates [Moderne](https://moderne.io/) rewrite capabilities for automated code transformations. These modifications are environment-driven enlisted in the [junitbuild.java-library-conventions.gradle.kts](gradle/plugins/common/src/main/kotlin/junitbuild.java-library-conventions.gradle.kts) + +You can use `gradle rewriteRun` to apply these changes. + #### Documentation Text in `*.adoc` and `*.md` files should be wrapped at 90 characters whenever technically diff --git a/documentation/src/test/java/example/ClassTemplateDemo.java b/documentation/src/test/java/example/ClassTemplateDemo.java index 93f669ab5be2..67b9395619ca 100644 --- a/documentation/src/test/java/example/ClassTemplateDemo.java +++ b/documentation/src/test/java/example/ClassTemplateDemo.java @@ -52,9 +52,9 @@ void wellKnown() { } // end::user_guide[] - static + public // tag::user_guide[] - public class MyClassTemplateInvocationContextProvider + static class MyClassTemplateInvocationContextProvider // tag::custom_line_break[] implements ClassTemplateInvocationContextProvider { diff --git a/documentation/src/test/java/example/ParameterizedMigrationDemo.java b/documentation/src/test/java/example/ParameterizedMigrationDemo.java index e5425f73412e..a6308d678e9e 100644 --- a/documentation/src/test/java/example/ParameterizedMigrationDemo.java +++ b/documentation/src/test/java/example/ParameterizedMigrationDemo.java @@ -25,9 +25,9 @@ public class ParameterizedMigrationDemo { // tag::before[] @RunWith(Parameterized.class) // end::before[] - static + public // tag::before[] - public class JUnit4ParameterizedClassTests { + static class JUnit4ParameterizedClassTests { @Parameterized.Parameters public static Iterable data() { diff --git a/documentation/src/test/java/example/ParameterizedTestDemo.java b/documentation/src/test/java/example/ParameterizedTestDemo.java index 72caa35d7ba4..e789cb5e896d 100644 --- a/documentation/src/test/java/example/ParameterizedTestDemo.java +++ b/documentation/src/test/java/example/ParameterizedTestDemo.java @@ -357,9 +357,9 @@ void testWithArgumentsSource(String argument) { } // end::ArgumentsSource_example[] - static + public // tag::ArgumentsProvider_example[] - public class MyArgumentsProvider implements ArgumentsProvider { + static class MyArgumentsProvider implements ArgumentsProvider { @Override public Stream provideArguments(ParameterDeclarations parameters, @@ -375,9 +375,9 @@ void testWithArgumentsSourceWithConstructorInjection(String argument) { assertNotNull(argument); } - static + public // tag::ArgumentsProviderWithConstructorInjection_example[] - public class MyArgumentsProviderWithConstructorInjection implements ArgumentsProvider { + static class MyArgumentsProviderWithConstructorInjection implements ArgumentsProvider { private final TestInfo testInfo; @@ -427,9 +427,9 @@ void testWithImplicitFallbackArgumentConversion(Book book) { } // end::implicit_fallback_conversion_example[] - static + public // tag::implicit_fallback_conversion_example_Book[] - public class Book { + static class Book { private final String title; @@ -458,10 +458,10 @@ void testWithExplicitArgumentConversion( } // end::explicit_conversion_example[] - static + public @SuppressWarnings({ "NullableProblems", "NullAway" }) // tag::explicit_conversion_example_ToStringArgumentConverter[] - public class ToStringArgumentConverter extends SimpleArgumentConverter { + static class ToStringArgumentConverter extends SimpleArgumentConverter { @Override protected Object convert(Object source, Class targetType) { @@ -474,10 +474,10 @@ protected Object convert(Object source, Class targetType) { } // end::explicit_conversion_example_ToStringArgumentConverter[] - static + public @SuppressWarnings({ "NullableProblems", "NullAway", "ConstantValue" }) // tag::explicit_conversion_example_TypedArgumentConverter[] - public class ToLengthArgumentConverter extends TypedArgumentConverter { + static class ToLengthArgumentConverter extends TypedArgumentConverter { protected ToLengthArgumentConverter() { super(String.class, Integer.class); @@ -516,7 +516,7 @@ void testWithArgumentsAccessor(ArgumentsAccessor arguments) { arguments.get(2, Gender.class), arguments.get(3, LocalDate.class)); - if (person.getFirstName().equals("Jane")) { + if ("Jane".equals(person.getFirstName())) { assertEquals(Gender.F, person.getGender()); } else { @@ -540,9 +540,9 @@ void testWithArgumentsAggregator(@AggregateWith(PersonAggregator.class) Person p } // end::ArgumentsAggregator_example[] - static + public // tag::ArgumentsAggregator_example_PersonAggregator[] - public class PersonAggregator extends SimpleArgumentsAggregator { + static class PersonAggregator extends SimpleArgumentsAggregator { @Override protected Person aggregateArguments(ArgumentsAccessor arguments, Class targetType, AnnotatedElementContext context, int parameterIndex) { diff --git a/documentation/src/test/java/example/TestInfoDemo.java b/documentation/src/test/java/example/TestInfoDemo.java index d6b55e0bffff..5ec6589560b6 100644 --- a/documentation/src/test/java/example/TestInfoDemo.java +++ b/documentation/src/test/java/example/TestInfoDemo.java @@ -31,13 +31,13 @@ static void beforeAll(TestInfo testInfo) { TestInfoDemo(TestInfo testInfo) { String displayName = testInfo.getDisplayName(); - assertTrue(displayName.equals("TEST 1") || displayName.equals("test2()")); + assertTrue("TEST 1".equals(displayName) || "test2()".equals(displayName)); } @BeforeEach void init(TestInfo testInfo) { String displayName = testInfo.getDisplayName(); - assertTrue(displayName.equals("TEST 1") || displayName.equals("test2()")); + assertTrue("TEST 1".equals(displayName) || "test2()".equals(displayName)); } @Test diff --git a/documentation/src/test/java/example/TestTemplateDemo.java b/documentation/src/test/java/example/TestTemplateDemo.java index 1dda57c462e5..015ea64b6131 100644 --- a/documentation/src/test/java/example/TestTemplateDemo.java +++ b/documentation/src/test/java/example/TestTemplateDemo.java @@ -38,10 +38,10 @@ void testTemplate(String fruit) { } // end::user_guide[] - static + public // @formatter:off // tag::user_guide[] - public class MyTestTemplateInvocationContextProvider + static class MyTestTemplateInvocationContextProvider implements TestTemplateInvocationContextProvider { @Override diff --git a/documentation/src/test/resources/log4j2-test.xml b/documentation/src/test/resources/log4j2-test.xml index 9fb7a4a69de1..0d7f4fe5a9fc 100644 --- a/documentation/src/test/resources/log4j2-test.xml +++ b/documentation/src/test/resources/log4j2-test.xml @@ -16,4 +16,4 @@ - \ No newline at end of file + diff --git a/gradle/plugins/common/src/main/kotlin/junitbuild.java-library-conventions.gradle.kts b/gradle/plugins/common/src/main/kotlin/junitbuild.java-library-conventions.gradle.kts index a505a3c5b6e8..b40b6415efbd 100644 --- a/gradle/plugins/common/src/main/kotlin/junitbuild.java-library-conventions.gradle.kts +++ b/gradle/plugins/common/src/main/kotlin/junitbuild.java-library-conventions.gradle.kts @@ -17,13 +17,46 @@ plugins { id("org.openrewrite.rewrite") } +/** + * activeRecipe("org.openrewrite.java.RemoveUnusedImports") // there are (non); fails to analyze + * activeRecipe("org.openrewrite.java.format.AutoFormat") // could remove check, spot, and all other recipes if working + * activeRecipe("org.openrewrite.java.format.BlankLines") // IndexOutOfBoundsException: Index 0 out of bounds for length 0 + * activeRecipe("org.openrewrite.java.format.NormalizeFormat") + * activeRecipe("org.openrewrite.java.format.NormalizeLineBreaks") + * activeRecipe("org.openrewrite.java.format.RemoveTrailingWhitespace") + * activeRecipe("org.openrewrite.java.format.Spaces") + * activeRecipe("org.openrewrite.java.format.TabsAndIndents") + * activeRecipe("org.openrewrite.java.format.WrappingAndBraces") + * activeRecipe("org.openrewrite.java.migrate.UpgradeToJava17") + * activeRecipe("org.openrewrite.java.testing.assertj.Assertj") + * activeRecipe("org.openrewrite.java.testing.cleanup.AssertTrueNullToAssertNull") + * activeRecipe("org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic") + * activeRecipe("org.openrewrite.java.testing.junit5.JUnit5BestPractices") // exclude legacy + * activeRecipe("org.openrewrite.staticanalysis.CodeCleanup") + * activeRecipe("org.openrewrite.staticanalysis.CommonStaticAnalysis") + * activeRecipe("org.openrewrite.staticanalysis.FinalizeLocalVariables") + * activeRecipe("org.openrewrite.staticanalysis.RedundantFileCreation") + * activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedLocalVariables") + * activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedPrivateFields") + * activeRecipe("org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods") // there are non; fails to analyze (even tho it worked once) + * activeRecipe("org.openrewrite.staticanalysis.StringLiteralEquality") + * activeRecipe("org.openrewrite.text.EndOfLineAtEndOfFile") + * activeRecipe("org.openrewrite.java.migrate.UpgradeToJava21") + */ rewrite { - activeRecipe("org.openrewrite.java.migrate.UpgradeToJava17") + activeRecipe("org.openrewrite.staticanalysis.EqualsAvoidsNull") + activeRecipe("org.openrewrite.staticanalysis.MissingOverrideAnnotation") + activeRecipe("org.openrewrite.staticanalysis.ModifierOrder") + failOnDryRunResults = true } +/** + * rewrite("org.openrewrite.recipe:rewrite-testing-frameworks") + * rewrite("org.openrewrite.recipe:rewrite-migrate-java") + */ dependencies { rewrite(platform(dependencyFromLibs("openrewrite-recipe-bom"))) - rewrite("org.openrewrite.recipe:rewrite-migrate-java") + rewrite("org.openrewrite.recipe:rewrite-static-analysis") } val mavenizedProjects: List by rootProject.extra @@ -281,6 +314,9 @@ tasks { checkstyleTest { config = resources.text.fromFile(checkstyle.configDirectory.file("checkstyleTest.xml")) } + check { + dependsOn(rewriteDryRun) + } } pluginManager.withPlugin("java-test-fixtures") { diff --git a/gradle/plugins/common/src/main/kotlin/junitbuild.spotless-conventions.gradle.kts b/gradle/plugins/common/src/main/kotlin/junitbuild.spotless-conventions.gradle.kts index af3d6818a029..d72f321d65f9 100644 --- a/gradle/plugins/common/src/main/kotlin/junitbuild.spotless-conventions.gradle.kts +++ b/gradle/plugins/common/src/main/kotlin/junitbuild.spotless-conventions.gradle.kts @@ -13,13 +13,11 @@ spotless { targetExclude("gradle/plugins/**/build/**") leadingSpacesToTabs() trimTrailingWhitespace() - endWithNewline() } format("documentation") { target("*.adoc", "*.md", "src/**/*.adoc", "src/**/*.md") trimTrailingWhitespace() - endWithNewline() } pluginManager.withPlugin("java") { @@ -36,7 +34,6 @@ spotless { val majorMinorVersion = "([0-9]+\\.[0-9]+).*".toRegex().matchEntire(fullVersion)!!.let { it.groups[1]!!.value } eclipse(majorMinorVersion).configFile(javaFormatterConfigFile) trimTrailingWhitespace() - endWithNewline() removeUnusedImports() } @@ -46,7 +43,6 @@ spotless { }) licenseHeaderFile(license.headerFile, "^$") trimTrailingWhitespace() - endWithNewline() } } @@ -56,7 +52,6 @@ spotless { ktlint(requiredVersionFromLibs("ktlint")) licenseHeaderFile(license.headerFile) trimTrailingWhitespace() - endWithNewline() } configurations.named { it.startsWith("spotless") }.configureEach { // Workaround for CVE-2024-12798 and CVE-2024-12801 @@ -74,7 +69,6 @@ spotless { groovy { licenseHeaderFile(license.headerFile) trimTrailingWhitespace() - endWithNewline() } } } diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutInvocationFactory.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutInvocationFactory.java index 41312b59d622..db95be214f07 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutInvocationFactory.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutInvocationFactory.java @@ -54,7 +54,7 @@ private ScheduledExecutorService getThreadExecutorForSameThreadInvocation() { } @SuppressWarnings({ "deprecation", "try" }) - private static abstract class ExecutorResource implements Store.CloseableResource, AutoCloseable { + private abstract static class ExecutorResource implements Store.CloseableResource, AutoCloseable { protected final ScheduledExecutorService executor; diff --git a/junit-jupiter-engine/src/main/resources/META-INF/services/org.junit.platform.engine.TestEngine b/junit-jupiter-engine/src/main/resources/META-INF/services/org.junit.platform.engine.TestEngine index 581900d54294..f19e8767902b 100644 --- a/junit-jupiter-engine/src/main/resources/META-INF/services/org.junit.platform.engine.TestEngine +++ b/junit-jupiter-engine/src/main/resources/META-INF/services/org.junit.platform.engine.TestEngine @@ -1 +1 @@ -org.junit.jupiter.engine.JupiterTestEngine \ No newline at end of file +org.junit.jupiter.engine.JupiterTestEngine diff --git a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationNameFormatter.java b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationNameFormatter.java index 4df551843e4d..970d204cbc2f 100644 --- a/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationNameFormatter.java +++ b/junit-jupiter-params/src/main/java/org/junit/jupiter/params/ParameterizedInvocationNameFormatter.java @@ -57,7 +57,7 @@ static ParameterizedInvocationNameFormatter create(ExtensionContext extensionCon ParameterizedDeclarationContext declarationContext) { String name = declarationContext.getDisplayNamePattern(); - String pattern = name.equals(DEFAULT_DISPLAY_NAME) + String pattern = DEFAULT_DISPLAY_NAME.equals(name) ? extensionContext.getConfigurationParameter(DISPLAY_NAME_PATTERN_KEY) // .orElse(DEFAULT_DISPLAY_NAME_PATTERN) : name; diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/AnnotationUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/AnnotationUtils.java index 0e7d7b7e2441..c2763722655a 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/AnnotationUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/AnnotationUtils.java @@ -381,7 +381,7 @@ private static boolean isRepeatableAnnotationContainer(Class { // @formatter:off Repeatable repeatable = Arrays.stream(candidate.getMethods()) - .filter(attribute -> attribute.getName().equals("value") && attribute.getReturnType().isArray()) + .filter(attribute -> "value".equals(attribute.getName()) && attribute.getReturnType().isArray()) .findFirst() .map(attribute -> attribute.getReturnType().getComponentType().getAnnotation(Repeatable.class)) .orElse(null); diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java index 40208636bd4c..ab2e774b567a 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ModuleUtils.java @@ -223,7 +223,7 @@ List> scan(ModuleReference reference) { // @formatter:off return names.filter(name -> name.endsWith(".class")) .map(this::className) - .filter(name -> !name.equals("module-info")) + .filter(name -> !"module-info".equals(name)) .filter(classFilter::match) .> map(this::loadClassUnchecked) .filter(classFilter::match) diff --git a/junit-vintage-engine/src/main/resources/META-INF/services/org.junit.platform.engine.TestEngine b/junit-vintage-engine/src/main/resources/META-INF/services/org.junit.platform.engine.TestEngine index 97ee0b959ac4..79b0bd6d4d59 100644 --- a/junit-vintage-engine/src/main/resources/META-INF/services/org.junit.platform.engine.TestEngine +++ b/junit-vintage-engine/src/main/resources/META-INF/services/org.junit.platform.engine.TestEngine @@ -1 +1 @@ -org.junit.vintage.engine.VintageTestEngine \ No newline at end of file +org.junit.vintage.engine.VintageTestEngine diff --git a/junit-vintage-engine/src/test/java/org/junit/vintage/engine/discovery/IsPotentialJUnit4TestClassTests.java b/junit-vintage-engine/src/test/java/org/junit/vintage/engine/discovery/IsPotentialJUnit4TestClassTests.java index 85486d998c89..b97eaa33b5ca 100644 --- a/junit-vintage-engine/src/test/java/org/junit/vintage/engine/discovery/IsPotentialJUnit4TestClassTests.java +++ b/junit-vintage-engine/src/test/java/org/junit/vintage/engine/discovery/IsPotentialJUnit4TestClassTests.java @@ -40,7 +40,7 @@ void abstractClass() { assertFalse(isPotentialJUnit4TestClass.test(Baz.class)); } - public static abstract class Baz { + public abstract static class Baz { } @Test diff --git a/junit-vintage-engine/src/test/resources/log4j2-test.xml b/junit-vintage-engine/src/test/resources/log4j2-test.xml index 063e415913fd..c0f95992bbdf 100644 --- a/junit-vintage-engine/src/test/resources/log4j2-test.xml +++ b/junit-vintage-engine/src/test/resources/log4j2-test.xml @@ -13,4 +13,4 @@ - \ No newline at end of file + diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/api/DisplayNameGenerationTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/api/DisplayNameGenerationTests.java index bf356db5d3ca..22c5e901955e 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/api/DisplayNameGenerationTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/api/DisplayNameGenerationTests.java @@ -333,7 +333,7 @@ public String generateDisplayNameForMethod(List> enclosingInstanceTypes } @DisplayNameGeneration(NoNameGenerator.class) - static abstract class AbstractTestCase { + abstract static class AbstractTestCase { @Test void test() { } diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/engine/NestedTestClassesTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/engine/NestedTestClassesTests.java index 70a844cd2639..4331efff7fbe 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/engine/NestedTestClassesTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/engine/NestedTestClassesTests.java @@ -417,7 +417,7 @@ void notExecutedByImplementingClass() { } - static abstract class AbstractSuperClass implements InterfaceWithNestedClass { + abstract static class AbstractSuperClass implements InterfaceWithNestedClass { @Nested class NestedInAbstractClass { diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/engine/SealedClassTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/engine/SealedClassTests.java index 899cf5333280..5842685124c0 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/engine/SealedClassTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/engine/SealedClassTests.java @@ -23,7 +23,7 @@ void sealedTestClassesAreTestClasses() { .assertStatistics(stats -> stats.finished(2).succeeded(1).failed(1)); } - sealed abstract static class AbstractTestCase permits TestCase { + abstract static sealed class AbstractTestCase permits TestCase { @Test void succeedingTest() { diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/engine/TestClassInheritanceTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/engine/TestClassInheritanceTests.java index 7db63a5e3021..b39e1544b6e2 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/engine/TestClassInheritanceTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/engine/TestClassInheritanceTests.java @@ -136,7 +136,7 @@ void beforeAndAfterMethodsInTestClassHierarchy() { // ------------------------------------------------------------------- - private static abstract class AbstractTestCase { + private abstract static class AbstractTestCase { static int countSuperBeforeInvoked = 0; static int countSuperAfterInvoked = 0; diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/engine/descriptor/ExtensionContextTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/engine/descriptor/ExtensionContextTests.java index 2599244c739c..055f392be22c 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/engine/descriptor/ExtensionContextTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/engine/descriptor/ExtensionContextTests.java @@ -529,7 +529,7 @@ private TestMethodTestDescriptor nestedMethodDescriptor() { } } - static abstract class BaseNestedTestCase { + abstract static class BaseNestedTestCase { @Test void nestedMethod() { } diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/engine/descriptor/JupiterTestDescriptorTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/engine/descriptor/JupiterTestDescriptorTests.java index 053d03498d22..bc18c15aad66 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/engine/descriptor/JupiterTestDescriptorTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/engine/descriptor/JupiterTestDescriptorTests.java @@ -289,7 +289,7 @@ void enclosingClassesAreDerivedFromParent() { } @Tag("inherited-class-level-tag") - private static abstract class AbstractTestCase { + private abstract static class AbstractTestCase { } @Tag("classTag1") diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/engine/discovery/DiscoveryTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/engine/discovery/DiscoveryTests.java index 02fa1eb5b01d..df43af4414b7 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/engine/discovery/DiscoveryTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/engine/discovery/DiscoveryTests.java @@ -412,7 +412,7 @@ void reportsWarningsForBlankDisplayNames() throws Exception { // ------------------------------------------------------------------- @SuppressWarnings("unused") - static abstract class AbstractTestCase { + abstract static class AbstractTestCase { @Test void test() { @@ -465,7 +465,7 @@ void testTemplate() { } - static abstract class AbstractSuperClass { + abstract static class AbstractSuperClass { @Nested class NestedInAbstractClass { @Test diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/engine/discovery/predicates/IsTestMethodTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/engine/discovery/predicates/IsTestMethodTests.java index 73373a4999d2..24c074a4a9f2 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/engine/discovery/predicates/IsTestMethodTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/engine/discovery/predicates/IsTestMethodTests.java @@ -154,7 +154,7 @@ private Method abstractMethod(String name) { } @SuppressWarnings({ "JUnitMalformedDeclaration", "unused" }) - private static abstract class AbstractClassWithAbstractTestMethod { + private abstract static class AbstractClassWithAbstractTestMethod { @Test abstract void bogusAbstractTestMethod(); diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/BeforeAndAfterEachTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/BeforeAndAfterEachTests.java index a5e6b501e1ea..1517bc464ec5 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/BeforeAndAfterEachTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/BeforeAndAfterEachTests.java @@ -231,7 +231,7 @@ void beforeEachMethodThrowsAnException() { ); // @formatter:on - List expected = beforeEachMethodCallSequence.getFirst().equals("beforeEachMethod1") ? list1 : list2; + List expected = "beforeEachMethod1".equals(beforeEachMethodCallSequence.getFirst()) ? list1 : list2; assertEquals(expected, callSequence, "wrong call sequence"); diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/OrderedClassTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/OrderedClassTests.java index dd76fa677ce9..8516bece3fcd 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/OrderedClassTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/OrderedClassTests.java @@ -245,7 +245,7 @@ private static EngineTestKit.Builder testKit(@Nullable Class testClass) { // ------------------------------------------------------------------------- - private static abstract class AbstractTestCase { + private abstract static class AbstractTestCase { @Test public void successfulTest() { @@ -322,7 +322,7 @@ static class ProblematicConstructorTestCase extends AbstractTestCase { } @TestMethodOrder(OrderAnnotation.class) - private static abstract class AbstractDisabledMethodsTestCase { + private abstract static class AbstractDisabledMethodsTestCase { @Disabled @Test diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/migrationsupport/conditions/IgnoreAnnotationIntegrationTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/migrationsupport/conditions/IgnoreAnnotationIntegrationTests.java index 20d523c6dc05..de6a0429c900 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/migrationsupport/conditions/IgnoreAnnotationIntegrationTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/migrationsupport/conditions/IgnoreAnnotationIntegrationTests.java @@ -50,7 +50,7 @@ class ImplicitIgnoreConditionRegistration extends BaseNestedTestCase { } @TestInstance(PER_CLASS) - private static abstract class BaseNestedTestCase { + private abstract static class BaseNestedTestCase { private static List tests = new ArrayList<>(); diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedClassIntegrationTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedClassIntegrationTests.java index 1eac5e4d9d01..0162576740be 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedClassIntegrationTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedClassIntegrationTests.java @@ -1178,7 +1178,7 @@ static Stream parameters() { @Test void test() { - assertTrue(value.equals("foo") || value.equals("bar")); + assertTrue("foo".equals(value) || "bar".equals(value)); } } @@ -1195,7 +1195,7 @@ static Stream parameters() { @Test void test() { - assertTrue(value.equals("foo") || value.equals("bar")); + assertTrue("foo".equals(value) || "bar".equals(value)); } } @@ -1217,7 +1217,7 @@ record FieldSourceConstructorInjectionTestCase(String value) { @Test void test() { - assertTrue(value.equals("foo") || value.equals("bar")); + assertTrue("foo".equals(value) || "bar".equals(value)); } } @@ -1232,7 +1232,7 @@ static class FieldSourceFieldInjectionTestCase { @Test void test() { - assertTrue(value.equals("foo") || value.equals("bar")); + assertTrue("foo".equals(value) || "bar".equals(value)); } } @@ -1251,7 +1251,7 @@ void test() { record ArgumentsSourceConstructorInjectionTestCase(String value) { @Test void test() { - assertTrue(value.equals("foo") || value.equals("bar")); + assertTrue("foo".equals(value) || "bar".equals(value)); } } @@ -1264,7 +1264,7 @@ static class ArgumentsSourceFieldInjectionTestCase { @Test void test() { - assertTrue(value.equals("foo") || value.equals("bar")); + assertTrue("foo".equals(value) || "bar".equals(value)); } } @@ -1851,7 +1851,7 @@ void test() { } } - static abstract class AbstractBaseLifecycleTestCase { + abstract static class AbstractBaseLifecycleTestCase { @BeforeParameterizedClassInvocation static void zzz_before(TestReporter reporter) { @@ -1884,7 +1884,7 @@ void test(TestReporter reporter) { } } - static abstract class AbstractBaseLifecycleWithErrorsTestCase { + abstract static class AbstractBaseLifecycleWithErrorsTestCase { @BeforeParameterizedClassInvocation static void zzz_before(TestReporter reporter) { diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedTestExtensionTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedTestExtensionTests.java index 9f589354ae5c..8fb9e3019e45 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedTestExtensionTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/params/ParameterizedTestExtensionTests.java @@ -111,7 +111,7 @@ void emptyDisplayNameIsIllegal() { void defaultDisplayNameWithEmptyStringInConfigurationIsIllegal() { AtomicInteger invocations = new AtomicInteger(); Function> configurationSupplier = key -> { - if (key.equals(ParameterizedInvocationNameFormatter.DISPLAY_NAME_PATTERN_KEY)) { + if (ParameterizedInvocationNameFormatter.DISPLAY_NAME_PATTERN_KEY.equals(key)) { invocations.incrementAndGet(); return Optional.of(""); } diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/params/aggregator/AggregatorIntegrationTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/params/aggregator/AggregatorIntegrationTests.java index 1d57fbf27f51..d786fbffab55 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/params/aggregator/AggregatorIntegrationTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/params/aggregator/AggregatorIntegrationTests.java @@ -203,13 +203,13 @@ void argumentsAccessorInvocationIndex(ArgumentsAccessor arguments) { } private void testPersonAggregator(Person person) { - if (person.firstName.equals("Jane")) { + if ("Jane".equals(person.firstName)) { assertEquals("Jane Doe", person.getFullName()); assertEquals(1980, person.dateOfBirth.getYear()); assertEquals(Gender.F, person.gender); } - if (person.firstName.equals("Jack")) { + if ("Jack".equals(person.firstName)) { assertEquals("Jack Smith", person.getFullName()); assertEquals(2000, person.dateOfBirth.getYear()); assertEquals(Gender.M, person.gender); diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/params/support/AnnotationConsumerInitializerTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/params/support/AnnotationConsumerInitializerTests.java index 0cbcceb950b5..d67a3f2ef620 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/params/support/AnnotationConsumerInitializerTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/params/support/AnnotationConsumerInitializerTests.java @@ -124,7 +124,7 @@ void shouldInitializeForEachAnnotations(AbstractAnnotationBasedArgumentsProvider Named.of("deprecated", new DeprecatedAnnotationBasedArgumentsProvider()) // ); - private static abstract class AbstractAnnotationBasedArgumentsProvider + private abstract static class AbstractAnnotationBasedArgumentsProvider extends AnnotationBasedArgumentsProvider { List annotations = new ArrayList<>(); diff --git a/platform-tests/src/test/java/org/junit/platform/commons/support/scanning/DefaultClasspathScannerTests.java b/platform-tests/src/test/java/org/junit/platform/commons/support/scanning/DefaultClasspathScannerTests.java index d79540ddf728..96ded621c581 100644 --- a/platform-tests/src/test/java/org/junit/platform/commons/support/scanning/DefaultClasspathScannerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/commons/support/scanning/DefaultClasspathScannerTests.java @@ -136,7 +136,7 @@ private void assertClassesScannedWhenExceptionIsThrown(Predicate> filte @Test void scanForResourcesInClasspathRootWhenGenericRuntimeExceptionOccurs(LogRecordListener listener) throws Exception { Predicate runtimeExceptionSimulationFilter = resource -> { - if (resource.getName().equals("org/junit/platform/commons/other-example.resource")) { + if ("org/junit/platform/commons/other-example.resource".equals(resource.getName())) { throw new RuntimeException("a generic exception"); } return true; diff --git a/platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java b/platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java index 22022c758fcc..c2916d17a2fe 100644 --- a/platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java +++ b/platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java @@ -98,7 +98,7 @@ */ class ReflectionUtilsTests { - private static final Predicate isFooMethod = method -> method.getName().equals("foo"); + private static final Predicate isFooMethod = method -> "foo".equals(method.getName()); private static final Predicate methodContains1 = method -> method.getName().contains("1"); private static final Predicate methodContains2 = method -> method.getName().contains("2"); private static final Predicate methodContains4 = method -> method.getName().contains("4"); @@ -1266,7 +1266,7 @@ void isMethodPresentPreconditions() { @Test void isMethodPresent() { - Predicate isMethod1 = method -> (method.getName().equals("method1") + Predicate isMethod1 = method -> ("method1".equals(method.getName()) && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == String.class); assertThat(ReflectionUtils.isMethodPresent(MethodShadowingChild.class, isMethod1)).isTrue(); @@ -1502,7 +1502,7 @@ private static void assertOneFooMethodIn(Class clazz) { */ @Test void findMethodsFindsDistinctMethodsDeclaredInMultipleInterfaces() { - Predicate isStringsMethod = method -> method.getName().equals("strings"); + Predicate isStringsMethod = method -> "strings".equals(method.getName()); assertThat(findMethods(DoubleInheritedInterfaceMethodTestCase.class, isStringsMethod)).hasSize(1); } @@ -1549,10 +1549,10 @@ void findMethodsUsingHierarchyUpMode() throws Exception { .containsExactly(ChildClass.class.getMethod("otherMethod3"), ParentClass.class.getMethod("otherMethod2"), GrandparentClass.class.getMethod("otherMethod1")); - assertThat(findMethods(ChildClass.class, method -> method.getName().equals("method2"), BOTTOM_UP))// + assertThat(findMethods(ChildClass.class, method -> "method2".equals(method.getName()), BOTTOM_UP))// .containsExactly(ParentClass.class.getMethod("method2")); - assertThat(findMethods(ChildClass.class, method -> method.getName().equals("wrongName"), BOTTOM_UP))// + assertThat(findMethods(ChildClass.class, method -> "wrongName".equals(method.getName()), BOTTOM_UP))// .isEmpty(); assertThat(findMethods(ParentClass.class, method -> method.getName().contains("method"), BOTTOM_UP))// @@ -1571,10 +1571,10 @@ void findMethodsUsingHierarchyDownMode() throws Exception { .containsExactly(GrandparentClass.class.getMethod("otherMethod1"), ParentClass.class.getMethod("otherMethod2"), ChildClass.class.getMethod("otherMethod3")); - assertThat(findMethods(ChildClass.class, method -> method.getName().equals("method2"), TOP_DOWN))// + assertThat(findMethods(ChildClass.class, method -> "method2".equals(method.getName()), TOP_DOWN))// .containsExactly(ParentClass.class.getMethod("method2")); - assertThat(findMethods(ChildClass.class, method -> method.getName().equals("wrongName"), TOP_DOWN))// + assertThat(findMethods(ChildClass.class, method -> "wrongName".equals(method.getName()), TOP_DOWN))// .isEmpty(); assertThat(findMethods(ParentClass.class, method -> method.getName().contains("method"), TOP_DOWN))// diff --git a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/ParallelExecutionIntegrationTests.java b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/ParallelExecutionIntegrationTests.java index a311559c9cea..212cc49147be 100644 --- a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/ParallelExecutionIntegrationTests.java +++ b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/ParallelExecutionIntegrationTests.java @@ -886,7 +886,7 @@ void repeatedTest() throws Exception { } @ExtendWith(ThreadReporter.class) - static abstract class BarrierTestCase { + abstract static class BarrierTestCase { @Test void test1() throws Exception { diff --git a/platform-tests/src/test/java/org/junit/platform/launcher/core/DefaultLauncherTests.java b/platform-tests/src/test/java/org/junit/platform/launcher/core/DefaultLauncherTests.java index 33bb887bd4e2..da83caa648a2 100644 --- a/platform-tests/src/test/java/org/junit/platform/launcher/core/DefaultLauncherTests.java +++ b/platform-tests/src/test/java/org/junit/platform/launcher/core/DefaultLauncherTests.java @@ -1019,7 +1019,7 @@ public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId inOrder.verify(executionListener).executionStarted( argThat(d -> d.getUniqueIdObject().equals(UniqueId.forEngine("engine-id")))); inOrder.verify(executionListener).executionSkipped( - argThat(d -> d.getUniqueIdObject().getLastSegment().getType().equals("container")), + argThat(d -> "container".equals(d.getUniqueIdObject().getLastSegment().getType())), eq("Execution cancelled")); inOrder.verify(executionListener).executionFinished( argThat(d -> d.getUniqueIdObject().equals(UniqueId.forEngine("engine-id"))), diff --git a/platform-tests/src/test/java/org/junit/platform/suite/engine/SuiteEngineTests.java b/platform-tests/src/test/java/org/junit/platform/suite/engine/SuiteEngineTests.java index 12cb46e6d928..851ff5da88ff 100644 --- a/platform-tests/src/test/java/org/junit/platform/suite/engine/SuiteEngineTests.java +++ b/platform-tests/src/test/java/org/junit/platform/suite/engine/SuiteEngineTests.java @@ -726,7 +726,7 @@ static void afterSuite() { @Suite @SelectClasses(SingleTestTestCase.class) - abstract private static class AbstractPrivateSuite { + private abstract static class AbstractPrivateSuite { } @Suite diff --git a/platform-tests/src/test/resources/do_not_delete_me.txt b/platform-tests/src/test/resources/do_not_delete_me.txt index 91c5d9e7c55b..0db3b13a83b1 100644 --- a/platform-tests/src/test/resources/do_not_delete_me.txt +++ b/platform-tests/src/test/resources/do_not_delete_me.txt @@ -1,3 +1,3 @@ I am used by tests, so... -Do NOT delete me! \ No newline at end of file +Do NOT delete me! diff --git a/platform-tests/src/test/resources/testservices/META-INF/services/org.junit.platform.launcher.TestExecutionListener b/platform-tests/src/test/resources/testservices/META-INF/services/org.junit.platform.launcher.TestExecutionListener index 4bb9bbe72066..402a62451836 100644 --- a/platform-tests/src/test/resources/testservices/META-INF/services/org.junit.platform.launcher.TestExecutionListener +++ b/platform-tests/src/test/resources/testservices/META-INF/services/org.junit.platform.launcher.TestExecutionListener @@ -1,3 +1,3 @@ org.junit.platform.launcher.listeners.NoopTestExecutionListener org.junit.platform.launcher.listeners.UnusedTestExecutionListener -org.junit.platform.launcher.listeners.AnotherUnusedTestExecutionListener \ No newline at end of file +org.junit.platform.launcher.listeners.AnotherUnusedTestExecutionListener diff --git a/platform-tooling-support-tests/src/main/java/platform/tooling/support/Helper.java b/platform-tooling-support-tests/src/main/java/platform/tooling/support/Helper.java index 0df95dd15ca8..4c58f53048b6 100644 --- a/platform-tooling-support-tests/src/main/java/platform/tooling/support/Helper.java +++ b/platform-tooling-support-tests/src/main/java/platform/tooling/support/Helper.java @@ -51,8 +51,8 @@ public static List loadModuleDirectoryNames() { .filter(Matcher::matches) // .map(matcher -> matcher.group(1)) // .filter(name -> name.startsWith("junit-")) // - .filter(name -> !name.equals("junit-bom")) // - .filter(name -> !name.equals("junit-platform-console-standalone")).toList(); + .filter(name -> !"junit-bom".equals(name)) // + .filter(name -> !"junit-platform-console-standalone".equals(name)).toList(); } catch (Exception e) { throw new AssertionError("loading module directory names failed: " + SETTINGS_GRADLE); diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ManifestTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ManifestTests.java index f71b3f14eb12..6b7384ab4770 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ManifestTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ManifestTests.java @@ -56,7 +56,7 @@ void manifestEntriesAdhereToConventions(String module) throws Exception { assertValue(attributes, "Bundle-SymbolicName", module); assertValue(attributes, "Bundle-Version", MavenVersion.parseMavenString(version).getOSGiVersion().toString()); - if (module.equals("junit-platform-console")) { + if ("junit-platform-console".equals(module)) { assertValue(attributes, "Main-Class", "org.junit.platform.console.ConsoleLauncher"); } var domain = Domain.domain(manifest); diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ToolProviderTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ToolProviderTests.java index d018c629fc7a..75dc1b330b8c 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ToolProviderTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ToolProviderTests.java @@ -90,7 +90,7 @@ static void triggerReleaseOfFileHandlesOnWindows() throws Exception { void findAndRunJUnitOnTheClassPath() { try (var loader = new URLClassLoader("junit", urls(lib), ClassLoader.getPlatformClassLoader())) { var sl = ServiceLoader.load(ToolProvider.class, loader); - var junit = StreamSupport.stream(sl.spliterator(), false).filter(p -> p.name().equals("junit")).findFirst(); + var junit = StreamSupport.stream(sl.spliterator(), false).filter(p -> "junit".equals(p.name())).findFirst(); assertTrue(junit.isPresent(), "Tool 'junit' not found in: " + lib); assertJUnitPrintsHelpMessage(junit.get()); @@ -116,7 +116,7 @@ void findAndRunJUnitOnTheModulePath() { var layer = bootLayer.defineModulesWithOneLoader(configuration, ClassLoader.getPlatformClassLoader()); var sl = ServiceLoader.load(layer, ToolProvider.class); - var junit = StreamSupport.stream(sl.spliterator(), false).filter(p -> p.name().equals("junit")).findFirst(); + var junit = StreamSupport.stream(sl.spliterator(), false).filter(p -> "junit".equals(p.name())).findFirst(); assertTrue(junit.isPresent(), "Tool 'junit' not found in modules: " + modules); assertJUnitPrintsHelpMessage(junit.get());