Skip to content

Commit

Permalink
Use null instead of Optional for detectionTool fields
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Mar 19, 2024
1 parent eaf2a3b commit 43ff507
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/main/java/io/codemodder/codetf/CodeTFResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public final class CodeTFResult {
private final String codemod;
private final String summary;
private final String description;
private final Optional<DetectionTool> detectionTool;
private final DetectionTool detectionTool;
private final Set<String> failedFiles;
private final List<CodeTFReference> references;
private final Map<String, String> properties;
Expand All @@ -29,7 +29,7 @@ public CodeTFResult(
this.codemod = CodeTFValidator.requireNonBlank(codemod);
this.summary = CodeTFValidator.requireNonBlank(summary);
this.description = CodeTFValidator.requireNonBlank(description);
this.detectionTool = Optional.ofNullable(detectionTool);
this.detectionTool = detectionTool;
this.failedFiles = CodeTFValidator.toImmutableCopyOrEmptyOnNull(failedFiles);
this.references = CodeTFValidator.toImmutableCopyOrEmptyOnNull(references);
this.properties = CodeTFValidator.toImmutableCopyOrEmptyOnNull(properties);
Expand All @@ -48,7 +48,7 @@ public String getDescription() {
return description;
}

public Optional<DetectionTool> getDetectionTool() {
public DetectionTool getDetectionTool() {
return detectionTool;
}

Expand Down Expand Up @@ -113,7 +113,7 @@ public CodeTFResult build() {
originalResult.getCodemod(),
updatedSummary != null ? updatedSummary : originalResult.getSummary(),
updatedDescription != null ? updatedDescription : originalResult.getDescription(),
originalResult.detectionTool.orElse(null),
originalResult.detectionTool,
originalResult.getFailedFiles(),
updatedReferences != null ? updatedReferences : originalResult.getReferences(),
originalResult.getProperties(),
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/io/codemodder/codetf/DetectorRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Objects;
import java.util.Optional;

/** Describes the "rule" section of a detection tool. */
public final class DetectorRule {
private final String id;
private final String name;
private final Optional<String> url;
private final String url;

@JsonCreator
public DetectorRule(
Expand All @@ -18,7 +17,7 @@ public DetectorRule(
@JsonProperty(value = "url", index = 3) String url) {
this.id = Objects.requireNonNull(id);
this.name = Objects.requireNonNull(name);
this.url = Optional.ofNullable(url);
this.url = url;
}

public String getId() {
Expand All @@ -29,7 +28,7 @@ public String getName() {
return name;
}

public Optional<String> getUrl() {
public String getUrl() {
return url;
}
}
6 changes: 3 additions & 3 deletions src/test/java/io/codemodder/codetf/CodeTFResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void it_creates_detection_tool_with_empty_url() {
assertEquals("rule", tool.getRule().getId());
assertEquals("Here's a rule", tool.getRule().getName());
assertEquals(2, tool.getFindings().size());
assertTrue(tool.getRule().getUrl().isEmpty());
assertNull(tool.getRule().getUrl());
}

@Test
Expand All @@ -112,8 +112,8 @@ void it_creates_detection_tool_with_url() {
assertEquals("rule", tool.getRule().getId());
assertEquals("Here's a rule", tool.getRule().getName());
assertEquals(2, tool.getFindings().size());
assertTrue(tool.getRule().getUrl().isPresent());
assertEquals("https://example.com", tool.getRule().getUrl().get());
assertNotNull(tool.getRule().getUrl());
assertEquals("https://example.com", tool.getRule().getUrl());
}

@Test
Expand Down

0 comments on commit 43ff507

Please sign in to comment.