aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common/src
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2023-01-11 14:26:26 +0100
committersonartech <sonartech@sonarsource.com>2023-01-12 20:02:51 +0000
commit4dc57b2e3f3c8a30c7ffa1da6751e7bfae2d1d46 (patch)
tree897b2cbb9c504be88ec412d102d0f641247ce042 /server/sonar-server-common/src
parent44c39cc1617233606191e312682a26bd2dd01b46 (diff)
downloadsonarqube-4dc57b2e3f3c8a30c7ffa1da6751e7bfae2d1d46.tar.gz
sonarqube-4dc57b2e3f3c8a30c7ffa1da6751e7bfae2d1d46.zip
[NO-JIRA] Remove reported generic code smell
Diffstat (limited to 'server/sonar-server-common/src')
-rw-r--r--server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java5
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java22
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java5
3 files changed, 29 insertions, 3 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java
index b2d4f83f761..40f88950a0a 100644
--- a/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java
+++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.es;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap;
import java.util.Arrays;
import java.util.Map;
@@ -44,7 +43,7 @@ class IndexDefinitionHash {
IndexType.IndexMainType mainType = index.getMainType();
return of(
index.getSettings().toString(),
- ImmutableMap.of(mainType.getIndex(), mainType),
+ Map.of(mainType.getIndex(), mainType),
index.getRelationTypes().stream().collect(uniqueIndex(IndexType.IndexRelationType::getName, t -> t)),
index.getAttributes());
}
@@ -69,7 +68,7 @@ class IndexDefinitionHash {
private static void appendObject(StringBuilder sb, Object value) {
if (value instanceof Object[] arrayValue) {
sb.append(Arrays.toString(arrayValue));
- } else if (value instanceof Map map) {
+ } else if (value instanceof Map<?, ?> map) {
appendMap(sb, map);
} else if (value instanceof IndexType indexType) {
sb.append(indexType.format());
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java
index a719dcc8146..c0d7c6c5d08 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/ConditionEvaluatorTest.java
@@ -75,6 +75,28 @@ public class ConditionEvaluatorTest {
}
@Test
+ public void GREATER_THAN_long() {
+ test(new FakeMeasure(10L), Condition.Operator.GREATER_THAN, "9", EvaluatedCondition.EvaluationStatus.ERROR, "10");
+ test(new FakeMeasure(10L), Condition.Operator.GREATER_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10");
+ test(new FakeMeasure(10L), Condition.Operator.GREATER_THAN, "11", EvaluatedCondition.EvaluationStatus.OK, "10");
+
+ test(new FakeMeasure(10L), Condition.Operator.GREATER_THAN, "9", EvaluatedCondition.EvaluationStatus.ERROR, "10");
+ test(new FakeMeasure(10L), Condition.Operator.GREATER_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10");
+ test(new FakeMeasure(10L), Condition.Operator.GREATER_THAN, "11", EvaluatedCondition.EvaluationStatus.OK, "10");
+ }
+
+ @Test
+ public void LESS_THAN_long() {
+ test(new FakeMeasure(10L), Condition.Operator.LESS_THAN, "9", EvaluatedCondition.EvaluationStatus.OK, "10");
+ test(new FakeMeasure(10L), Condition.Operator.LESS_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10");
+ test(new FakeMeasure(10L), Condition.Operator.LESS_THAN, "11", EvaluatedCondition.EvaluationStatus.ERROR, "10");
+
+ test(new FakeMeasure(10L), Condition.Operator.LESS_THAN, "9", EvaluatedCondition.EvaluationStatus.OK, "10");
+ test(new FakeMeasure(10L), Condition.Operator.LESS_THAN, "10", EvaluatedCondition.EvaluationStatus.OK, "10");
+ test(new FakeMeasure(10L), Condition.Operator.LESS_THAN, "11", EvaluatedCondition.EvaluationStatus.ERROR, "10");
+ }
+
+ @Test
public void evaluate_throws_IAE_if_fail_to_parse_threshold() {
assertThatThrownBy(() -> test(new FakeMeasure(10), Condition.Operator.LESS_THAN, "9bar", EvaluatedCondition.EvaluationStatus.ERROR, "10da"))
.isInstanceOf(IllegalArgumentException.class)
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java
index f8391d4afbf..0f8623bcd65 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/FakeMeasure.java
@@ -46,6 +46,11 @@ public class FakeMeasure implements QualityGateEvaluator.Measure {
this.valueType = Metric.ValueType.INT;
}
+ public FakeMeasure(@Nullable Long value) {
+ this.value = value == null ? null : value.doubleValue();
+ this.valueType = Metric.ValueType.MILLISEC;
+ }
+
@Override
public Metric.ValueType getType() {
return valueType;