@SerializedName("level")
private final String level;
- private Result(String ruleId, String message, LinkedHashSet<Location> locations,
+ private Result(String ruleId, String message, @Nullable LinkedHashSet<Location> locations,
@Nullable String primaryLocationLineHash, @Nullable List<CodeFlow> codeFlows, @Nullable String level) {
this.ruleId = ruleId;
this.message = WrappedText.of(message);
return message;
}
+ @CheckForNull
public Set<Location> getLocations() {
return locations;
}
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import javax.annotation.Nullable;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.sensor.SensorContext;
private void mapLocations(Result result, NewExternalIssue newExternalIssue) {
NewIssueLocation newIssueLocation = newExternalIssue.newLocation();
- if (result.getLocations().isEmpty()) {
+ Set<Location> locations = result.getLocations();
+ if (locations == null || locations.isEmpty()) {
newExternalIssue.at(locationMapper.fillIssueInProjectLocation(result, newIssueLocation));
} else {
- Location firstLocation = result.getLocations().iterator().next();
+ Location firstLocation = locations.iterator().next();
NewIssueLocation primaryLocation = fillFileOrProjectLocation(result, newIssueLocation, firstLocation);
newExternalIssue.at(primaryLocation);
}
}
@Test
- public void mapResult_whenLocationNotFound_createsProjectLocation() {
+ public void mapResult_whenLocationsIsEmpty_createsProjectLocation() {
+ NewExternalIssue newExternalIssue = resultMapper.mapResult(DRIVER_NAME, WARNING, result);
+
+ verify(locationMapper).fillIssueInProjectLocation(result, newExternalIssueLocation);
+ verifyNoMoreInteractions(locationMapper);
+ verify(newExternalIssue).at(newExternalIssueLocation);
+ verify(newExternalIssue, never()).addLocation(any());
+ verify(newExternalIssue, never()).addFlow(any());
+ }
+
+ @Test
+ public void mapResult_whenLocationsIsNull_createsProjectLocation() {
+ when(result.getLocations()).thenReturn(null);
NewExternalIssue newExternalIssue = resultMapper.mapResult(DRIVER_NAME, WARNING, result);
verify(locationMapper).fillIssueInProjectLocation(result, newExternalIssueLocation);