diff --git a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java index 468eda75..2aa7c764 100644 --- a/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java +++ b/src/test/java/io/jenkins/plugins/checks/status/BuildStatusChecksPublisherITest.java @@ -22,9 +22,18 @@ public class BuildStatusChecksPublisherITest extends IntegrationTestWithJenkinsP @TestExtension public static final LoggingChecksPublisher.Factory PUBLISHER_FACTORY = new LoggingChecksPublisher.Factory(); + /** + * Provide inject an implementation of {@link AbstractStatusChecksProperties} to control the checks. + */ @TestExtension public static final ChecksProperties PROPERTIES = new ChecksProperties(); + /** + * Tests when the implementation of {@link AbstractStatusChecksProperties} is not applicable, + * a status checks should not be published. + * + * @throws IOException if failed getting log from {@link Run} + */ @Test public void shouldNotPublishStatusWhenNotApplicable() throws IOException { PUBLISHER_FACTORY.setFormatter(details -> String.format(STATUS_TEMPLATE, @@ -37,6 +46,11 @@ public void shouldNotPublishStatusWhenNotApplicable() throws IOException { .doesNotContain(String.format(STATUS_TEMPLATE, "Test Status", "COMPLETED", "SUCCESS")); } + /** + * Tests when status checks is skipped, a status checks should not be published. + * + * @throws IOException if failed getting log from {@link Run} + */ @Test public void shouldNotPublishStatusWhenSkipped() throws IOException { PUBLISHER_FACTORY.setFormatter(details -> String.format(STATUS_TEMPLATE, @@ -49,9 +63,14 @@ public void shouldNotPublishStatusWhenSkipped() throws IOException { assertThat(JenkinsRule.getLog(buildSuccessfully(createFreeStyleProject()))) .doesNotContain(String.format(STATUS_TEMPLATE, "Test Status", "IN_PROGRESS", "NONE")) .doesNotContain(String.format(STATUS_TEMPLATE, "Test Status", "COMPLETED", "SUCCESS")); - } + /** + * Tests when an implementation of {@link AbstractStatusChecksProperties} is applicable and not skipped, + * a status checks using the specified name should be published. + * + * @throws IOException if failed getting log from {@link Run} + */ @Test public void shouldPublishStatusWithProperties() throws IOException { PUBLISHER_FACTORY.setFormatter(details -> String.format(STATUS_TEMPLATE, diff --git a/src/test/java/io/jenkins/plugins/checks/util/LoggingChecksPublisher.java b/src/test/java/io/jenkins/plugins/checks/util/LoggingChecksPublisher.java index 598156d5..34a3c09d 100644 --- a/src/test/java/io/jenkins/plugins/checks/util/LoggingChecksPublisher.java +++ b/src/test/java/io/jenkins/plugins/checks/util/LoggingChecksPublisher.java @@ -9,7 +9,36 @@ import java.util.Optional; +/** + * Implementation of {@link ChecksPublisher} for use in testing, that logs the checks details in user specified format. + * + * For example: + * + *
+ * public class ChecksPublishingTest extends IntegrationTestWithJenkinsPerTest {
+ *
+ *     @TestExtension
+ *     public static final LoggingChecksPublisher.Factory PUBLISHER_FACTORY = new LoggingChecksPublisher.Factory();
+ *
+ *     @Test
+ *     public void shouldLogChecks() {
+ *         // ...Run a test job...
+ *         Run run = buildSuccessfully(createFreeStyleProject());
+ *
+ *         // ...Inspect logs...
+ *         assertThat(JenkinsRule.getLog(run))
+ *                 .contains("...")
+ *                 .doesNotContain("...");
+ *     }
+ * }
+ * 
+ * + * An example of this can be found in {@link io.jenkins.plugins.checks.status.BuildStatusChecksPublisherITest} + */ public class LoggingChecksPublisher extends ChecksPublisher { + /** + * Defines how to format a {@link ChecksDetails} to {@link String}. + */ @FunctionalInterface public interface Formatter { String format(ChecksDetails details); @@ -18,11 +47,20 @@ public interface Formatter { private Formatter formatter = ChecksDetails::toString; private TaskListener listener = TaskListener.NULL; + /** + * Logs the {@code details} using the {@link TaskListener}. + * + * @param details + * checks details that will be logged + */ @Override public void publish(final ChecksDetails details) { listener.getLogger().print(formatter.format(details)); } + /** + * Implementation of {@link ChecksPublisherFactory} that returns a {@link LoggingChecksPublisher}. + */ public static class Factory extends ChecksPublisherFactory { private final LoggingChecksPublisher publisher = new LoggingChecksPublisher();