diff --git a/src/main/java/org/junitpioneer/jupiter/ReportEntry.java b/src/main/java/org/junitpioneer/jupiter/ReportEntry.java index a20c64c9f..84f54b320 100644 --- a/src/main/java/org/junitpioneer/jupiter/ReportEntry.java +++ b/src/main/java/org/junitpioneer/jupiter/ReportEntry.java @@ -39,7 +39,7 @@ * @since 0.5.6 */ @Repeatable(ReportEntry.ReportEntries.class) -@Target(ElementType.METHOD) +@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) @Retention(RetentionPolicy.RUNTIME) @ExtendWith(ReportEntryExtension.class) public @interface ReportEntry { diff --git a/src/main/java/org/junitpioneer/jupiter/StdIo.java b/src/main/java/org/junitpioneer/jupiter/StdIo.java index 5ce8c64a8..e77a6b9c2 100644 --- a/src/main/java/org/junitpioneer/jupiter/StdIo.java +++ b/src/main/java/org/junitpioneer/jupiter/StdIo.java @@ -40,7 +40,7 @@ * @since 0.7 */ @Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) +@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) @WritesStdIo @ExtendWith(StdIoExtension.class) public @interface StdIo { diff --git a/src/test/java/org/junitpioneer/jupiter/ReportEntryExtensionTests.java b/src/test/java/org/junitpioneer/jupiter/ReportEntryExtensionTests.java index bc827f41d..44b7afd35 100644 --- a/src/test/java/org/junitpioneer/jupiter/ReportEntryExtensionTests.java +++ b/src/test/java/org/junitpioneer/jupiter/ReportEntryExtensionTests.java @@ -18,6 +18,10 @@ import static org.junitpioneer.testkit.PioneerTestKit.abort; import static org.junitpioneer.testkit.assertion.PioneerAssert.assertThat; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.stream.Stream; import org.junit.jupiter.api.Disabled; @@ -90,6 +94,17 @@ void repeatedAnnotation_logEachKeyValuePairAsIndividualEntry() { "rapping at my chamber door"); } + @Test + @DisplayName("works as a meta-annotation") + void metaAnnotation() { + ExecutionResults results = PioneerTestKit + .executeTestMethod(ReportEntryTestCases.class, "with_composed_annotation"); + + assertThat(results) + .hasNumberOfReportEntries(1) + .withValues("“Though thy crest be shorn and shaven, thou,” I said, “art sure no craven,"); + } + @Nested @DisplayName("with explicitly set 'when' parameter") class PublishConditionTests { @@ -600,10 +615,21 @@ void parameterized_multiple(String line, int number) { void parameterized_with_nulls(String line, String value) { } + @Test + @ComposedEntry + void with_composed_annotation() { + } + private static Stream withNulls() { return Stream.of(Arguments.of("By the grave and stern decorum of the countenance it wore,", null)); } } + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + @ReportEntry("“Though thy crest be shorn and shaven, thou,” I said, “art sure no craven,") + @interface ComposedEntry { + } + } diff --git a/src/test/java/org/junitpioneer/jupiter/StdIoExtensionTests.java b/src/test/java/org/junitpioneer/jupiter/StdIoExtensionTests.java index d749829d7..a2e581305 100644 --- a/src/test/java/org/junitpioneer/jupiter/StdIoExtensionTests.java +++ b/src/test/java/org/junitpioneer/jupiter/StdIoExtensionTests.java @@ -22,6 +22,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.ArrayList; import java.util.List; @@ -61,6 +65,17 @@ void catchesOut(StdOut out) { "Lifts up his burning head, each under eye"); } + @Test + @ComposedIo + @DisplayName("works if StdIo is a meta-annotation") + void catchesOutFromMeta(StdOut out) { + app.write(); + + assertThat(out.capturedLines()) + .containsExactly("Lo! in the orient when the gracious light", + "Lifts up his burning head, each under eye"); + } + @Test @StdIo @DisplayName("catches the output on the standard err as lines") @@ -352,4 +367,10 @@ public void readAndWrite() throws IOException { } + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + @StdIo + @interface ComposedIo { + } + }