From 9f451cb3fb66e618e48278de7104e204b8695ef1 Mon Sep 17 00:00:00 2001 From: Léo Geoffroy Date: Mon, 6 Nov 2023 14:18:31 +0100 Subject: SONAR-20877 Update naming to issueStatus --- .../java/org/sonar/core/issue/DefaultIssue.java | 6 +- .../org/sonar/core/issue/status/IssueStatus.java | 69 +++++++++++++++++++ .../org/sonar/core/issue/status/SimpleStatus.java | 69 ------------------- .../main/resources/org/sonar/l10n/core.properties | 18 ++--- .../org/sonar/core/issue/DefaultIssueTest.java | 10 +-- .../sonar/core/issue/status/IssueStatusTest.java | 77 ++++++++++++++++++++++ .../sonar/core/issue/status/SimpleStatusTest.java | 77 ---------------------- 7 files changed, 160 insertions(+), 166 deletions(-) create mode 100644 sonar-core/src/main/java/org/sonar/core/issue/status/IssueStatus.java delete mode 100644 sonar-core/src/main/java/org/sonar/core/issue/status/SimpleStatus.java create mode 100644 sonar-core/src/test/java/org/sonar/core/issue/status/IssueStatusTest.java delete mode 100644 sonar-core/src/test/java/org/sonar/core/issue/status/SimpleStatusTest.java (limited to 'sonar-core/src') 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 955dfdc1939..f919ade4c22 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,7 +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.status.IssueStatus; import org.sonar.core.issue.tracking.Trackable; import static org.sonar.api.utils.DateUtils.truncateToSeconds; @@ -345,9 +345,9 @@ public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure. } @Nullable - public SimpleStatus getSimpleStatus() { + public IssueStatus getIssueStatus() { Preconditions.checkArgument(!Strings.isNullOrEmpty(status), "Status must be set"); - return SimpleStatus.of(status, resolution); + return IssueStatus.of(status, resolution); } @Override diff --git a/sonar-core/src/main/java/org/sonar/core/issue/status/IssueStatus.java b/sonar-core/src/main/java/org/sonar/core/issue/status/IssueStatus.java new file mode 100644 index 00000000000..93875e88dde --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/issue/status/IssueStatus.java @@ -0,0 +1,69 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +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 IssueStatus { + + + OPEN, + CONFIRMED, + FALSE_POSITIVE, + ACCEPTED, + FIXED; + + private static final Logger LOGGER = LoggerFactory.getLogger(IssueStatus.class); + + @CheckForNull + public static IssueStatus of(String status, @Nullable String resolution) { + switch (status) { + case Issue.STATUS_OPEN: + case Issue.STATUS_REOPENED: + return IssueStatus.OPEN; + case Issue.STATUS_CONFIRMED: + return IssueStatus.CONFIRMED; + case Issue.STATUS_CLOSED: + return IssueStatus.FIXED; + // Security hotspot should not return issue status as they are deprecated. + case Issue.STATUS_REVIEWED: + case Issue.STATUS_TO_REVIEW: + return null; + default: + } + if (Issue.STATUS_RESOLVED.equals(status) && resolution != null) { + switch (resolution) { + case Issue.RESOLUTION_FALSE_POSITIVE: + return IssueStatus.FALSE_POSITIVE; + case Issue.RESOLUTION_WONT_FIX: + return IssueStatus.ACCEPTED; + case Issue.RESOLUTION_FIXED: + return IssueStatus.FIXED; + default: + } + } + LOGGER.warn("Can't find mapped issue status for status '{}' and resolution '{}'", status, resolution); + return null; + } +} 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 deleted file mode 100644 index e2744d16182..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/issue/status/SimpleStatus.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -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) { - case Issue.STATUS_OPEN: - case Issue.STATUS_REOPENED: - return SimpleStatus.OPEN; - case Issue.STATUS_CONFIRMED: - return SimpleStatus.CONFIRMED; - case Issue.STATUS_CLOSED: - return SimpleStatus.FIXED; - // Security hotspot should not return simple status as they are deprecated. - case Issue.STATUS_REVIEWED: - case Issue.STATUS_TO_REVIEW: - return null; - default: - } - if (Issue.STATUS_RESOLVED.equals(status) && resolution != null) { - switch (resolution) { - case Issue.RESOLUTION_FALSE_POSITIVE: - return SimpleStatus.FALSE_POSITIVE; - case Issue.RESOLUTION_WONT_FIX: - return SimpleStatus.ACCEPTED; - case Issue.RESOLUTION_FIXED: - return SimpleStatus.FIXED; - default: - } - } - LOGGER.warn("Can't find mapped simple status for status '{}' and resolution '{}'", status, resolution); - return null; - } -} diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 5be65c97f7a..61e90368830 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1054,11 +1054,11 @@ issue.clean_code_attribute.TRUSTWORTHY=Not trustworthy issue.clean_code_attribute.TRUSTWORTHY.title=This is a responsibility issue, the code is not trustworthy enough. issue.clean_code_attribute.TRUSTWORTHY.advice=To be trustworthy, the code needs to abstain from revealing or hard-coding private information. -issue.simple_status.OPEN=Open -issue.simple_status.ACCEPTED=Accepted -issue.simple_status.CONFIRMED=Confirmed -issue.simple_status.FIXED=Fixed -issue.simple_status.FALSE_POSITIVE=False Positive +issue.issue_status.OPEN=Open +issue.issue_status.ACCEPTED=Accepted +issue.issue_status.CONFIRMED=Confirmed +issue.issue_status.FIXED=Fixed +issue.issue_status.FALSE_POSITIVE=False Positive issue.status.ACCEPTED=Accepted issue.status.REOPENED=Reopened @@ -1070,12 +1070,6 @@ issue.status.TO_REVIEW=To Review issue.status.IN_REVIEW=In Review issue.status.REVIEWED=Reviewed -issue.simple_status.OPEN=Open -issue.simple_status.ACCEPTED=Accepted -issue.simple_status.CONFIRMED=Confirmed -issue.simple_status.FIXED=Fixed -issue.simple_status.FALSE_POSITIVE=False Positive - issue.scope.MAIN=Main code issue.scope.TEST=Test code @@ -1180,7 +1174,7 @@ issues.facet.types=Type issues.facet.severities=Severity issues.facet.scopes=Scope issues.facet.projects=Project -issues.facet.simpleStatuses=Status +issues.facet.issueStatuses=Status issues.facet.hotspotStatuses=Hotspot Status issues.facet.assignees=Assignee issues.facet.files=File 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 4c1da1c1a16..baae9a88dd6 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 @@ -27,7 +27,7 @@ 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 org.sonar.core.issue.status.IssueStatus; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -305,18 +305,18 @@ public class DefaultIssueTest { } @Test - public void getSimpleStatus_shouldReturnExpectedStatus() { + public void getIssueStatus_shouldReturnExpectedStatus() { issue.setStatus(Issue.STATUS_RESOLVED); issue.setResolution(Issue.RESOLUTION_FIXED); - assertThat(issue.getSimpleStatus()).isEqualTo(SimpleStatus.FIXED); + assertThat(issue.getIssueStatus()).isEqualTo(IssueStatus.FIXED); } @Test - public void getSimpleStatus_shouldThrowException_whenStatusNotSet() { + public void getIssueStatus_shouldThrowException_whenStatusNotSet() { issue.setResolution(Issue.RESOLUTION_FIXED); - assertThatThrownBy(issue::getSimpleStatus) + assertThatThrownBy(issue::getIssueStatus) .hasMessage("Status must be set") .isInstanceOf(IllegalArgumentException.class); } diff --git a/sonar-core/src/test/java/org/sonar/core/issue/status/IssueStatusTest.java b/sonar-core/src/test/java/org/sonar/core/issue/status/IssueStatusTest.java new file mode 100644 index 00000000000..c3c8eef6513 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/issue/status/IssueStatusTest.java @@ -0,0 +1,77 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +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; + +public class IssueStatusTest { + + @Rule + public LogTester logTester = new LogTester(); + + @Test + public void of_shouldMapToCorrectIssueStatus() { + assertThat(IssueStatus.of(Issue.STATUS_RESOLVED, Issue.RESOLUTION_FIXED)) + .isEqualTo(IssueStatus.FIXED); + + assertThat(IssueStatus.of(Issue.STATUS_CONFIRMED, null)) + .isEqualTo(IssueStatus.CONFIRMED); + + assertThat(IssueStatus.of(Issue.STATUS_RESOLVED, Issue.RESOLUTION_FALSE_POSITIVE)) + .isEqualTo(IssueStatus.FALSE_POSITIVE); + + assertThat(IssueStatus.of(Issue.STATUS_RESOLVED, Issue.RESOLUTION_WONT_FIX)) + .isEqualTo(IssueStatus.ACCEPTED); + + assertThat(IssueStatus.of(Issue.STATUS_REOPENED, null)) + .isEqualTo(IssueStatus.OPEN); + + assertThat(IssueStatus.of(Issue.STATUS_CLOSED, null)) + .isEqualTo(IssueStatus.FIXED); + } + + @Test + public void of_shouldReturnNull_WhenStatusBelongsToHotspot() { + assertThat(IssueStatus.of(Issue.STATUS_TO_REVIEW, null)) + .isNull(); + + assertThat(IssueStatus.of(Issue.STATUS_REVIEWED, Issue.RESOLUTION_SAFE)) + .isNull(); + + assertThat(IssueStatus.of(Issue.STATUS_REVIEWED, Issue.RESOLUTION_ACKNOWLEDGED)) + .isNull(); + } + + @Test + public void of_shouldThrowExceptionWhenUnknownMapping() { + assertThat(IssueStatus.of(Issue.STATUS_RESOLVED, null)).isNull(); + assertThat(logTester.getLogs()).extracting(LogAndArguments::getFormattedMsg).contains("Can't find mapped issue status for status 'RESOLVED' and resolution 'null'"); + + assertThat(IssueStatus.of(Issue.STATUS_RESOLVED, Issue.RESOLUTION_SAFE)).isNull(); + assertThat(logTester.getLogs()).extracting(LogAndArguments::getFormattedMsg).contains("Can't find mapped issue status for status 'RESOLVED' and resolution 'SAFE'"); + } + +} 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 deleted file mode 100644 index 2e4ba579fdf..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/issue/status/SimpleStatusTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -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; - -public class SimpleStatusTest { - - @Rule - public LogTester logTester = new LogTester(); - - @Test - public void of_shouldMapToCorrectSimpleStatus() { - assertThat(SimpleStatus.of(Issue.STATUS_RESOLVED, Issue.RESOLUTION_FIXED)) - .isEqualTo(SimpleStatus.FIXED); - - assertThat(SimpleStatus.of(Issue.STATUS_CONFIRMED, null)) - .isEqualTo(SimpleStatus.CONFIRMED); - - assertThat(SimpleStatus.of(Issue.STATUS_RESOLVED, Issue.RESOLUTION_FALSE_POSITIVE)) - .isEqualTo(SimpleStatus.FALSE_POSITIVE); - - assertThat(SimpleStatus.of(Issue.STATUS_RESOLVED, Issue.RESOLUTION_WONT_FIX)) - .isEqualTo(SimpleStatus.ACCEPTED); - - assertThat(SimpleStatus.of(Issue.STATUS_REOPENED, null)) - .isEqualTo(SimpleStatus.OPEN); - - assertThat(SimpleStatus.of(Issue.STATUS_CLOSED, null)) - .isEqualTo(SimpleStatus.FIXED); - } - - @Test - public void of_shouldReturnNull_WhenStatusBelongsToHotspot() { - assertThat(SimpleStatus.of(Issue.STATUS_TO_REVIEW, null)) - .isNull(); - - assertThat(SimpleStatus.of(Issue.STATUS_REVIEWED, Issue.RESOLUTION_SAFE)) - .isNull(); - - assertThat(SimpleStatus.of(Issue.STATUS_REVIEWED, Issue.RESOLUTION_ACKNOWLEDGED)) - .isNull(); - } - - @Test - public void of_shouldThrowExceptionWhenUnknownMapping() { - 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'"); - - 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'"); - } - -} -- cgit v1.2.3