From 4de1d2f004390395412b3372f0decf677ca6931e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Fri, 20 Sep 2024 15:17:50 +0200 Subject: [PATCH] SLLS-263 Adopt INFO and BLOCKER impact severity levels --- pom.xml | 2 +- .../ls/clientapi/SonarLintVSCodeClient.java | 5 +- .../sonarlint/ls/util/EnumLabelsMapper.java | 2 + .../clientapi/SonarLintVSCodeClientTests.java | 3 +- .../ls/util/EnumLabelsMapperTests.java | 114 ++++++++++-------- 5 files changed, 75 insertions(+), 51 deletions(-) diff --git a/pom.xml b/pom.xml index 446ff2266..717205ece 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ 17 - 10.5.0.78949 + 10.6.0.79033 1.6.10 diff --git a/src/main/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClient.java b/src/main/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClient.java index eab50366b..9a34cfb5b 100644 --- a/src/main/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClient.java +++ b/src/main/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClient.java @@ -64,6 +64,7 @@ import org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.TaintVulnerabilityDto; import org.sonarsource.sonarlint.core.rpc.protocol.client.binding.AssistBindingParams; import org.sonarsource.sonarlint.core.rpc.protocol.client.binding.AssistBindingResponse; +import org.sonarsource.sonarlint.core.rpc.protocol.client.binding.NoBindingSuggestionFoundParams; import org.sonarsource.sonarlint.core.rpc.protocol.client.binding.SuggestBindingParams; import org.sonarsource.sonarlint.core.rpc.protocol.client.connection.AssistCreatingConnectionParams; import org.sonarsource.sonarlint.core.rpc.protocol.client.connection.AssistCreatingConnectionResponse; @@ -311,9 +312,9 @@ public AssistBindingResponse assistBinding(AssistBindingParams params, SonarLint } @Override - public void noBindingSuggestionFound(String projectKey) { + public void noBindingSuggestionFound(NoBindingSuggestionFoundParams params) { var messageRequestParams = new ShowMessageRequestParams(); - messageRequestParams.setMessage("SonarLint couldn't match the server project '" + projectKey + "' to any of the currently " + + messageRequestParams.setMessage("SonarLint couldn't match the server project '" + params.getProjectKey() + "' to any of the currently " + "open workspace folders. Please make sure the project is open in the workspace, or try configuring the binding manually."); messageRequestParams.setType(MessageType.Error); var learnMoreAction = new MessageActionItem("Learn more"); diff --git a/src/main/java/org/sonarsource/sonarlint/ls/util/EnumLabelsMapper.java b/src/main/java/org/sonarsource/sonarlint/ls/util/EnumLabelsMapper.java index a7eaa4c2f..928a2f73c 100644 --- a/src/main/java/org/sonarsource/sonarlint/ls/util/EnumLabelsMapper.java +++ b/src/main/java/org/sonarsource/sonarlint/ls/util/EnumLabelsMapper.java @@ -91,9 +91,11 @@ public static String softwareQualityToLabel(SoftwareQuality softwareQuality) { public static String impactSeverityToLabel(ImpactSeverity softwareQuality) { return switch (softwareQuality) { + case INFO -> "Info"; case LOW -> "Low"; case MEDIUM -> "Medium"; case HIGH -> "High"; + case BLOCKER -> "Blocker"; }; } diff --git a/src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java b/src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java index 898baebef..f59faf886 100644 --- a/src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java +++ b/src/test/java/org/sonarsource/sonarlint/ls/clientapi/SonarLintVSCodeClientTests.java @@ -67,6 +67,7 @@ import org.sonarsource.sonarlint.core.rpc.protocol.backend.tracking.TextRangeWithHashDto; import org.sonarsource.sonarlint.core.rpc.protocol.client.OpenUrlInBrowserParams; import org.sonarsource.sonarlint.core.rpc.protocol.client.binding.AssistBindingParams; +import org.sonarsource.sonarlint.core.rpc.protocol.client.binding.NoBindingSuggestionFoundParams; import org.sonarsource.sonarlint.core.rpc.protocol.client.binding.SuggestBindingParams; import org.sonarsource.sonarlint.core.rpc.protocol.client.connection.AssistCreatingConnectionParams; import org.sonarsource.sonarlint.core.rpc.protocol.client.connection.ConnectionSuggestionDto; @@ -533,7 +534,7 @@ void testNoBindingSuggestionFound() { var learnMoreAction = new MessageActionItem("Learn more"); messageRequestParams.setActions(List.of(learnMoreAction)); - underTest.noBindingSuggestionFound(projectKey); + underTest.noBindingSuggestionFound(new NoBindingSuggestionFoundParams(projectKey, false)); verify(client).showMessageRequest(messageRequestParams); verify(client).browseTo("https://docs.sonarsource.com/sonarlint/vs-code/troubleshooting/#troubleshooting-connected-mode-setup"); } diff --git a/src/test/java/org/sonarsource/sonarlint/ls/util/EnumLabelsMapperTests.java b/src/test/java/org/sonarsource/sonarlint/ls/util/EnumLabelsMapperTests.java index 976f2fe15..60292b803 100644 --- a/src/test/java/org/sonarsource/sonarlint/ls/util/EnumLabelsMapperTests.java +++ b/src/test/java/org/sonarsource/sonarlint/ls/util/EnumLabelsMapperTests.java @@ -19,72 +19,92 @@ */ package org.sonarsource.sonarlint.ls.util; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.sonarsource.sonarlint.core.rpc.protocol.backend.issue.ResolutionStatus; import org.sonarsource.sonarlint.core.rpc.protocol.common.CleanCodeAttribute; import org.sonarsource.sonarlint.core.rpc.protocol.common.CleanCodeAttributeCategory; import org.sonarsource.sonarlint.core.rpc.protocol.common.ImpactSeverity; import org.sonarsource.sonarlint.core.rpc.protocol.common.SoftwareQuality; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; class EnumLabelsMapperTests { - @Test - void resolutionStatusToLabel() { - assertThat(EnumLabelsMapper.resolutionStatusToLabel(ResolutionStatus.ACCEPT)).isEqualTo("Accepted"); - assertThat(EnumLabelsMapper.resolutionStatusToLabel(ResolutionStatus.FALSE_POSITIVE)).isEqualTo("False positive"); - assertThat(EnumLabelsMapper.resolutionStatusToLabel(ResolutionStatus.WONT_FIX)).isEqualTo("Won't fix"); + @ParameterizedTest(name = "ResolutionStatus.{0} is mapped to `{1}`") + @CsvSource({ + "ACCEPT , Accepted", + "FALSE_POSITIVE, False positive", + "WONT_FIX , Won't fix", + }) + void resolutionStatusToLabel(String enumName, String expectedLabel) { + assertThat(EnumLabelsMapper.resolutionStatusToLabel(ResolutionStatus.valueOf(enumName))).isEqualTo(expectedLabel); } - @Test - void resolutionStatusFromLabel() { - assertThat(EnumLabelsMapper.resolutionStatusFromLabel("Accepted")).isEqualTo(ResolutionStatus.ACCEPT); - assertThat(EnumLabelsMapper.resolutionStatusFromLabel("False positive")).isEqualTo(ResolutionStatus.FALSE_POSITIVE); - assertThat(EnumLabelsMapper.resolutionStatusFromLabel("Won't fix")).isEqualTo(ResolutionStatus.WONT_FIX); - assertThrows(IllegalArgumentException.class, () -> EnumLabelsMapper.resolutionStatusFromLabel("Unknown")); + @ParameterizedTest(name = "Label `{0}` is mapped to ResolutionStatus.{1}") + @CsvSource({ + "Accepted , ACCEPT", + "False positive, FALSE_POSITIVE", + "Won't fix , WONT_FIX", + }) + void resolutionStatusFromLabel(String label, String expectedEnumValue) { + assertThat(EnumLabelsMapper.resolutionStatusFromLabel(label)).isEqualTo(ResolutionStatus.valueOf(expectedEnumValue)); + assertThatThrownBy(() -> EnumLabelsMapper.resolutionStatusFromLabel("Unknown")).isInstanceOf(IllegalArgumentException.class); } - @Test - void cleanCodeAttributeToLabel() { - assertEquals("Not conventional", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.CONVENTIONAL)); - assertEquals("Not formatted", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.FORMATTED)); - assertEquals("Not identifiable", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.IDENTIFIABLE)); - assertEquals("Not clear", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.CLEAR)); - assertEquals("Not complete", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.COMPLETE)); - assertEquals("Not efficient", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.EFFICIENT)); - assertEquals("Not logical", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.LOGICAL)); - assertEquals("Not distinct", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.DISTINCT)); - assertEquals("Not focused", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.FOCUSED)); - assertEquals("Not modular", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.MODULAR)); - assertEquals("Not tested", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.TESTED)); - assertEquals("Not lawful", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.LAWFUL)); - assertEquals("Not respectful", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.RESPECTFUL)); - assertEquals("Not trustworthy", EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.TRUSTWORTHY)); + @ParameterizedTest(name = "CleanCodeAttribute.{0} is mapped to `{1}`") + @CsvSource({ + "CONVENTIONAL, Not conventional", + "FORMATTED , Not formatted", + "IDENTIFIABLE, Not identifiable", + "CLEAR , Not clear", + "COMPLETE , Not complete", + "EFFICIENT , Not efficient", + "LOGICAL , Not logical", + "DISTINCT , Not distinct", + "FOCUSED , Not focused", + "MODULAR , Not modular", + "TESTED , Not tested", + "LAWFUL , Not lawful", + "RESPECTFUL , Not respectful", + "TRUSTWORTHY , Not trustworthy" + }) + void cleanCodeAttributeToLabel(String enumName, String expectedLabel) { + assertThat(EnumLabelsMapper.cleanCodeAttributeToLabel(CleanCodeAttribute.valueOf(enumName))).isEqualTo(expectedLabel); } - @Test - void testCleanCodeAttributeCategoryToLabel() { - assertEquals("Adaptability", EnumLabelsMapper.cleanCodeAttributeCategoryToLabel(CleanCodeAttributeCategory.ADAPTABLE)); - assertEquals("Consistency", EnumLabelsMapper.cleanCodeAttributeCategoryToLabel(CleanCodeAttributeCategory.CONSISTENT)); - assertEquals("Intentionality", EnumLabelsMapper.cleanCodeAttributeCategoryToLabel(CleanCodeAttributeCategory.INTENTIONAL)); - assertEquals("Responsibility", EnumLabelsMapper.cleanCodeAttributeCategoryToLabel(CleanCodeAttributeCategory.RESPONSIBLE)); + @ParameterizedTest(name = "CleanCodeAttributeCategory.{0} is mapped to `{1}`") + @CsvSource({ + "ADAPTABLE , Adaptability", + "CONSISTENT , Consistency", + "INTENTIONAL, Intentionality", + "RESPONSIBLE, Responsibility" + }) + void testCleanCodeAttributeCategoryToLabel(String enumName, String expectedLabel) { + assertThat(EnumLabelsMapper.cleanCodeAttributeCategoryToLabel(CleanCodeAttributeCategory.valueOf(enumName))).isEqualTo(expectedLabel); } - @Test - void testSoftwareQualityToLabel() { - assertEquals("Maintainability", EnumLabelsMapper.softwareQualityToLabel(SoftwareQuality.MAINTAINABILITY)); - assertEquals("Reliability", EnumLabelsMapper.softwareQualityToLabel(SoftwareQuality.RELIABILITY)); - assertEquals("Security", EnumLabelsMapper.softwareQualityToLabel(SoftwareQuality.SECURITY)); + @ParameterizedTest(name = "SoftwareQuality.{0} is mapped to `{1}`") + @CsvSource({ + "MAINTAINABILITY, Maintainability", + "RELIABILITY , Reliability", + "SECURITY , Security" + }) + void testSoftwareQualityToLabel(String enumName, String expectedLabel) { + assertThat(EnumLabelsMapper.softwareQualityToLabel(SoftwareQuality.valueOf(enumName))).isEqualTo(expectedLabel); } - @Test - void testImpactSeverityToLabel() { - assertEquals("Low", EnumLabelsMapper.impactSeverityToLabel(ImpactSeverity.LOW)); - assertEquals("Medium", EnumLabelsMapper.impactSeverityToLabel(ImpactSeverity.MEDIUM)); - assertEquals("High", EnumLabelsMapper.impactSeverityToLabel(ImpactSeverity.HIGH)); + @ParameterizedTest(name = "ImpactSeverity.{0} is mapped to `{1}`") + @CsvSource({ + "INFO , Info", + "LOW , Low", + "MEDIUM , Medium", + "HIGH , High", + "BLOCKER, Blocker", + }) + void testImpactSeverityToLabel(String enumName, String expectedLabel) { + assertThat(EnumLabelsMapper.impactSeverityToLabel(ImpactSeverity.valueOf(enumName))).isEqualTo(expectedLabel); } }