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

Use null instead of Optional for detectionTool fields #16

Merged
merged 2 commits into from
Mar 19, 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ To deserialize a CodeTF file using these objects, simply deserialize with Jackso

## Gradle
```kotlin
implementation("io.codemodder:codetf-java:3.1.1")
implementation("io.codemodder:codetf-java:3.2.0")
```

## Maven
```xml
<dependency>
<groupId>io.codemodder</groupId>
<artifactId>codetf-java</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.codemodder</groupId>
<artifactId>codetf-java</artifactId>
<version>3.1.1</version>
<version>3.2.0</version>


<name>codetf-java</name>
Expand Down
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
Loading