From 954f9022337a4d568eef9cd221cafae2aadf9da4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?L=C3=A9o=20Geoffroy?= Date: Tue, 31 Oct 2023 11:51:38 +0100 Subject: [PATCH] SONAR-20877 Add mapping for hotspots status --- .../org/sonar/core/issue/status/SimpleStatus.java | 6 ++++++ .../sonar/core/issue/status/SimpleStatusTest.java | 12 ++++++++++++ 2 files changed, 18 insertions(+) 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 e910d4d8161..ba9df611bfb 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 @@ -19,6 +19,7 @@ */ package org.sonar.core.issue.status; +import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.api.issue.Issue; @@ -29,6 +30,7 @@ public enum SimpleStatus { ACCEPTED, FIXED; + @CheckForNull public static SimpleStatus of(String status, @Nullable String resolution) { switch (status) { case Issue.STATUS_OPEN: @@ -38,6 +40,10 @@ public enum SimpleStatus { 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 (resolution != null) { 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 b8cd9fd70de..6ba0af10fe5 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 @@ -48,6 +48,18 @@ public class SimpleStatusTest { .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() { assertThatThrownBy(() -> SimpleStatus.of(Issue.STATUS_RESOLVED, null)) -- 2.39.5