Skip to content

Commit

Permalink
Declare TrackLogRecords on test method parameters rather than method
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Oct 13, 2023
1 parent 9af6ca4 commit f4d7fa7
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ void shouldGetDisplayNameFromDisplayNameAnnotation() {
}

@Test
@TrackLogRecords
void shouldGetDisplayNameFromSupplierIfNoDisplayNameAnnotationWithBlankStringPresent(
LogRecordListener listener) {
@TrackLogRecords LogRecordListener listener) {

String displayName = DisplayNameUtils.determineDisplayName(BlankDisplayNameTestCase.class,
() -> "default-name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -158,8 +157,7 @@ void duplicateRegistrationViaField() {
}

@Test
@TrackLogRecords
void registrationOrder(LogRecordListener listener) {
void registrationOrder(@TrackLogRecords LogRecordListener listener) {
assertOneTestSucceeded(AllInOneWithTestInstancePerMethodTestCase.class);
assertThat(getRegisteredLocalExtensions(listener))//
.containsExactly(//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -209,8 +208,7 @@ void randomWithBogusSeedRepeatedly(LogRecordListener listener) {
}

@Test
@TrackLogRecords
void randomWithDifferentSeedConsecutively(LogRecordListener listener) {
void randomWithDifferentSeedConsecutively(@TrackLogRecords LogRecordListener listener) {
Set<String> uniqueSequences = new HashSet<>();

for (var i = 0; i < 10; i++) {
Expand Down Expand Up @@ -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 + "].";
Expand All @@ -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));
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ void testWatcherIsNotInvokedForTestFactoryMethods() {
}

@Test
@TrackLogRecords
void testWatcherExceptionsAreLoggedAndSwallowed(LogRecordListener logRecordListener) {
void testWatcherExceptionsAreLoggedAndSwallowed(@TrackLogRecords LogRecordListener logRecordListener) {
assertCommonStatistics(executeTestsForClass(ExceptionThrowingTestWatcherTestCase.class));

// @formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand All @@ -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"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) //
Expand All @@ -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() //
Expand All @@ -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() //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class SameThreadExecutionIntegrationTests {
* @see <a href="https://github.com/junit-team/junit5/issues/1688">gh-1688</a>
*/
@Test
@TrackLogRecords
void threadInterruptedByUserCode(LogRecordListener listener) {
void threadInterruptedByUserCode(@TrackLogRecords LogRecordListener listener) {
EngineTestKit.engine("junit-jupiter")//
.selectors(selectClass(InterruptedThreadTestCase.class))//
.execute()//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() //
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit f4d7fa7

Please sign in to comment.