From f4d7fa76cf3950d4aade6c52b13a7a37c62d6b27 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Fri, 13 Oct 2023 15:55:26 +0200 Subject: [PATCH] Declare TrackLogRecords on test method parameters rather than method --- .../jupiter/api/fixtures/TrackLogRecords.java | 2 +- .../engine/MultipleTestableAnnotationsTests.java | 3 +-- .../engine/descriptor/DisplayNameUtilsTests.java | 3 +-- ...onRegistrationViaParametersAndFieldsTests.java | 6 ++---- .../engine/extension/OrderedClassTests.java | 3 +-- .../engine/extension/OrderedMethodTests.java | 15 +++++---------- .../engine/extension/TestWatcherTests.java | 3 +-- .../extension/TimeoutConfigurationTests.java | 6 ++---- .../engine/VintageLauncherIntegrationTests.java | 10 ++++------ .../commons/util/ReflectionUtilsTests.java | 3 +-- .../SameThreadExecutionIntegrationTests.java | 3 +-- .../core/DefaultLauncherEngineFilterTests.java | 6 ++---- .../launcher/core/DefaultLauncherTests.java | 3 +-- 13 files changed, 23 insertions(+), 43 deletions(-) diff --git a/junit-jupiter-api/src/testFixtures/java/org/junit/jupiter/api/fixtures/TrackLogRecords.java b/junit-jupiter-api/src/testFixtures/java/org/junit/jupiter/api/fixtures/TrackLogRecords.java index ef33de69dda6..01619bf454d2 100644 --- a/junit-jupiter-api/src/testFixtures/java/org/junit/jupiter/api/fixtures/TrackLogRecords.java +++ b/junit-jupiter-api/src/testFixtures/java/org/junit/jupiter/api/fixtures/TrackLogRecords.java @@ -41,7 +41,7 @@ * @see LoggerFactory * @see LogRecordListener */ -@Target({ ElementType.TYPE, ElementType.METHOD }) +@Target({ ElementType.TYPE, ElementType.PARAMETER }) @Retention(RetentionPolicy.RUNTIME) @ExtendWith(TrackLogRecords.Extension.class) public @interface TrackLogRecords { diff --git a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/MultipleTestableAnnotationsTests.java b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/MultipleTestableAnnotationsTests.java index f8ded8659782..e604a59525ff 100644 --- a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/MultipleTestableAnnotationsTests.java +++ b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/MultipleTestableAnnotationsTests.java @@ -29,11 +29,10 @@ * * @since 5.0 */ -@TrackLogRecords class MultipleTestableAnnotationsTests extends AbstractJupiterTestEngineTests { @Test - void testAndRepeatedTest(LogRecordListener listener) { + void testAndRepeatedTest(@TrackLogRecords LogRecordListener listener) { discoverTests(request().selectors(selectClass(TestCase.class)).build()); // @formatter:off diff --git a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/descriptor/DisplayNameUtilsTests.java b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/descriptor/DisplayNameUtilsTests.java index 5a8679e4acd7..cab152e7fe0e 100644 --- a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/descriptor/DisplayNameUtilsTests.java +++ b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/descriptor/DisplayNameUtilsTests.java @@ -47,9 +47,8 @@ void shouldGetDisplayNameFromDisplayNameAnnotation() { } @Test - @TrackLogRecords void shouldGetDisplayNameFromSupplierIfNoDisplayNameAnnotationWithBlankStringPresent( - LogRecordListener listener) { + @TrackLogRecords LogRecordListener listener) { String displayName = DisplayNameUtils.determineDisplayName(BlankDisplayNameTestCase.class, () -> "default-name"); diff --git a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/ExtensionRegistrationViaParametersAndFieldsTests.java b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/ExtensionRegistrationViaParametersAndFieldsTests.java index 5b8a208d0492..aad66de58391 100644 --- a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/ExtensionRegistrationViaParametersAndFieldsTests.java +++ b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/ExtensionRegistrationViaParametersAndFieldsTests.java @@ -138,8 +138,7 @@ void fieldsWithTestInstancePerClass() { } @Test - @TrackLogRecords - void multipleRegistrationsViaField(LogRecordListener listener) { + void multipleRegistrationsViaField(@TrackLogRecords LogRecordListener listener) { assertOneTestSucceeded(MultipleRegistrationsViaFieldTestCase.class); assertThat(getRegisteredLocalExtensions(listener)).containsExactly("LongParameterResolver", "DummyExtension"); } @@ -158,8 +157,7 @@ void duplicateRegistrationViaField() { } @Test - @TrackLogRecords - void registrationOrder(LogRecordListener listener) { + void registrationOrder(@TrackLogRecords LogRecordListener listener) { assertOneTestSucceeded(AllInOneWithTestInstancePerMethodTestCase.class); assertThat(getRegisteredLocalExtensions(listener))// .containsExactly(// diff --git a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/OrderedClassTests.java b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/OrderedClassTests.java index 09026c6b1362..001fc49053f9 100644 --- a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/OrderedClassTests.java +++ b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/OrderedClassTests.java @@ -106,8 +106,7 @@ void orderAnnotationOnNestedTestClassesWithGlobalConfig() { } @Test - @TrackLogRecords - void orderAnnotationOnNestedTestClassesWithLocalConfig(LogRecordListener listener) { + void orderAnnotationOnNestedTestClassesWithLocalConfig(@TrackLogRecords LogRecordListener listener) { executeTests(ClassOrderer.class, selectClass(OuterWithLocalConfig.class))// .assertStatistics(stats -> stats.succeeded(callSequence.size())); diff --git a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/OrderedMethodTests.java b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/OrderedMethodTests.java index ed86fd2a2448..00c8a113a889 100644 --- a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/OrderedMethodTests.java +++ b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/OrderedMethodTests.java @@ -179,8 +179,7 @@ void defaultOrderer() { } @Test - @TrackLogRecords - void randomWithBogusSeedRepeatedly(LogRecordListener listener) { + void randomWithBogusSeedRepeatedly(@TrackLogRecords LogRecordListener listener) { var seed = "explode"; var expectedMessagePattern = Pattern.compile( "Failed to convert configuration parameter \\[" + Pattern.quote(Random.RANDOM_SEED_PROPERTY_NAME) @@ -209,8 +208,7 @@ void randomWithBogusSeedRepeatedly(LogRecordListener listener) { } @Test - @TrackLogRecords - void randomWithDifferentSeedConsecutively(LogRecordListener listener) { + void randomWithDifferentSeedConsecutively(@TrackLogRecords LogRecordListener listener) { Set uniqueSequences = new HashSet<>(); for (var i = 0; i < 10; i++) { @@ -240,8 +238,7 @@ void randomWithDifferentSeedConsecutively(LogRecordListener listener) { } @Test - @TrackLogRecords - void randomWithCustomSeed(LogRecordListener listener) { + void randomWithCustomSeed(@TrackLogRecords LogRecordListener listener) { var seed = "42"; var expectedMessage = "Using custom seed for configuration parameter [" + Random.RANDOM_SEED_PROPERTY_NAME + "] with value [" + seed + "]."; @@ -268,8 +265,7 @@ void randomWithCustomSeed(LogRecordListener listener) { } @Test - @TrackLogRecords - void misbehavingMethodOrdererThatAddsElements(LogRecordListener listener) { + void misbehavingMethodOrdererThatAddsElements(@TrackLogRecords LogRecordListener listener) { Class testClass = MisbehavingByAddingTestCase.class; executeTestsInParallel(testClass).assertStatistics(stats -> stats.succeeded(2)); @@ -283,8 +279,7 @@ void misbehavingMethodOrdererThatAddsElements(LogRecordListener listener) { } @Test - @TrackLogRecords - void misbehavingMethodOrdererThatRemovesElements(LogRecordListener listener) { + void misbehavingMethodOrdererThatRemovesElements(@TrackLogRecords LogRecordListener listener) { Class testClass = MisbehavingByRemovingTestCase.class; executeTestsInParallel(testClass).assertStatistics(stats -> stats.succeeded(3)); diff --git a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/TestWatcherTests.java b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/TestWatcherTests.java index 6ada22bf2527..bf4e1e2250a0 100644 --- a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/TestWatcherTests.java +++ b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/TestWatcherTests.java @@ -107,8 +107,7 @@ void testWatcherIsNotInvokedForTestFactoryMethods() { } @Test - @TrackLogRecords - void testWatcherExceptionsAreLoggedAndSwallowed(LogRecordListener logRecordListener) { + void testWatcherExceptionsAreLoggedAndSwallowed(@TrackLogRecords LogRecordListener logRecordListener) { assertCommonStatistics(executeTestsForClass(ExceptionThrowingTestWatcherTestCase.class)); // @formatter:off diff --git a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/TimeoutConfigurationTests.java b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/TimeoutConfigurationTests.java index 4886f2718607..996592f951cb 100644 --- a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/TimeoutConfigurationTests.java +++ b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/TimeoutConfigurationTests.java @@ -124,8 +124,7 @@ void specificTimeoutsAreUsedIfSet() { } @Test - @TrackLogRecords - void logsInvalidValues(LogRecordListener logRecordListener) { + void logsInvalidValues(@TrackLogRecords LogRecordListener logRecordListener) { when(extensionContext.getConfigurationParameter(DEFAULT_TEST_METHOD_TIMEOUT_PROPERTY_NAME)).thenReturn( Optional.of("invalid")); @@ -143,8 +142,7 @@ void specificThreadModeIsUsed() { } @Test - @TrackLogRecords - void logsInvalidThreadModeValueAndReturnEmpty(LogRecordListener logRecordListener) { + void logsInvalidThreadModeValueAndReturnEmpty(@TrackLogRecords LogRecordListener logRecordListener) { when(extensionContext.getConfigurationParameter(DEFAULT_TIMEOUT_THREAD_MODE_PROPERTY_NAME)).thenReturn( Optional.of("invalid")); diff --git a/junit-vintage-engine/src/test/java/org/junit/vintage/engine/VintageLauncherIntegrationTests.java b/junit-vintage-engine/src/test/java/org/junit/vintage/engine/VintageLauncherIntegrationTests.java index cb12669aef13..e6eea6bff78b 100644 --- a/junit-vintage-engine/src/test/java/org/junit/vintage/engine/VintageLauncherIntegrationTests.java +++ b/junit-vintage-engine/src/test/java/org/junit/vintage/engine/VintageLauncherIntegrationTests.java @@ -151,9 +151,8 @@ void removesCompleteClassIfItHasExcludedTag() { .containsExactly("JUnit Vintage"); } - @TrackLogRecords @Test - void executesAllTestsForNotFilterableRunner(LogRecordListener logRecordListener) { + void executesAllTestsForNotFilterableRunner(@TrackLogRecords LogRecordListener logRecordListener) { Class testClass = JUnit4TestCaseWithNotFilterableRunner.class; var request = request() // .selectors(selectClass(testClass)) // @@ -172,9 +171,8 @@ void executesAllTestsForNotFilterableRunner(LogRecordListener logRecordListener) + " does not support filtering and will therefore be run completely."); } - @TrackLogRecords @Test - void executesAllTestsForNotFilterableChildRunnerOfSuite(LogRecordListener logRecordListener) { + void executesAllTestsForNotFilterableChildRunnerOfSuite(@TrackLogRecords LogRecordListener logRecordListener) { Class suiteClass = JUnit4SuiteOfSuiteWithFilterableChildRunner.class; Class testClass = JUnit4TestCaseWithNotFilterableRunner.class; var request = request() // @@ -194,9 +192,9 @@ void executesAllTestsForNotFilterableChildRunnerOfSuite(LogRecordListener logRec + " was not able to satisfy all filter requests."); } - @TrackLogRecords @Test - void executesAllTestsWhenFilterDidNotExcludeTestForJUnit3Suite(LogRecordListener logRecordListener) { + void executesAllTestsWhenFilterDidNotExcludeTestForJUnit3Suite( + @TrackLogRecords LogRecordListener logRecordListener) { Class suiteClass = JUnit3SuiteWithSingleTestCaseWithSingleTestWhichFails.class; Class testClass = PlainJUnit3TestCaseWithSingleTestWhichFails.class; var request = request() // 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 d74b74ce7592..56ed88a8ddcc 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 @@ -838,8 +838,7 @@ private void assertNestedCycle(Class start, Class from, Class to) { * @since 1.3 */ @Test - @TrackLogRecords - void findNestedClassesWithInvalidNestedClassFile(LogRecordListener listener) throws Exception { + void findNestedClassesWithInvalidNestedClassFile(@TrackLogRecords LogRecordListener listener) throws Exception { var jarUrl = getClass().getResource("/gh-1436-invalid-nested-class-file.jar"); try (var classLoader = new URLClassLoader(new URL[] { jarUrl })) { diff --git a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/SameThreadExecutionIntegrationTests.java b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/SameThreadExecutionIntegrationTests.java index 9a17de1a825b..838fcacb842e 100644 --- a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/SameThreadExecutionIntegrationTests.java +++ b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/SameThreadExecutionIntegrationTests.java @@ -32,8 +32,7 @@ class SameThreadExecutionIntegrationTests { * @see gh-1688 */ @Test - @TrackLogRecords - void threadInterruptedByUserCode(LogRecordListener listener) { + void threadInterruptedByUserCode(@TrackLogRecords LogRecordListener listener) { EngineTestKit.engine("junit-jupiter")// .selectors(selectClass(InterruptedThreadTestCase.class))// .execute()// diff --git a/platform-tests/src/test/java/org/junit/platform/launcher/core/DefaultLauncherEngineFilterTests.java b/platform-tests/src/test/java/org/junit/platform/launcher/core/DefaultLauncherEngineFilterTests.java index 85732038f6de..34aa62947fad 100644 --- a/platform-tests/src/test/java/org/junit/platform/launcher/core/DefaultLauncherEngineFilterTests.java +++ b/platform-tests/src/test/java/org/junit/platform/launcher/core/DefaultLauncherEngineFilterTests.java @@ -148,8 +148,7 @@ void launcherWillExecuteEnginesHonoringBothIncludeAndExcludeEngineFilters() { } @Test - @TrackLogRecords - void launcherThrowsExceptionWhenNoEngineMatchesIncludeEngineFilter(LogRecordListener log) { + void launcherThrowsExceptionWhenNoEngineMatchesIncludeEngineFilter(@TrackLogRecords LogRecordListener log) { var engine = new DemoHierarchicalTestEngine("first"); TestDescriptor test1 = engine.addTest("test1", noOp); LauncherDiscoveryRequest request = request() // @@ -169,8 +168,7 @@ void launcherThrowsExceptionWhenNoEngineMatchesIncludeEngineFilter(LogRecordList } @Test - @TrackLogRecords - void launcherWillLogWarningWhenAllEnginesWereExcluded(LogRecordListener log) { + void launcherWillLogWarningWhenAllEnginesWereExcluded(@TrackLogRecords LogRecordListener log) { var engine = new DemoHierarchicalTestEngine("first"); TestDescriptor test = engine.addTest("test1", noOp); 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 f5b777b4b71d..2549fbc4c5e8 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 @@ -597,8 +597,7 @@ void testPlanThrowsExceptionWhenModified() { } @Test - @TrackLogRecords - void thirdPartyEngineUsingReservedEngineIdPrefixEmitsWarning(LogRecordListener listener) { + void thirdPartyEngineUsingReservedEngineIdPrefixEmitsWarning(@TrackLogRecords LogRecordListener listener) { var id = "junit-using-reserved-prefix"; var launcher = createLauncher(new TestEngineStub(id)); launcher.discover(request().build());