diff --git a/src/main/java/io/jenkins/plugins/checks/api/ChecksAction.java b/src/main/java/io/jenkins/plugins/checks/api/ChecksAction.java index b153be98..d802169b 100644 --- a/src/main/java/io/jenkins/plugins/checks/api/ChecksAction.java +++ b/src/main/java/io/jenkins/plugins/checks/api/ChecksAction.java @@ -51,4 +51,13 @@ public Optional getDescription() { public Optional getIdentifier() { return Optional.ofNullable(identifier); } + + @Override + public String toString() { + return "ChecksAction{" + + "label='" + label + '\'' + + ", description='" + description + '\'' + + ", identifier='" + identifier + '\'' + + '}'; + } } diff --git a/src/main/java/io/jenkins/plugins/checks/api/ChecksAnnotation.java b/src/main/java/io/jenkins/plugins/checks/api/ChecksAnnotation.java index 3f0645f7..e7ad2507 100644 --- a/src/main/java/io/jenkins/plugins/checks/api/ChecksAnnotation.java +++ b/src/main/java/io/jenkins/plugins/checks/api/ChecksAnnotation.java @@ -101,6 +101,21 @@ public enum ChecksAnnotationLevel { FAILURE } + @Override + public String toString() { + return "ChecksAnnotation{" + + "path='" + path + '\'' + + ", startLine=" + startLine + + ", endLine=" + endLine + + ", annotationLevel=" + annotationLevel + + ", message='" + message + '\'' + + ", startColumn=" + startColumn + + ", endColumn=" + endColumn + + ", title='" + title + '\'' + + ", rawDetails='" + rawDetails + '\'' + + '}'; + } + /** * Builder for {@link ChecksAnnotation}. */ diff --git a/src/main/java/io/jenkins/plugins/checks/api/ChecksDetails.java b/src/main/java/io/jenkins/plugins/checks/api/ChecksDetails.java index 006fb8ad..2a27bcc8 100644 --- a/src/main/java/io/jenkins/plugins/checks/api/ChecksDetails.java +++ b/src/main/java/io/jenkins/plugins/checks/api/ChecksDetails.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Optional; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.Beta; @@ -112,6 +113,20 @@ public List getActions() { return actions; } + @Override + public String toString() { + return "ChecksDetails{" + + "name='" + name + '\'' + + ", detailsURL='" + detailsURL + '\'' + + ", status=" + status + + ", conclusion=" + conclusion + + ", startedAt=" + startedAt + + ", completedAt=" + completedAt + + ", output=" + output + + ", actions=" + actions + + '}'; + } + /** * Builder for {@link ChecksDetails}. */ diff --git a/src/main/java/io/jenkins/plugins/checks/api/ChecksImage.java b/src/main/java/io/jenkins/plugins/checks/api/ChecksImage.java index 2d4b5d2d..eb54daf3 100644 --- a/src/main/java/io/jenkins/plugins/checks/api/ChecksImage.java +++ b/src/main/java/io/jenkins/plugins/checks/api/ChecksImage.java @@ -60,4 +60,13 @@ public Optional getImageUrl() { public Optional getCaption() { return Optional.ofNullable(caption); } + + @Override + public String toString() { + return "ChecksImage{" + + "alt='" + alt + '\'' + + ", imageUrl='" + imageUrl + '\'' + + ", caption='" + caption + '\'' + + '}'; + } } diff --git a/src/main/java/io/jenkins/plugins/checks/api/ChecksOutput.java b/src/main/java/io/jenkins/plugins/checks/api/ChecksOutput.java index 0672ee67..56c12cd3 100644 --- a/src/main/java/io/jenkins/plugins/checks/api/ChecksOutput.java +++ b/src/main/java/io/jenkins/plugins/checks/api/ChecksOutput.java @@ -62,6 +62,17 @@ public List getChecksImages() { return images; } + @Override + public String toString() { + return "ChecksOutput{" + + "title='" + title + '\'' + + ", summary='" + summary + '\'' + + ", text='" + text + '\'' + + ", annotations=" + annotations + + ", images=" + images + + '}'; + } + /** * Builder for {@link ChecksOutput}. */ diff --git a/src/test/java/io/jenkins/plugins/checks/api/ChecksActionTest.java b/src/test/java/io/jenkins/plugins/checks/api/ChecksActionTest.java index cf86d8f6..df4d0520 100644 --- a/src/test/java/io/jenkins/plugins/checks/api/ChecksActionTest.java +++ b/src/test/java/io/jenkins/plugins/checks/api/ChecksActionTest.java @@ -13,5 +13,8 @@ void shouldConstructCorrectly() { assertThat(action.getLabel()).isPresent().hasValue("re-run"); assertThat(action.getDescription()).isPresent().hasValue("re-run the Jenkins build"); assertThat(action.getIdentifier()).isPresent().hasValue("re-run id"); + + assertThat(action).hasToString("ChecksAction{" + + "label='re-run', description='re-run the Jenkins build', identifier='re-run id'}"); } } diff --git a/src/test/java/io/jenkins/plugins/checks/api/ChecksAnnotationTest.java b/src/test/java/io/jenkins/plugins/checks/api/ChecksAnnotationTest.java index 6c871a77..29d3c00d 100644 --- a/src/test/java/io/jenkins/plugins/checks/api/ChecksAnnotationTest.java +++ b/src/test/java/io/jenkins/plugins/checks/api/ChecksAnnotationTest.java @@ -40,6 +40,14 @@ void shouldBuildCorrectlyWithAllFields() { .hasStartColumn(Optional.of(33)).hasEndColumn(Optional.of(38)) .hasTitle(Optional.of(TITLE)) .hasRawDetails(Optional.of(RAW_DETAILS)); + + assertThat(annotation).hasToString("ChecksAnnotation{" + + "path='github-checks-api-plugin/src/main/java/io/jenkins/plugins/checks/CheckGHEventSubscriber.java'" + + ", startLine=20, endLine=20, annotationLevel=NOTICE" + + ", message='Avoid unused private fields such as 'LOGGER''" + + ", startColumn=33, endColumn=38, title='UnusedPrivateField'" + + ", rawDetails='" + RAW_DETAILS + + "'}"); } @Test diff --git a/src/test/java/io/jenkins/plugins/checks/api/ChecksDetailsTest.java b/src/test/java/io/jenkins/plugins/checks/api/ChecksDetailsTest.java index 3c49de77..a0cefb44 100644 --- a/src/test/java/io/jenkins/plugins/checks/api/ChecksDetailsTest.java +++ b/src/test/java/io/jenkins/plugins/checks/api/ChecksDetailsTest.java @@ -2,7 +2,6 @@ import io.jenkins.plugins.checks.api.ChecksDetails.ChecksDetailsBuilder; import io.jenkins.plugins.checks.api.ChecksOutput.ChecksOutputBuilder; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import java.time.LocalDateTime; @@ -13,6 +12,7 @@ import java.util.Optional; import static io.jenkins.plugins.checks.api.ChecksDetailsAssert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests the class {@link ChecksDetails}. @@ -55,13 +55,20 @@ void shouldBuildCorrectlyWithAllFields() { .hasDetailsURL(Optional.of(detailsURL)) .hasConclusion(ChecksConclusion.SUCCESS); - Assertions.assertThat(details.getOutput()) + assertThat(details.getOutput()) .usingFieldByFieldValueComparator() .contains(output); - Assertions.assertThat(details.getActions()) + assertThat(details.getActions()) .usingFieldByFieldElementComparator() .containsExactlyElementsOf(actions); + + assertThat(details).hasToString("ChecksDetails{" + + "name='Jenkins', detailsURL='https://ci.jenkins.io', status=COMPLETED, conclusion=SUCCESS" + + ", startedAt=2020-06-27T01:10, completedAt=2021-07-28T02:20" + + ", output=" + output.toString() + + ", actions=" + actions.toString() + + "}"); } @Test @@ -72,7 +79,7 @@ void shouldBuildCorrectlyWhenAddingActions() { new ChecksAction("action_2", "the second action", "2")); actions.forEach(builder::addAction); - Assertions.assertThat(builder.build().getActions()) + assertThat(builder.build().getActions()) .usingFieldByFieldElementComparator() .containsExactlyInAnyOrderElementsOf(actions); } diff --git a/src/test/java/io/jenkins/plugins/checks/api/ChecksImageTest.java b/src/test/java/io/jenkins/plugins/checks/api/ChecksImageTest.java index 6e8ef109..9264fa7c 100644 --- a/src/test/java/io/jenkins/plugins/checks/api/ChecksImageTest.java +++ b/src/test/java/io/jenkins/plugins/checks/api/ChecksImageTest.java @@ -17,5 +17,10 @@ void shouldConstructCorrectly() { .hasAlt(Optional.of("warnings-chart")) .hasImageUrl(Optional.of("https://ci.jenkins.io/job/Plugins/job/warnings-ng-plugin/job/master/")) .hasCaption(Optional.of("charts generated by warning-ng-plugin")); + + assertThat(image).hasToString("ChecksImage{" + + "alt='warnings-chart'" + + ", imageUrl='https://ci.jenkins.io/job/Plugins/job/warnings-ng-plugin/job/master/'" + + ", caption='charts generated by warning-ng-plugin'}"); } } diff --git a/src/test/java/io/jenkins/plugins/checks/api/ChecksOutputTest.java b/src/test/java/io/jenkins/plugins/checks/api/ChecksOutputTest.java index 79170b0d..3677cc07 100644 --- a/src/test/java/io/jenkins/plugins/checks/api/ChecksOutputTest.java +++ b/src/test/java/io/jenkins/plugins/checks/api/ChecksOutputTest.java @@ -40,6 +40,12 @@ void shouldBuildCorrectlyWithAllFields() { assertThat(checksOutput.getChecksImages()) .usingFieldByFieldElementComparator() .containsExactlyInAnyOrderElementsOf(images); + + assertThat(checksOutput).hasToString("ChecksOutput{" + + "title='Coverage Report', summary='All code have been covered', text='# Markdown Supported Text'" + + ", annotations=" + annotations + + ", images=" + images + + "}"); } @Test