Skip to content

Commit

Permalink
SLLS-263 Refactor label mapper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jblievremont committed Sep 20, 2024
1 parent 8fdb3d1 commit 5fa320e
Showing 1 changed file with 66 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
*/
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;
Expand All @@ -32,59 +33,84 @@

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);
@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));
assertThrows(IllegalArgumentException.class, () -> EnumLabelsMapper.resolutionStatusFromLabel("Unknown"));
}

@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() {
@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);
assertEquals("Info", EnumLabelsMapper.impactSeverityToLabel(ImpactSeverity.INFO));
assertEquals("Low", EnumLabelsMapper.impactSeverityToLabel(ImpactSeverity.LOW));
assertEquals("Medium", EnumLabelsMapper.impactSeverityToLabel(ImpactSeverity.MEDIUM));
assertEquals("High", EnumLabelsMapper.impactSeverityToLabel(ImpactSeverity.HIGH));
assertEquals("Blocker", EnumLabelsMapper.impactSeverityToLabel(ImpactSeverity.BLOCKER));
}

}

0 comments on commit 5fa320e

Please sign in to comment.