]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5094 Convert the technical operators to human readable form
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 7 Mar 2014 14:24:48 +0000 (15:24 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 10 Mar 2014 09:14:39 +0000 (10:14 +0100)
sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java
sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java

index 18b6a364ecd5a284506417738a002993d51ca9ac..4355b70cee0b6ef28af926d34276229872d1e2de 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.batch.qualitygate;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 import org.apache.commons.lang.StringUtils;
@@ -33,17 +34,20 @@ import org.sonar.api.resources.Resource;
 import org.sonar.api.resources.ResourceUtils;
 import org.sonar.api.utils.Duration;
 import org.sonar.api.utils.Durations;
+import org.sonar.core.qualitygate.db.QualityGateConditionDto;
 import org.sonar.core.timemachine.Periods;
 
-import java.util.Collection;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
+import java.util.*;
 
 public class QualityGateVerifier implements Decorator {
 
   private static final String VARIATION_METRIC_PREFIX = "new_";
   private static final String VARIATION = "variation";
+  private static final Map<String, String> OPERATOR_LABELS = ImmutableMap.of(
+    QualityGateConditionDto.OPERATOR_EQUALS, "=",
+    QualityGateConditionDto.OPERATOR_NOT_EQUALS, "!=",
+    QualityGateConditionDto.OPERATOR_GREATER_THAN, ">",
+    QualityGateConditionDto.OPERATOR_LESS_THAN, "<");
 
   private QualityGate qualityGate;
 
@@ -147,7 +151,7 @@ public class QualityGateVerifier implements Decorator {
     }
 
     stringBuilder
-      .append(" ").append(condition.operator()).append(" ")
+      .append(" ").append(operatorLabel(condition.operator())).append(" ")
       .append(alertValue(condition, level));
 
     if (alertPeriod != null) {
@@ -166,6 +170,10 @@ public class QualityGateVerifier implements Decorator {
     }
   }
 
+  private String operatorLabel(String operator) {
+    return OPERATOR_LABELS.get(operator);
+  }
+
   @Override
   public String toString() {
     return getClass().getSimpleName();
index 53977f6b9f74ad0ecc2a7b02cb5289f463e18dbf..4d770de9b3da55f44f1bd3fee450c93d7ab3d133 100644 (file)
@@ -188,7 +188,7 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "Classes LT 10000, Coverages LT 50.0")));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "Classes < 10000, Coverages < 50.0")));
   }
 
   @Test
@@ -203,7 +203,7 @@ public class QualityGateVerifierTest {
     when(qualityGate.conditions()).thenReturn(conditions);
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "THE RATING LT 10")));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "THE RATING < 10")));
   }
 
   @Test
@@ -218,7 +218,7 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "Classes LT 10000")));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "Classes < 10000")));
   }
 
   @Test
@@ -343,7 +343,7 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.WARN, "Classes variation GT 30 since someday")));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.WARN, "Classes variation > 30 since someday")));
   }
 
   @Test
@@ -365,7 +365,7 @@ public class QualityGateVerifierTest {
 
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.WARN, "New Measure GT 30 since someday")));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.WARN, "New Measure > 30 since someday")));
   }
 
   @Test
@@ -381,7 +381,7 @@ public class QualityGateVerifierTest {
     when(qualityGate.conditions()).thenReturn(conditions);
     verifier.decorate(project, context);
 
-    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "The Debt LT 1h")));
+    verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.QUALITY_GATE_STATUS, Metric.Level.ERROR, "The Debt < 1h")));
   }
 
   private ArgumentMatcher<Measure> matchesMetric(final Metric metric, final Metric.Level alertStatus, final String alertText) {