diff options
author | Léo Geoffroy <leo.geoffroy@sonarsource.com> | 2023-11-01 15:31:12 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-11-08 20:02:52 +0000 |
commit | f757b8680c35a43a6fdcb4d3930848008527fb16 (patch) | |
tree | 9b2cda7287557e812231d43e9eb0bdfd7b872cf1 /sonar-core/src | |
parent | a4718d6858cc6e44080641cb1da4e8f5c9ee0762 (diff) | |
download | sonarqube-f757b8680c35a43a6fdcb4d3930848008527fb16.tar.gz sonarqube-f757b8680c35a43a6fdcb4d3930848008527fb16.zip |
SONAR-20877 Add new status to changelog for issues
Diffstat (limited to 'sonar-core/src')
4 files changed, 47 insertions, 10 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 aa69711c00a..955dfdc1939 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 @@ -48,6 +48,7 @@ import org.sonar.api.rule.Severity; import org.sonar.api.rules.CleanCodeAttribute; import org.sonar.api.rules.RuleType; import org.sonar.api.utils.Duration; +import org.sonar.core.issue.status.SimpleStatus; import org.sonar.core.issue.tracking.Trackable; import static org.sonar.api.utils.DateUtils.truncateToSeconds; @@ -343,6 +344,12 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. return this; } + @Nullable + public SimpleStatus getSimpleStatus() { + Preconditions.checkArgument(!Strings.isNullOrEmpty(status), "Status must be set"); + return SimpleStatus.of(status, resolution); + } + @Override @CheckForNull public String resolution() { diff --git a/sonar-core/src/main/java/org/sonar/core/issue/status/SimpleStatus.java b/sonar-core/src/main/java/org/sonar/core/issue/status/SimpleStatus.java index 0be0e499470..e2744d16182 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/status/SimpleStatus.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/status/SimpleStatus.java @@ -21,15 +21,21 @@ package org.sonar.core.issue.status; import javax.annotation.CheckForNull; import javax.annotation.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.sonar.api.issue.Issue; public enum SimpleStatus { + + OPEN, CONFIRMED, FALSE_POSITIVE, ACCEPTED, FIXED; + private static final Logger LOGGER = LoggerFactory.getLogger(SimpleStatus.class); + @CheckForNull public static SimpleStatus of(String status, @Nullable String resolution) { switch (status) { @@ -57,6 +63,7 @@ public enum SimpleStatus { default: } } - throw new IllegalArgumentException(String.format("Can't find mapped simple status for status '%s' and resolution '%s'", status, resolution)); + LOGGER.warn("Can't find mapped simple status for status '{}' and resolution '{}'", status, resolution); + return null; } } 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 a09c91c03dc..4c1da1c1a16 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 @@ -23,9 +23,11 @@ import java.util.List; import java.util.Map; import org.apache.commons.lang.StringUtils; import org.junit.Test; +import org.sonar.api.issue.Issue; import org.sonar.api.issue.impact.Severity; import org.sonar.api.issue.impact.SoftwareQuality; import org.sonar.api.utils.Duration; +import org.sonar.core.issue.status.SimpleStatus; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -294,15 +296,33 @@ public class DefaultIssueTest { } + @Test 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)); + assertThat(issue.impacts()).containsExactlyInAnyOrderEntriesOf(Map.of(SoftwareQuality.MAINTAINABILITY, Severity.HIGH, SoftwareQuality.RELIABILITY, Severity.LOW)); + } + + @Test + public void getSimpleStatus_shouldReturnExpectedStatus() { + issue.setStatus(Issue.STATUS_RESOLVED); + issue.setResolution(Issue.RESOLUTION_FIXED); + + assertThat(issue.getSimpleStatus()).isEqualTo(SimpleStatus.FIXED); + } + + @Test + public void getSimpleStatus_shouldThrowException_whenStatusNotSet() { + issue.setResolution(Issue.RESOLUTION_FIXED); + + assertThatThrownBy(issue::getSimpleStatus) + .hasMessage("Status must be set") + .isInstanceOf(IllegalArgumentException.class); } @Test - public void replaceImpacts_shouldreplaceExistingImpacts() { + public void replaceImpacts_shouldReplaceExistingImpacts() { issue.addImpact(SoftwareQuality.MAINTAINABILITY, Severity.HIGH); issue.addImpact(SoftwareQuality.RELIABILITY, Severity.LOW); diff --git a/sonar-core/src/test/java/org/sonar/core/issue/status/SimpleStatusTest.java b/sonar-core/src/test/java/org/sonar/core/issue/status/SimpleStatusTest.java index 6ba0af10fe5..2e4ba579fdf 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/status/SimpleStatusTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/status/SimpleStatusTest.java @@ -19,14 +19,19 @@ */ package org.sonar.core.issue.status; +import org.junit.Rule; import org.junit.Test; import org.sonar.api.issue.Issue; +import org.sonar.api.testfixtures.log.LogAndArguments; +import org.sonar.api.testfixtures.log.LogTester; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; public class SimpleStatusTest { + @Rule + public LogTester logTester = new LogTester(); + @Test public void of_shouldMapToCorrectSimpleStatus() { assertThat(SimpleStatus.of(Issue.STATUS_RESOLVED, Issue.RESOLUTION_FIXED)) @@ -62,13 +67,11 @@ public class SimpleStatusTest { @Test public void of_shouldThrowExceptionWhenUnknownMapping() { - assertThatThrownBy(() -> SimpleStatus.of(Issue.STATUS_RESOLVED, null)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Can't find mapped simple status for status 'RESOLVED' and resolution 'null'"); + assertThat(SimpleStatus.of(Issue.STATUS_RESOLVED, null)).isNull(); + assertThat(logTester.getLogs()).extracting(LogAndArguments::getFormattedMsg).contains("Can't find mapped simple status for status 'RESOLVED' and resolution 'null'"); - assertThatThrownBy(() -> SimpleStatus.of(Issue.STATUS_RESOLVED, Issue.RESOLUTION_SAFE)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessage("Can't find mapped simple status for status 'RESOLVED' and resolution 'SAFE'"); + assertThat(SimpleStatus.of(Issue.STATUS_RESOLVED, Issue.RESOLUTION_SAFE)).isNull(); + assertThat(logTester.getLogs()).extracting(LogAndArguments::getFormattedMsg).contains("Can't find mapped simple status for status 'RESOLVED' and resolution 'SAFE'"); } } |