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 new failure property #25

Merged
merged 1 commit into from
Jul 24, 2024
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
22 changes: 13 additions & 9 deletions src/main/java/io/codemodder/codetf/CodeTFResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class CodeTFResult {
private final String summary;
private final String description;
private final DetectionTool detectionTool;
private final FailureState failureState;
private final Failure failure;
private final Set<String> failedFiles;
private final List<CodeTFReference> references;
private final Map<String, String> properties;
Expand All @@ -25,7 +25,7 @@ public CodeTFResult(
@JsonProperty(value = "summary", index = 2) final String summary,
@JsonProperty(value = "description", index = 3) final String description,
@JsonProperty(value = "detectionTool", index = 4) final DetectionTool detectionTool,
@JsonProperty(value = "failureState", index = 5) final FailureState failureState,
@JsonProperty(value = "failure", index = 5) final Failure failure,
@JsonProperty(value = "failedFiles", index = 6) final Set<String> failedFiles,
@JsonProperty(value = "references", index = 7) final List<CodeTFReference> references,
@JsonProperty(value = "properties", index = 8) final Map<String, String> properties,
Expand All @@ -35,7 +35,7 @@ public CodeTFResult(
this.summary = CodeTFValidator.requireNonBlank(summary);
this.description = CodeTFValidator.requireNonBlank(description);
this.detectionTool = detectionTool;
this.failureState = failureState;
this.failure = failure;
this.failedFiles = CodeTFValidator.toImmutableCopyOrEmptyOnNull(failedFiles);
this.references = CodeTFValidator.toImmutableCopyOrEmptyOnNull(references);
this.properties = CodeTFValidator.toImmutableCopyOrEmptyOnNull(properties);
Expand Down Expand Up @@ -68,8 +68,12 @@ public DetectionTool getDetectionTool() {
return detectionTool;
}

public FailureState getFailureState() {
return failureState;
public Failure getFailureState() {
return failure;
}

public boolean failed() {
return failure != null;
}

public Set<String> getFailedFiles() {
Expand Down Expand Up @@ -116,7 +120,7 @@ public static class Builder {
private String updatedSummary;
private String updatedDescription;

private FailureState failureState;
private Failure failure;
private List<CodeTFReference> updatedReferences;
private DetectionTool detectionTool;
private List<CodeTFChangesetEntry> changeset;
Expand All @@ -140,8 +144,8 @@ public Builder withDescription(final String description) {
return this;
}

public Builder withFailureState(final FailureState failureState) {
this.failureState = failureState;
public Builder withFailureState(final Failure failure) {
this.failure = failure;
return this;
}

Expand Down Expand Up @@ -185,7 +189,7 @@ public CodeTFResult build() {
updatedSummary != null ? updatedSummary : originalResult.getSummary(),
updatedDescription != null ? updatedDescription : originalResult.getDescription(),
detectionTool != null ? detectionTool : originalResult.getDetectionTool(),
failureState != null ? failureState : originalResult.getFailureState(),
failure != null ? failure : originalResult.getFailureState(),
originalResult.getFailedFiles(),
updatedReferences != null ? updatedReferences : originalResult.getReferences(),
originalResult.getProperties(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class FailureState {
private final boolean failed;
public class Failure {
private final String reason;
private final String exception;

@JsonCreator
public FailureState(
@JsonProperty("failed") final boolean failed,
public Failure(
@JsonProperty("reason") final String reason,
@JsonProperty("exception") final String exception) {
this.failed = failed;
this.reason = reason;
this.exception = exception;
}

public boolean failed() {
return failed;
}

public String reason() {
return reason;
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/io/codemodder/codetf/CodeTFResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ void it_has_changeset_with_ai() {

@Test
void it_has_failure_state() {
FailureState state = new FailureState(true, "reason", "exception");
assertTrue(state.failed());
Failure state = new Failure("reason", "exception");
assertEquals("reason", state.reason());
assertEquals("exception", state.exception());
}
Expand Down
Loading