Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix StdIo and ReportEntry to target ANNOTATION_TYPE #698

Merged
merged 1 commit into from Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {
}

}