]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19050 consistent use of CodeCharacteristic term
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Mon, 24 Apr 2023 07:15:32 +0000 (09:15 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 24 Apr 2023 20:04:24 +0000 (20:04 +0000)
server/sonar-db-dao/src/main/java/org/sonar/db/issue/IssueDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToCodeCharacteristicConverter.java [new file with mode: 0644]
server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverter.java [deleted file]
server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleDtoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToCodeCharacteristicConverterTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverterTest.java [deleted file]
server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java

index e3c25bcd54c786fa2c2289185222ae6376c48110..abbef0bc7f2ab9725cd0beb01fdadab0d43ca0c9 100644 (file)
@@ -42,11 +42,12 @@ import org.sonar.core.issue.DefaultIssue;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.protobuf.DbIssues;
 import org.sonar.db.rule.RuleDto;
+import org.sonar.db.rule.RuleTypeToCodeCharacteristicConverter;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.sonar.api.utils.DateUtils.dateToLong;
 import static org.sonar.api.utils.DateUtils.longToDate;
-import static org.sonar.db.rule.RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic;
+import static org.sonar.db.rule.RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic;
 
 public final class IssueDto implements Serializable {
 
@@ -728,7 +729,7 @@ public final class IssueDto implements Serializable {
 
   @CheckForNull
   public CodeCharacteristic getEffectiveRuleCharacteristic() {
-    return ruleCharacteristic != null ? ruleCharacteristic : convertToRuleCharacteristic(ruleType);
+    return ruleCharacteristic != null ? ruleCharacteristic : RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic(ruleType);
   }
 
   public int getRuleType() {
index a3f1180e9c0ea94d144b058f73ca24399486e1ee..01fe39ea256fe4a8b119f52dc1fb933c5b8d7b19 100644 (file)
@@ -403,7 +403,7 @@ public class RuleDto {
   }
 
   public CodeCharacteristic getEffectiveCharacteristic() {
-    return characteristic != null ? characteristic : RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic(type);
+    return characteristic != null ? characteristic : RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic(type);
   }
 
   public RuleDto setCharacteristic(@Nullable CodeCharacteristic characteristic) {
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToCodeCharacteristicConverter.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToCodeCharacteristicConverter.java
new file mode 100644 (file)
index 0000000..76165c2
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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.db.rule;
+
+import org.sonar.api.code.CodeCharacteristic;
+import org.sonar.api.rules.RuleType;
+
+public class RuleTypeToCodeCharacteristicConverter {
+
+  private RuleTypeToCodeCharacteristicConverter() {
+  }
+
+  public static CodeCharacteristic convertToCodeCharacteristic(int ruleType) {
+    if (ruleType == 0) {
+      return CodeCharacteristic.CLEAR;
+    }
+    return convertToCodeCharacteristic(RuleType.valueOf(ruleType));
+  }
+
+  public static CodeCharacteristic convertToCodeCharacteristic(RuleType ruleType) {
+    return switch (ruleType) {
+      case BUG -> CodeCharacteristic.ROBUST;
+      case CODE_SMELL -> CodeCharacteristic.CLEAR;
+      case SECURITY_HOTSPOT, VULNERABILITY -> CodeCharacteristic.SECURE;
+    };
+  }
+
+}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverter.java b/server/sonar-db-dao/src/main/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverter.java
deleted file mode 100644 (file)
index 38f8b64..0000000
+++ /dev/null
@@ -1,45 +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.db.rule;
-
-import org.sonar.api.code.CodeCharacteristic;
-import org.sonar.api.rules.RuleType;
-
-public class RuleTypeToRuleCharacteristicConverter {
-
-  private RuleTypeToRuleCharacteristicConverter() {
-  }
-
-  public static CodeCharacteristic convertToRuleCharacteristic(int ruleType) {
-    if (ruleType == 0) {
-      return CodeCharacteristic.CLEAR;
-    }
-    return convertToRuleCharacteristic(RuleType.valueOf(ruleType));
-  }
-
-  public static CodeCharacteristic convertToRuleCharacteristic(RuleType ruleType) {
-    return switch (ruleType) {
-      case BUG -> CodeCharacteristic.ROBUST;
-      case CODE_SMELL -> CodeCharacteristic.CLEAR;
-      case SECURITY_HOTSPOT, VULNERABILITY -> CodeCharacteristic.SECURE;
-    };
-  }
-
-}
index e8483c24d5b4a2b7b63cca3d0fbf1c79c826f2f9..f805010721a771213878c6bac341fc26026f48d1 100644 (file)
@@ -189,7 +189,7 @@ public class RuleDtoTest {
     assertThat(characteristic).isNull();
 
     CodeCharacteristic effectiveCharacteristic = rule.getEffectiveCharacteristic();
-    CodeCharacteristic expected = RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic(RuleType.BUG);
+    CodeCharacteristic expected = RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic(RuleType.BUG);
     assertThat(effectiveCharacteristic).isEqualTo(expected);
   }
 
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToCodeCharacteristicConverterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToCodeCharacteristicConverterTest.java
new file mode 100644 (file)
index 0000000..b6d8073
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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.db.rule;
+
+import com.tngtech.java.junit.dataprovider.DataProvider;
+import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import com.tngtech.java.junit.dataprovider.UseDataProvider;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.sonar.api.code.CodeCharacteristic;
+import org.sonar.api.rules.RuleType;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.db.rule.RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic;
+
+@RunWith(DataProviderRunner.class)
+public class RuleTypeToCodeCharacteristicConverterTest {
+
+  @Test
+  @UseDataProvider("ruleTypeToCodeCharacteristicData")
+  public void convertToCodeCharacteristic_when_receivedNonNullRuleType_should_convertToCorrespondingDefaultCharacteristic(RuleType type,
+    CodeCharacteristic expectedCharacteristic) {
+    assertThat(convertToCodeCharacteristic(type)).isEqualTo(expectedCharacteristic);
+  }
+
+  @DataProvider
+  public static Object[][] ruleTypeToCodeCharacteristicData() {
+    return new Object[][] {
+      {RuleType.CODE_SMELL, CodeCharacteristic.CLEAR},
+      {RuleType.BUG, CodeCharacteristic.ROBUST},
+      {RuleType.VULNERABILITY, CodeCharacteristic.SECURE},
+      {RuleType.SECURITY_HOTSPOT, CodeCharacteristic.SECURE}
+    };
+  }
+
+}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverterTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/rule/RuleTypeToRuleCharacteristicConverterTest.java
deleted file mode 100644 (file)
index 508b407..0000000
+++ /dev/null
@@ -1,53 +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.db.rule;
-
-import com.tngtech.java.junit.dataprovider.DataProvider;
-import com.tngtech.java.junit.dataprovider.DataProviderRunner;
-import com.tngtech.java.junit.dataprovider.UseDataProvider;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.sonar.api.code.CodeCharacteristic;
-import org.sonar.api.rules.RuleType;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.rule.RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic;
-
-@RunWith(DataProviderRunner.class)
-public class RuleTypeToRuleCharacteristicConverterTest {
-
-  @Test
-  @UseDataProvider("ruleTypeToRulCharacteristicData")
-  public void convertToRuleCharacteristic_when_receivedNonNullRuleType_should_convertToCorrespondingDefaultCharacteristic(RuleType type,
-    CodeCharacteristic expectedCharacteristic) {
-    assertThat(convertToRuleCharacteristic(type)).isEqualTo(expectedCharacteristic);
-  }
-
-  @DataProvider
-  public static Object[][] ruleTypeToRulCharacteristicData() {
-    return new Object[][] {
-      {RuleType.CODE_SMELL, CodeCharacteristic.CLEAR},
-      {RuleType.BUG, CodeCharacteristic.ROBUST},
-      {RuleType.VULNERABILITY, CodeCharacteristic.SECURE},
-      {RuleType.SECURITY_HOTSPOT, CodeCharacteristic.SECURE}
-    };
-  }
-
-}
index 94f6523dcebc3d17fa97a575580ebae2b6f7876f..28b9d5e522fba8f32a6fab3148c0648f480c5f64 100644 (file)
@@ -38,6 +38,7 @@ import org.sonar.db.DatabaseUtils;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.ResultSetIterator;
+import org.sonar.db.rule.RuleTypeToCodeCharacteristicConverter;
 import org.sonar.server.security.SecurityStandards;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -45,7 +46,7 @@ import static org.elasticsearch.common.Strings.isNullOrEmpty;
 import static org.sonar.api.utils.DateUtils.longToDate;
 import static org.sonar.db.DatabaseUtils.getLong;
 import static org.sonar.db.rule.RuleDto.deserializeSecurityStandardsString;
-import static org.sonar.db.rule.RuleTypeToRuleCharacteristicConverter.convertToRuleCharacteristic;
+import static org.sonar.db.rule.RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic;
 import static org.sonar.server.security.SecurityStandards.fromSecurityStandards;
 
 /**
@@ -244,7 +245,7 @@ class IssueIteratorForSingleChunk implements IssueIterator {
       doc.setIsNewCodeReference(!isNullOrEmpty(rs.getString(24)));
 
       String characteristic = rs.getString(25);
-      doc.setCharacteristic(characteristic != null ? characteristic : convertToRuleCharacteristic(rs.getInt(26)).name());
+      doc.setCharacteristic(characteristic != null ? characteristic : RuleTypeToCodeCharacteristicConverter.convertToCodeCharacteristic(rs.getInt(26)).name());
 
       return doc;
     }