{@code @DisabledUntil} can be used on the method and class level. It can only be used once per method or class, * but is inherited from higher-level containers.
* + * @since 1.6.0 * @see org.junit.jupiter.api.Disabled */ @Retention(RetentionPolicy.RUNTIME) diff --git a/src/main/java/org/junitpioneer/jupiter/StopwatchExtension.java b/src/main/java/org/junitpioneer/jupiter/StopwatchExtension.java index a50547acc..c8806174f 100644 --- a/src/main/java/org/junitpioneer/jupiter/StopwatchExtension.java +++ b/src/main/java/org/junitpioneer/jupiter/StopwatchExtension.java @@ -36,30 +36,15 @@ public void afterTestExecution(ExtensionContext context) { calculateAndReportElapsedTime(context); } - /** - * Stores the current time for the method in the execution context. - * - * @param context Extension context of the class - */ - void storeNowAsLaunchTime(ExtensionContext context) { + private void storeNowAsLaunchTime(ExtensionContext context) { context.getStore(NAMESPACE).put(context.getUniqueId(), clock.instant().toEpochMilli()); } - /** - * Loads the stored time for method from the execution context. - * - * @param context Extension context of the class - */ - long loadLaunchTime(ExtensionContext context) { + private long loadLaunchTime(ExtensionContext context) { return context.getStore(NAMESPACE).get(context.getUniqueId(), long.class); } - /** - * Calculates the elapsed time method and publishes it to the execution context. - * - * @param context Extension context of the class - */ - void calculateAndReportElapsedTime(ExtensionContext context) { + private void calculateAndReportElapsedTime(ExtensionContext context) { long launchTime = loadLaunchTime(context); long elapsedTime = clock.instant().toEpochMilli() - launchTime; diff --git a/src/main/java/org/junitpioneer/jupiter/issue/IssueExtensionExecutionListener.java b/src/main/java/org/junitpioneer/jupiter/issue/IssueExtensionExecutionListener.java index 185966786..9f519ccd6 100644 --- a/src/main/java/org/junitpioneer/jupiter/issue/IssueExtensionExecutionListener.java +++ b/src/main/java/org/junitpioneer/jupiter/issue/IssueExtensionExecutionListener.java @@ -62,6 +62,7 @@ public void reportingEntryPublished(TestIdentifier testIdentifier, ReportEntry e if (messages.containsKey(REPORT_ENTRY_KEY)) { String issueId = messages.get(REPORT_ENTRY_KEY); + // because test IDs are unique, there's no risk of overriding previously entered information testCases.put(testId, new IssueTestCaseBuilder(testId).setIssueId(issueId)); } } diff --git a/src/test/java/org/junitpioneer/jupiter/StopwatchExtensionTests.java b/src/test/java/org/junitpioneer/jupiter/StopwatchExtensionTests.java index 98abf893f..a65e24cee 100644 --- a/src/test/java/org/junitpioneer/jupiter/StopwatchExtensionTests.java +++ b/src/test/java/org/junitpioneer/jupiter/StopwatchExtensionTests.java @@ -12,6 +12,7 @@ import static org.junitpioneer.testkit.assertion.PioneerAssert.assertThat; +import org.assertj.core.api.Assertions; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junitpioneer.testkit.ExecutionResults; @@ -21,49 +22,52 @@ @DisplayName("Stopwatch extension ") public class StopwatchExtensionTests { - @DisplayName("should be executed with annotation on class level and report an entry for test method") @Test + @DisplayName("should be executed with annotation on class level and report an entry for test method") void runClassLevelAnnotationTest() { - + String methodName = "stopwatchExtensionShouldBeExecutedWithAnnotationOnClassLevel"; ExecutionResults results = PioneerTestKit.executeTestClass(ClassLevelAnnotationTestCases.class); assertThat(results).hasNumberOfReportEntries(1); - String methodName = "stopwatchExtensionShouldBeExecutedWithAnnotationOnClassLevel"; assertStringStartWithUnitAndContainsName(results, methodName); - } - @DisplayName("should be executed with annotation on class level and test method and report an entry for test method") @Test + @DisplayName("should be executed with annotation on class level and test method and report an entry for test method") void runClassAndMethodLevelAnnotationTest() { String methodName = "stopwatchExtensionShouldBeExecutedWithAnnotationOnClassAndMethodLevel"; - ExecutionResults results = PioneerTestKit.executeTestClass(ClassAndMethodLevelAnnotationTestCases.class); assertThat(results).hasNumberOfReportEntries(1); assertStringStartWithUnitAndContainsName(results, methodName); } - @DisplayName("should be executed with annotation on test method and report an entry for test method") @Test + @DisplayName("should be executed with annotation on test method and report an entry for test method") void runMethodLevelAnnotationTest() { String methodName = "stopwatchExtensionShouldBeExecutedOnWithAnnotationOnMethodLevel"; - ExecutionResults results = PioneerTestKit.executeTestMethod(MethodLevelAnnotationTestCases.class, methodName); assertThat(results).hasNumberOfReportEntries(1); assertStringStartWithUnitAndContainsName(results, methodName); } - @DisplayName("should not be executed and therefore no entry should be published") @Test + @DisplayName("should not be executed and therefore no entry should be published") void runAnnotationTest() { String methodName = "stopwatchExtensionShouldNotBeExecuted"; - ExecutionResults results = PioneerTestKit.executeTestMethod(NonAnnotationTestCases.class, methodName); + assertThat(results).hasNumberOfReportEntries(0); + } + @Test + @DisplayName("should not change the report entry key") + void verifyReportEntryKey() { + // the store key is mentioned in the documentation and changing it would break + // `TestExecutionListener` implementations that use it to filter stopwatch report entries + Assertions.assertThat(StopwatchExtension.STORE_KEY).startsWith("StopwatchExtension"); } private void assertStringStartWithUnitAndContainsName(ExecutionResults results, String methodName) { @@ -89,8 +93,8 @@ void stopwatchExtensionShouldBeExecutedWithAnnotationOnClassLevel() { */ static class MethodLevelAnnotationTestCases { - @Stopwatch @Test + @Stopwatch void stopwatchExtensionShouldBeExecutedOnWithAnnotationOnMethodLevel() { } @@ -102,8 +106,8 @@ void stopwatchExtensionShouldBeExecutedOnWithAnnotationOnMethodLevel() { @Stopwatch static class ClassAndMethodLevelAnnotationTestCases { - @Stopwatch @Test + @Stopwatch void stopwatchExtensionShouldBeExecutedWithAnnotationOnClassAndMethodLevel() { }