Skip to content

Commit

Permalink
Fix StdIo and ReportEntry not targeting ANNOTATION_TYPE (#696 / #698)
Browse files Browse the repository at this point in the history
This commit fixes the annotations @ReportEntry and @stdio missing
the ANNOTATION_TYPE or TYPE from their @target. They can now be used
on composed annotations.

Closes: #696
PR: #698
  • Loading branch information
Michael1993 committed Nov 30, 2022
1 parent 1330e8b commit 63c82ed
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/junitpioneer/jupiter/ReportEntry.java
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/junitpioneer/jupiter/StdIo.java
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Arguments> 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 {
}

}
21 changes: 21 additions & 0 deletions src/test/java/org/junitpioneer/jupiter/StdIoExtensionTests.java
Expand Up @@ -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;

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -352,4 +367,10 @@ public void readAndWrite() throws IOException {

}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@StdIo
@interface ComposedIo {
}

}

0 comments on commit 63c82ed

Please sign in to comment.