From 97beb6b78638d7e12d59c72868891ff24f402a0f Mon Sep 17 00:00:00 2001 From: Vincent Potucek Date: Mon, 15 Dec 2025 10:18:46 +0100 Subject: [PATCH] Add `CleanupAssertions` #5193 #5002 - https://docs.openrewrite.org/recipes/java/testing/junit/jupiterbestpractices Signed-off-by: Vincent Potucek --- .github/workflows/sanity-check.yml | 48 +++++++ gradle/config/rewrite.yml | 9 ++ gradle/libs.versions.toml | 1 + gradle/plugins/common/build.gradle.kts | 5 +- ...nitbuild.checkstyle-conventions.gradle.kts | 4 - ...tbuild.java-library-conventions.gradle.kts | 1 + .../junitbuild.osgi-conventions.gradle.kts | 15 ++- .../junitbuild.rewrite-conventions.gradle.kts | 22 +++ .../engine/TestClassInheritanceTests.java | 26 ++-- ...stInstanceLifecycleConfigurationTests.java | 2 +- .../extension/BeforeAndAfterAllTests.java | 2 +- .../extension/BeforeAndAfterEachTests.java | 126 +++++++++--------- ...oreAndAfterTestExecutionCallbackTests.java | 104 +++++++-------- ...stProcessorAndPreDestroyCallbackTests.java | 2 +- .../rules/AbstractTestRuleAdapterTests.java | 2 +- .../junit/platform/engine/TestTagTests.java | 2 +- 16 files changed, 226 insertions(+), 145 deletions(-) create mode 100644 .github/workflows/sanity-check.yml create mode 100644 gradle/config/rewrite.yml create mode 100644 gradle/plugins/common/src/main/kotlin/junitbuild.rewrite-conventions.gradle.kts diff --git a/.github/workflows/sanity-check.yml b/.github/workflows/sanity-check.yml new file mode 100644 index 000000000000..490f6c5188e5 --- /dev/null +++ b/.github/workflows/sanity-check.yml @@ -0,0 +1,48 @@ +name: Sanity Check 🕊 +on: + push: + branches: + - main + - 'releases/**' + paths: + - '.github/**' + pull_request: + paths: + - '.github/**' +permissions: {} +jobs: + validate: + name: Validate 📊 + runs-on: ubuntu-latest + permissions: + security-events: write + steps: + - name: Checkout Repository 📥 + uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + with: + persist-credentials: false + - name: Checkstyle ☑️ + uses: ./.github/actions/run-gradle + with: + encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }} + arguments: checkstyleMain + - name: Spotless ✨ + uses: ./.github/actions/run-gradle + with: + encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }} + arguments: spotlessCheck + - name: ArchUnit 🏛️ + uses: ./.github/actions/run-gradle + with: + encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }} + arguments: archUnit + - name: OSGi 🧩 + uses: ./.github/actions/run-gradle + with: + encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }} + arguments: verifyOSGiTask + - name: Rewrite ⚙️ + uses: ./.github/actions/run-gradle + with: + encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }} + arguments: rewriteDryRun # -Dorg.gradle.jvmargs=-Xmx2G diff --git a/gradle/config/rewrite.yml b/gradle/config/rewrite.yml new file mode 100644 index 000000000000..c2f518dcd1df --- /dev/null +++ b/gradle/config/rewrite.yml @@ -0,0 +1,9 @@ +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.junit.openrewrite.SanityCheck +displayName: Apply all common best practices +description: Comprehensive code quality recipe combining modernization, security, and best practices. +recipeList: + - org.openrewrite.java.testing.junit5.CleanupAssertions +# - org.openrewrite.java.testing.junit.JupiterBestPractices +--- diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6f06005720c2..84a5ce04e7a6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -94,6 +94,7 @@ commonCustomUserData = { id = "com.gradle.common-custom-user-data-gradle-plugin" develocity = { id = "com.gradle.develocity", version = "4.2.2" } download = { id = "de.undercouch.download", version = "5.6.0" } errorProne = { id = "net.ltgt.errorprone", version = "4.3.0" } +rewrite = { id = "org.openrewrite.rewrite", version = "7.22.0" } foojayResolver = { id = "org.gradle.toolchains.foojay-resolver", version = "1.0.0" } jmh = { id = "me.champeau.jmh", version = "0.7.3" } jreleaser = { id = "org.jreleaser", version = "1.21.0" } diff --git a/gradle/plugins/common/build.gradle.kts b/gradle/plugins/common/build.gradle.kts index 3e05ad907f86..a8dce6e70ec7 100644 --- a/gradle/plugins/common/build.gradle.kts +++ b/gradle/plugins/common/build.gradle.kts @@ -7,16 +7,17 @@ plugins { dependencies { implementation("junitbuild.base:dsl-extensions") - implementation(projects.buildParameters) implementation(projects.backwardCompatibility) - implementation(libs.plugins.kotlin.markerCoordinates) + implementation(projects.buildParameters) implementation(libs.plugins.bnd.markerCoordinates) implementation(libs.plugins.commonCustomUserData.markerCoordinates) implementation(libs.plugins.develocity.markerCoordinates) implementation(libs.plugins.errorProne.markerCoordinates) implementation(libs.plugins.foojayResolver.markerCoordinates) implementation(libs.plugins.jmh.markerCoordinates) + implementation(libs.plugins.kotlin.markerCoordinates) implementation(libs.plugins.nullaway.markerCoordinates) + implementation(libs.plugins.rewrite.markerCoordinates) implementation(libs.plugins.shadow.markerCoordinates) implementation(libs.plugins.spotless.markerCoordinates) } diff --git a/gradle/plugins/common/src/main/kotlin/junitbuild.checkstyle-conventions.gradle.kts b/gradle/plugins/common/src/main/kotlin/junitbuild.checkstyle-conventions.gradle.kts index eae33aa9151a..62b9636e7caa 100644 --- a/gradle/plugins/common/src/main/kotlin/junitbuild.checkstyle-conventions.gradle.kts +++ b/gradle/plugins/common/src/main/kotlin/junitbuild.checkstyle-conventions.gradle.kts @@ -20,7 +20,3 @@ checkstyle { toolVersion = requiredVersionFromLibs("checkstyle") configDirectory = rootProject.layout.projectDirectory.dir("gradle/config/checkstyle") } - -tasks.check { - dependsOn(tasks.withType()) -} 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 260495b5d978..d28343a7642c 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 @@ -9,6 +9,7 @@ plugins { id("junitbuild.eclipse-conventions") id("junitbuild.jacoco-java-conventions") id("junitbuild.java-errorprone-conventions") + id("junitbuild.rewrite-conventions") } val mavenizedProjects: List by rootProject.extra diff --git a/gradle/plugins/common/src/main/kotlin/junitbuild.osgi-conventions.gradle.kts b/gradle/plugins/common/src/main/kotlin/junitbuild.osgi-conventions.gradle.kts index 6040ad6663af..7a4ec4cb7a6b 100644 --- a/gradle/plugins/common/src/main/kotlin/junitbuild.osgi-conventions.gradle.kts +++ b/gradle/plugins/common/src/main/kotlin/junitbuild.osgi-conventions.gradle.kts @@ -99,14 +99,21 @@ val osgiVerificationClasspath = configurations.resolvable("osgiVerificationClass extendsFrom(osgiVerification.get()) } +// Make the task available for calling from outside +tasks.register("verifyOSGiTask") { + description = "Verifies OSGi metadata in the built jar" + group = "verification" + dependsOn(verify) +} + // Bnd's Resolve task is what verifies that a jar can be used in OSGi and // that its metadata is valid. If the metadata is invalid this task will // fail. -val verifyOSGi by tasks.registering(Resolve::class) { +val verify by tasks.registering(Resolve::class) { bndrun = osgiProperties.flatMap { it.destinationFile } outputBndrun = layout.buildDirectory.file("resolvedOSGiProperties.bndrun") isReportOptional = false - // By default bnd will use jars found in: + // By default, bnd will use jars found in: // 1. project.sourceSets.main.runtimeClasspath // 2. project.configurations.archives.artifacts.files // to validate the metadata. @@ -116,7 +123,3 @@ val verifyOSGi by tasks.registering(Resolve::class) { bundles(osgiVerificationClasspath) properties.empty() } - -tasks.check { - dependsOn(verifyOSGi) -} diff --git a/gradle/plugins/common/src/main/kotlin/junitbuild.rewrite-conventions.gradle.kts b/gradle/plugins/common/src/main/kotlin/junitbuild.rewrite-conventions.gradle.kts new file mode 100644 index 000000000000..b2e24e6d3d78 --- /dev/null +++ b/gradle/plugins/common/src/main/kotlin/junitbuild.rewrite-conventions.gradle.kts @@ -0,0 +1,22 @@ +plugins { + id("org.openrewrite.rewrite") +} + +dependencies { + rewrite("org.openrewrite.recipe:rewrite-testing-frameworks:3.23.0") +} + +rewrite { + activeRecipe("org.junit.openrewrite.SanityCheck") + configFile = project.getRootProject().file("gradle/config/rewrite.yml") + exclusion( + // "**AssertionsTests.java", // https://github.com/openrewrite/rewrite-static-analysis/issues/799 + // legacy + "**TestCase.java", + "**TestCases.java", + "**documentation/src/test/java/example**", + "**testFixtures/java/org/junit/vintage/engine/samples**", + ) + setExportDatatables(true) + setFailOnDryRunResults(true) +} 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..ff0669a266d6 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 @@ -116,21 +116,21 @@ void beforeAndAfterMethodsInTestClassHierarchy() { // @formatter:on // @formatter:off - assertEquals(asList( - "beforeAll1", + assertEquals(callSequence, asList( + "beforeAll1", "beforeAll2", - "beforeAll3", - "beforeEach1", - "beforeEach2", - "beforeEach3", - "test3", - "afterEach3", - "afterEach2", - "afterEach1", - "afterAll3", + "beforeAll3", + "beforeEach1", + "beforeEach2", + "beforeEach3", + "test3", + "afterEach3", + "afterEach2", + "afterEach1", + "afterAll3", "afterAll2", - "afterAll1" - ), callSequence, "wrong call sequence"); + "afterAll1" + ), "wrong call sequence"); // @formatter:on } diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/engine/TestInstanceLifecycleConfigurationTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/engine/TestInstanceLifecycleConfigurationTests.java index 1269a9735cbd..3bf6c0b07103 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/engine/TestInstanceLifecycleConfigurationTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/engine/TestInstanceLifecycleConfigurationTests.java @@ -138,7 +138,7 @@ private void performAssertions(Class testClass, Map configPar executionResults.testEvents().assertStatistics(// stats -> stats.started(numTests).finished(numTests)); - assertEquals(Arrays.asList(methods), methodsInvoked); + assertEquals(methodsInvoked, Arrays.asList(methods)); } // ------------------------------------------------------------------------- diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/BeforeAndAfterAllTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/BeforeAndAfterAllTests.java index 04ae42dd6afd..71b894c7f233 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/BeforeAndAfterAllTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/BeforeAndAfterAllTests.java @@ -182,7 +182,7 @@ private void assertBeforeAllAndAfterAllCallbacks(Class testClass, int testsSt executeTestsForClass(testClass).testEvents()// .assertStatistics(stats -> stats.started(testsStarted).succeeded(testsSuccessful)); - assertEquals(asList(expectedCalls), callSequence, () -> "wrong call sequence for " + testClass.getName()); + assertEquals(callSequence, asList(expectedCalls), () -> "wrong call sequence for " + testClass.getName()); } // ------------------------------------------------------------------------- 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..623a0a18c3c3 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 @@ -64,31 +64,31 @@ void beforeEachAndAfterEachCallbacks() { assertEquals(0, testEvents.failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( + assertEquals(callSequence, asList( - // OuterTestCase - "fooBeforeEachCallback", - "barBeforeEachCallback", + // OuterTestCase + "fooBeforeEachCallback", + "barBeforeEachCallback", "beforeEachMethod", - "testOuter", + "testOuter", "afterEachMethod", - "barAfterEachCallback", - "fooAfterEachCallback", + "barAfterEachCallback", + "fooAfterEachCallback", - // InnerTestCase - "fooBeforeEachCallback", - "barBeforeEachCallback", - "fizzBeforeEachCallback", + // InnerTestCase + "fooBeforeEachCallback", + "barBeforeEachCallback", + "fizzBeforeEachCallback", "beforeEachMethod", - "beforeEachInnerMethod", - "testInner", - "afterEachInnerMethod", + "beforeEachInnerMethod", + "testInner", + "afterEachInnerMethod", "afterEachMethod", - "fizzAfterEachCallback", - "barAfterEachCallback", - "fooAfterEachCallback" + "fizzAfterEachCallback", + "barAfterEachCallback", + "fooAfterEachCallback" - ), callSequence, "wrong call sequence"); + ), "wrong call sequence"); // @formatter:on } @@ -103,13 +103,13 @@ void beforeEachAndAfterEachCallbacksDeclaredOnSuperclassAndSubclass() { assertEquals(0, testEvents.failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( - "fooBeforeEachCallback", - "barBeforeEachCallback", + assertEquals(callSequence, asList( + "fooBeforeEachCallback", + "barBeforeEachCallback", "testChild", - "barAfterEachCallback", - "fooAfterEachCallback" - ), callSequence, "wrong call sequence"); + "barAfterEachCallback", + "fooAfterEachCallback" + ), "wrong call sequence"); // @formatter:on } @@ -124,23 +124,23 @@ void beforeEachAndAfterEachCallbacksDeclaredOnInterfaceAndClass() { assertEquals(0, testEvents.failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( + assertEquals(callSequence, asList( - // Test Interface - "fooBeforeEachCallback", - "barBeforeEachCallback", + // Test Interface + "fooBeforeEachCallback", + "barBeforeEachCallback", "defaultTestMethod", - "barAfterEachCallback", - "fooAfterEachCallback", + "barAfterEachCallback", + "fooAfterEachCallback", - // Test Class - "fooBeforeEachCallback", - "barBeforeEachCallback", + // Test Class + "fooBeforeEachCallback", + "barBeforeEachCallback", "localTestMethod", - "barAfterEachCallback", - "fooAfterEachCallback" + "barAfterEachCallback", + "fooAfterEachCallback" - ), callSequence, "wrong call sequence"); + ), "wrong call sequence"); // @formatter:on } @@ -155,16 +155,16 @@ void beforeEachCallbackThrowsAnException() { assertEquals(1, testEvents.failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( - "fooBeforeEachCallback", - "exceptionThrowingBeforeEachCallback", // throws an exception. - // barBeforeEachCallback should not get invoked. + assertEquals(callSequence, asList( + "fooBeforeEachCallback", + "exceptionThrowingBeforeEachCallback", // throws an exception. + // barBeforeEachCallback should not get invoked. // beforeEachMethod should not get invoked. - // test should not get invoked. + // test should not get invoked. // afterEachMethod should not get invoked. - "barAfterEachCallback", - "fooAfterEachCallback" - ), callSequence, "wrong call sequence"); + "barAfterEachCallback", + "fooAfterEachCallback" + ), "wrong call sequence"); // @formatter:on assertThat(actualExceptionInAfterEachCallback).containsInstanceOf(EnigmaException.class); @@ -181,16 +181,16 @@ void afterEachCallbackThrowsAnException() { assertEquals(1, testEvents.failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( - "fooBeforeEachCallback", - "barBeforeEachCallback", + assertEquals(callSequence, asList( + "fooBeforeEachCallback", + "barBeforeEachCallback", "beforeEachMethod", - "test", + "test", "afterEachMethod", - "barAfterEachCallback", - "exceptionThrowingAfterEachCallback", // throws an exception. - "fooAfterEachCallback" - ), callSequence, "wrong call sequence"); + "barAfterEachCallback", + "exceptionThrowingAfterEachCallback", // throws an exception. + "fooAfterEachCallback" + ), "wrong call sequence"); // @formatter:on assertThat(actualExceptionInAfterEachCallback).containsInstanceOf(EnigmaException.class); @@ -233,7 +233,7 @@ void beforeEachMethodThrowsAnException() { List expected = beforeEachMethodCallSequence.getFirst().equals("beforeEachMethod1") ? list1 : list2; - assertEquals(expected, callSequence, "wrong call sequence"); + assertEquals(callSequence, expected, "wrong call sequence"); assertThat(actualExceptionInAfterEachCallback).containsInstanceOf(EnigmaException.class); } @@ -249,13 +249,13 @@ void afterEachMethodThrowsAnException() { assertEquals(1, testEvents.failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( - "fooBeforeEachCallback", + assertEquals(callSequence, asList( + "fooBeforeEachCallback", "beforeEachMethod", - "test", + "test", "afterEachMethod", // throws an exception. - "fooAfterEachCallback" - ), callSequence, "wrong call sequence"); + "fooAfterEachCallback" + ), "wrong call sequence"); // @formatter:on assertThat(actualExceptionInAfterEachCallback).containsInstanceOf(EnigmaException.class); @@ -272,13 +272,13 @@ void testMethodThrowsAnException() { assertEquals(1, testEvents.failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( - "fooBeforeEachCallback", + assertEquals(callSequence, asList( + "fooBeforeEachCallback", "beforeEachMethod", - "test", // throws an exception. + "test", // throws an exception. "afterEachMethod", - "fooAfterEachCallback" - ), callSequence, "wrong call sequence"); + "fooAfterEachCallback" + ), "wrong call sequence"); // @formatter:on assertThat(actualExceptionInAfterEachCallback).containsInstanceOf(EnigmaException.class); diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/BeforeAndAfterTestExecutionCallbackTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/BeforeAndAfterTestExecutionCallbackTests.java index 18a981e7dc96..2f559270e8ed 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/BeforeAndAfterTestExecutionCallbackTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/BeforeAndAfterTestExecutionCallbackTests.java @@ -65,31 +65,31 @@ void beforeAndAfterTestExecutionCallbacks() { assertEquals(0, executionResults.testEvents().failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( + assertEquals(callSequence, asList( - // OuterTestCase - "beforeEachMethodOuter", + // OuterTestCase + "beforeEachMethodOuter", "fooBeforeTestExecutionCallback", "barBeforeTestExecutionCallback", - "testOuter", + "testOuter", "barAfterTestExecutionCallback", "fooAfterTestExecutionCallback", - "afterEachMethodOuter", + "afterEachMethodOuter", - // InnerTestCase - "beforeEachMethodOuter", + // InnerTestCase + "beforeEachMethodOuter", "beforeEachMethodInner", - "fooBeforeTestExecutionCallback", - "barBeforeTestExecutionCallback", - "fizzBeforeTestExecutionCallback", - "testInner", - "fizzAfterTestExecutionCallback", - "barAfterTestExecutionCallback", - "fooAfterTestExecutionCallback", + "fooBeforeTestExecutionCallback", + "barBeforeTestExecutionCallback", + "fizzBeforeTestExecutionCallback", + "testInner", + "fizzAfterTestExecutionCallback", + "barAfterTestExecutionCallback", + "fooAfterTestExecutionCallback", "afterEachMethodInner", - "afterEachMethodOuter" + "afterEachMethodOuter" - ), callSequence, "wrong call sequence"); + ), "wrong call sequence"); // @formatter:on } @@ -104,13 +104,13 @@ void beforeAndAfterTestExecutionCallbacksDeclaredOnSuperclassAndSubclass() { assertEquals(0, executionResults.testEvents().failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( - "fooBeforeTestExecutionCallback", - "barBeforeTestExecutionCallback", + assertEquals(callSequence, asList( + "fooBeforeTestExecutionCallback", + "barBeforeTestExecutionCallback", "testChild", - "barAfterTestExecutionCallback", - "fooAfterTestExecutionCallback" - ), callSequence, "wrong call sequence"); + "barAfterTestExecutionCallback", + "fooAfterTestExecutionCallback" + ), "wrong call sequence"); // @formatter:on } @@ -125,23 +125,23 @@ void beforeAndAfterTestExecutionCallbacksDeclaredOnInterfaceAndClass() { assertEquals(0, executionResults.testEvents().failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( + assertEquals(callSequence, asList( - // Test Interface - "fooBeforeTestExecutionCallback", + // Test Interface + "fooBeforeTestExecutionCallback", "barBeforeTestExecutionCallback", - "defaultTestMethod", + "defaultTestMethod", "barAfterTestExecutionCallback", - "fooAfterTestExecutionCallback", + "fooAfterTestExecutionCallback", - // Test Class - "fooBeforeTestExecutionCallback", + // Test Class + "fooBeforeTestExecutionCallback", "barBeforeTestExecutionCallback", - "localTestMethod", + "localTestMethod", "barAfterTestExecutionCallback", - "fooAfterTestExecutionCallback" + "fooAfterTestExecutionCallback" - ), callSequence, "wrong call sequence"); + ), "wrong call sequence"); // @formatter:on } @@ -156,13 +156,13 @@ void beforeEachMethodThrowsAnException() { assertEquals(1, executionResults.testEvents().failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( - "beforeEachMethod", // throws an exception. + assertEquals(callSequence, asList( + "beforeEachMethod", // throws an exception. // fooBeforeTestExecutionCallback should not get invoked. - // test should not get invoked. + // test should not get invoked. // fooAfterTestExecutionCallback should not get invoked. - "afterEachMethod" - ), callSequence, "wrong call sequence"); + "afterEachMethod" + ), "wrong call sequence"); // @formatter:on assertNull(actualExceptionInAfterTestExecution, @@ -181,16 +181,16 @@ void beforeTestExecutionCallbackThrowsAnException() { assertEquals(1, executionResults.testEvents().failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( - "beforeEachMethod", + assertEquals(callSequence, asList( + "beforeEachMethod", "fooBeforeTestExecutionCallback", "exceptionThrowingBeforeTestExecutionCallback", // throws an exception. // barBeforeTestExecutionCallback should not get invoked. - // test() should not get invoked. + // test() should not get invoked. "barAfterTestExecutionCallback", "fooAfterTestExecutionCallback", - "afterEachMethod" - ), callSequence, "wrong call sequence"); + "afterEachMethod" + ), "wrong call sequence"); // @formatter:on assertNotNull(actualExceptionInAfterTestExecution, "test exception"); @@ -210,16 +210,16 @@ void afterTestExecutionCallbackThrowsAnException() { assertEquals(1, executionResults.testEvents().failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( - "beforeEachMethod", + assertEquals(callSequence, asList( + "beforeEachMethod", "fooBeforeTestExecutionCallback", "barBeforeTestExecutionCallback", - "test", + "test", "barAfterTestExecutionCallback", "exceptionThrowingAfterTestExecutionCallback", // throws an exception. "fooAfterTestExecutionCallback", - "afterEachMethod" - ), callSequence, "wrong call sequence"); + "afterEachMethod" + ), "wrong call sequence"); // @formatter:on assertNotNull(actualExceptionInAfterTestExecution, "test exception"); @@ -238,13 +238,13 @@ void testMethodThrowsAnException() { assertEquals(1, executionResults.testEvents().failed().count(), "# tests failed"); // @formatter:off - assertEquals(asList( - "beforeEachMethod", + assertEquals(callSequence, asList( + "beforeEachMethod", "fooBeforeTestExecutionCallback", - "test", // throws an exception. + "test", // throws an exception. "fooAfterTestExecutionCallback", - "afterEachMethod" - ), callSequence, "wrong call sequence"); + "afterEachMethod" + ), "wrong call sequence"); // @formatter:on assertNotNull(actualExceptionInAfterTestExecution, "test exception"); diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/TestInstancePostProcessorAndPreDestroyCallbackTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/TestInstancePostProcessorAndPreDestroyCallbackTests.java index 974d82af7679..0035741dcbbe 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/TestInstancePostProcessorAndPreDestroyCallbackTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/TestInstancePostProcessorAndPreDestroyCallbackTests.java @@ -114,7 +114,7 @@ private void assertPostProcessorAndPreDestroyCallbacks(Class testClass, int t executeTestsForClass(testClass).testEvents()// .assertStatistics(stats -> stats.started(1).succeeded(testsSuccessful)); - assertEquals(asList(expectedCalls), callSequence, () -> "wrong call sequence for " + testClass.getName()); + assertEquals(callSequence, asList(expectedCalls), () -> "wrong call sequence for " + testClass.getName()); } // ------------------------------------------------------------------------- diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/migrationsupport/rules/AbstractTestRuleAdapterTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/migrationsupport/rules/AbstractTestRuleAdapterTests.java index 0f3c98e30a11..323898da5cb5 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/migrationsupport/rules/AbstractTestRuleAdapterTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/migrationsupport/rules/AbstractTestRuleAdapterTests.java @@ -54,7 +54,7 @@ public void before() { JUnitException exception = assertThrows(JUnitException.class, adapter::before); - assertEquals(exception.getMessage(), "Failed to find method foo() in class org.junit.rules.ErrorCollector"); + assertEquals("Failed to find method foo() in class org.junit.rules.ErrorCollector", exception.getMessage()); } private static class TestableTestRuleAdapter extends AbstractTestRuleAdapter { diff --git a/platform-tests/src/test/java/org/junit/platform/engine/TestTagTests.java b/platform-tests/src/test/java/org/junit/platform/engine/TestTagTests.java index ca3efb2fb09e..9fdc2c957342 100644 --- a/platform-tests/src/test/java/org/junit/platform/engine/TestTagTests.java +++ b/platform-tests/src/test/java/org/junit/platform/engine/TestTagTests.java @@ -80,7 +80,7 @@ void tagEqualsOtherTagWithSameName() { assertEquals(TestTag.create("fast"), TestTag.create("fast")); assertEquals(TestTag.create("fast").hashCode(), TestTag.create("fast").hashCode()); assertNotEquals(null, TestTag.create("fast")); - assertNotEquals(TestTag.create("fast"), null); + assertNotEquals(null, TestTag.create("fast")); } @Test