aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>2023-08-09 14:18:17 +0200
committersonartech <sonartech@sonarsource.com>2023-08-18 20:02:48 +0000
commit6c53090d740ad446bf52e37318e3b6b58e94a76d (patch)
treee5a873a0f80a502f042b7a823e2bbbf4f0305e2d /sonar-core
parent88bb95d78ab8e02a11344a4e3d482ae2e48492a6 (diff)
downloadsonarqube-6c53090d740ad446bf52e37318e3b6b58e94a76d.tar.gz
sonarqube-6c53090d740ad446bf52e37318e3b6b58e94a76d.zip
SONAR-20021 persist impacts from report to Database
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java16
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java21
2 files changed, 36 insertions, 1 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java
index b26765e4c71..581def46912 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssue.java
@@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
+import java.util.EnumMap;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -133,6 +134,8 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure.
private String anticipatedTransitionUuid = null;
+ private Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> impacts = new EnumMap<>(SoftwareQuality.class);
+
@Override
public String key() {
return key;
@@ -150,7 +153,18 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure.
@Override
public Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> impacts() {
- return Collections.emptyMap();
+ return impacts;
+ }
+
+ public DefaultIssue replaceImpacts(Map<SoftwareQuality, org.sonar.api.issue.impact.Severity> impacts) {
+ this.impacts.clear();
+ this.impacts.putAll(impacts);
+ return this;
+ }
+
+ public DefaultIssue addImpact(SoftwareQuality softwareQuality, org.sonar.api.issue.impact.Severity severity) {
+ impacts.put(softwareQuality, severity);
+ return this;
}
public DefaultIssue setType(RuleType type) {
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java
index 9d1309c7850..a09c91c03dc 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java
@@ -20,8 +20,11 @@
package org.sonar.core.issue;
import java.util.List;
+import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
+import org.sonar.api.issue.impact.Severity;
+import org.sonar.api.issue.impact.SoftwareQuality;
import org.sonar.api.utils.Duration;
import static org.assertj.core.api.Assertions.assertThat;
@@ -288,5 +291,23 @@ public class DefaultIssueTest {
DefaultIssue defaultIssue = new DefaultIssue();
defaultIssue.setAnticipatedTransitionUuid("uuid");
assertThat(defaultIssue.getAnticipatedTransitionUuid()).isPresent();
+
+ }
+
+ public void getImpacts_whenAddingNewImpacts_shouldReturnListOfImpacts() {
+ issue.addImpact(SoftwareQuality.MAINTAINABILITY, Severity.HIGH);
+ issue.addImpact(SoftwareQuality.RELIABILITY, Severity.LOW);
+
+ assertThat(issue.impacts()).containsExactlyEntriesOf(Map.of(SoftwareQuality.MAINTAINABILITY, Severity.HIGH, SoftwareQuality.RELIABILITY, Severity.LOW));
+ }
+
+ @Test
+ public void replaceImpacts_shouldreplaceExistingImpacts() {
+ issue.addImpact(SoftwareQuality.MAINTAINABILITY, Severity.HIGH);
+ issue.addImpact(SoftwareQuality.RELIABILITY, Severity.LOW);
+
+ issue.replaceImpacts(Map.of(SoftwareQuality.SECURITY, Severity.LOW));
+
+ assertThat(issue.impacts()).containsExactlyEntriesOf(Map.of(SoftwareQuality.SECURITY, Severity.LOW));
}
}