aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2012-12-07 14:55:15 +0100
committerJulien Lancelot <julien.lancelot@gmail.com>2012-12-07 14:55:15 +0100
commit70eac6ea0e564da3735a3d80065326cee10c7c48 (patch)
tree763ba0f715331527183ecadf498d9d8576f2b058
parent428fbadc5f117da2a8e2bb8a9e43ddbf809f6fdb (diff)
downloadsonarqube-70eac6ea0e564da3735a3d80065326cee10c7c48.tar.gz
sonarqube-70eac6ea0e564da3735a3d80065326cee10c7c48.zip
SONAR-1352 Do not display "variation" on alerts on new metrics
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java4
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java22
2 files changed, 24 insertions, 2 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java
index 63e0efc328f..992c524e806 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java
@@ -43,6 +43,8 @@ import java.util.Locale;
public class CheckAlertThresholds implements Decorator {
+ private static final String VARIATION_METRIC_PREFIX = "new_";
+
private final Snapshot snapshot;
private final RulesProfile profile;
private final Periods periods;
@@ -140,7 +142,7 @@ public class CheckAlertThresholds implements Decorator {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(metric);
- if (alertPeriod != null) {
+ if (alertPeriod != null && !alert.getMetric().getKey().startsWith(VARIATION_METRIC_PREFIX)) {
String variation = i18n.message(getLocale(), "variation", null).toLowerCase();
stringBuilder.append(" ").append(variation);
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java
index 13af0bd4450..196cec3d98d 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java
@@ -218,7 +218,7 @@ public class CheckAlertThresholdsTest {
@Test
public void shouldVariationPeriodValueCouldBeUsedForRatingMetric() {
- Metric ratingMetric = new Metric.Builder("key.rating", "name.rating", Metric.ValueType.RATING).create();
+ Metric ratingMetric = new Metric.Builder("key_rating_metric", "Rating metric", Metric.ValueType.RATING).create();
Measure measureRatingMetric = new Measure(ratingMetric, 150d);
measureRatingMetric.setVariation1(50d);
when(context.getMeasure(ratingMetric)).thenReturn(measureRatingMetric);
@@ -273,6 +273,26 @@ public class CheckAlertThresholdsTest {
verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.WARN, "Classes variation > 30 since someday")));
}
+ @Test
+ public void shouldLabelAlertForNewMetricDoNotContainsVariationWord() {
+ Metric newMetric = new Metric.Builder("new_metric_key", "New Metric", Metric.ValueType.INT).create();
+ Measure measure = new Measure(newMetric, 15d);
+ measure.setVariation1(50d);
+ when(context.getMeasure(newMetric)).thenReturn(measure);
+ measureClasses.setVariation1(40d);
+
+ when(i18n.message(Mockito.any(Locale.class), Mockito.eq("metric.new_metric_key.name"), Mockito.isNull(String.class))).thenReturn("New Measure");
+ when(periods.label(snapshot, 1)).thenReturn("since someday");
+
+ when(profile.getAlerts()).thenReturn(Arrays.asList(
+ new Alert(null, newMetric, Alert.OPERATOR_GREATER, null, "30", 1) // generates warning because classes increases of 40, which is greater than 30
+ ));
+
+ decorator.decorate(project, context);
+
+ verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.WARN, "New Measure > 30 since someday")));
+ }
+
private ArgumentMatcher<Measure> matchesMetric(final Metric metric, final Metric.Level alertStatus, final String alertText) {
return new ArgumentMatcher<Measure>() {
@Override