diff options
author | Léo Geoffroy <leo.geoffroy@sonarsource.com> | 2023-10-25 17:56:20 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-11-08 20:02:51 +0000 |
commit | 15d518496c28f5d782b0f9db53b61ff346b18542 (patch) | |
tree | 4cf1ab3272224fe0429fe2bf79505f7102387148 /sonar-core/src | |
parent | 3c40fffa36a740785892e8963916b07b4a5faed5 (diff) | |
download | sonarqube-15d518496c28f5d782b0f9db53b61ff346b18542.tar.gz sonarqube-15d518496c28f5d782b0f9db53b61ff346b18542.zip |
SONAR-20877 Add new status mapping
Diffstat (limited to 'sonar-core/src')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/issue/status/SimpleStatus.java | 56 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/issue/status/SimpleStatusTest.java | 62 |
2 files changed, 118 insertions, 0 deletions
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 new file mode 100644 index 00000000000..e910d4d8161 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/issue/status/SimpleStatus.java @@ -0,0 +1,56 @@ +/* + * 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.Nullable; +import org.sonar.api.issue.Issue; + +public enum SimpleStatus { + OPEN, + CONFIRMED, + FALSE_POSITIVE, + ACCEPTED, + FIXED; + + 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; + default: + } + if (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: + } + } + throw new IllegalArgumentException(String.format("Can't find mapped simple status for status '%s' and resolution '%s'", status, resolution)); + } +} 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 new file mode 100644 index 00000000000..b8cd9fd70de --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/issue/status/SimpleStatusTest.java @@ -0,0 +1,62 @@ +/* + * 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.Test; +import org.sonar.api.issue.Issue; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class SimpleStatusTest { + + @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_shouldThrowExceptionWhenUnknownMapping() { + assertThatThrownBy(() -> SimpleStatus.of(Issue.STATUS_RESOLVED, null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("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'"); + } + +} |