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

Add toString for api models #8

Merged
merged 3 commits into from
Aug 10, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/io/jenkins/plugins/checks/api/ChecksAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ public Optional<String> getDescription() {
public Optional<String> getIdentifier() {
return Optional.ofNullable(identifier);
}

@Override
public String toString() {
return "ChecksAction{"
+ "label='" + label + '\''
+ ", description='" + description + '\''
+ ", identifier='" + identifier + '\''
+ '}';
}
}
15 changes: 15 additions & 0 deletions src/main/java/io/jenkins/plugins/checks/api/ChecksAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ public enum ChecksAnnotationLevel {
FAILURE
}

@Override
XiongKezhi marked this conversation as resolved.
Show resolved Hide resolved
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}.
*/
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/io/jenkins/plugins/checks/api/ChecksDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Optional;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
XiongKezhi marked this conversation as resolved.
Show resolved Hide resolved
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;

Expand Down Expand Up @@ -112,6 +113,20 @@ public List<ChecksAction> 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}.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/jenkins/plugins/checks/api/ChecksImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,13 @@ public Optional<String> getImageUrl() {
public Optional<String> getCaption() {
return Optional.ofNullable(caption);
}

@Override
public String toString() {
return "ChecksImage{"
+ "alt='" + alt + '\''
+ ", imageUrl='" + imageUrl + '\''
+ ", caption='" + caption + '\''
+ '}';
}
}
11 changes: 11 additions & 0 deletions src/main/java/io/jenkins/plugins/checks/api/ChecksOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ public List<ChecksImage> getChecksImages() {
return images;
}

@Override
public String toString() {
return "ChecksOutput{"
+ "title='" + title + '\''
+ ", summary='" + summary + '\''
+ ", text='" + text + '\''
+ ", annotations=" + annotations
+ ", images=" + images
+ '}';
}

/**
* Builder for {@link ChecksOutput}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions src/test/java/io/jenkins/plugins/checks/api/ChecksDetailsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}.
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down