diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2012-11-29 14:09:26 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2012-11-29 14:09:46 +0100 |
commit | a6205990cf53ae1c823efd8e730c26f562805d6c (patch) | |
tree | 2a51f08db0d1b898de5a8d91d7a63e59b2630690 /plugins | |
parent | c0449e0a612fc44c4a4bff06a35c1f744c898608 (diff) | |
download | sonarqube-a6205990cf53ae1c823efd8e730c26f562805d6c.tar.gz sonarqube-a6205990cf53ae1c823efd8e730c26f562805d6c.zip |
SONAR-1352 Fix issue when analysing project for the first time and an alert with a period is existing
Diffstat (limited to 'plugins')
2 files changed, 26 insertions, 9 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java index cec2e22be17..5d5e6c89a2c 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/AlertUtils.java @@ -50,14 +50,16 @@ public final class AlertUtils { } Comparable criteriaValue = getValueForComparison(alert.getMetric(), valueToEval); - Comparable metricValue = getMeasureValue(alert, measure); - - int comparison = metricValue.compareTo(criteriaValue); - return !(// NOSONAR complexity of this boolean expression is under control - (alert.isNotEqualsOperator() && comparison == 0) - || (alert.isGreaterOperator() && comparison != 1) - || (alert.isSmallerOperator() && comparison != -1) - || (alert.isEqualsOperator() && comparison != 0)); + Comparable measureValue = getMeasureValue(alert, measure); + if (measureValue != null) { + int comparison = measureValue.compareTo(criteriaValue); + return !(// NOSONAR complexity of this boolean expression is under control + (alert.isNotEqualsOperator() && comparison == 0) + || (alert.isGreaterOperator() && comparison != 1) + || (alert.isSmallerOperator() && comparison != -1) + || (alert.isEqualsOperator() && comparison != 0)); + } + return false; } private static String getValueToEval(Alert alert, Metric.Level alertLevel) { @@ -100,7 +102,8 @@ public final class AlertUtils { } if (metric.getType() == Metric.ValueType.INT || metric.getType() == Metric.ValueType.MILLISEC) { - return getValue(alert, measure).intValue(); + Double value = getValue(alert, measure); + return value != null ? value.intValue() : null; } if (alert.getPeriod() == null) { if (metric.getType() == Metric.ValueType.STRING || 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 90d1ce756e5..0d1d5295b3b 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 @@ -198,6 +198,20 @@ public class CheckAlertThresholdsTest { } @Test + public void shouldBeOkIfVariationIsNull() { + measureClasses.setVariation1(null); + + when(profile.getAlerts()).thenReturn(Arrays.asList( + new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "10", 1) + )); + + decorator.decorate(project, context); + + verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.OK, null))); + verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK))); + } + + @Test public void shouldVariationPeriodValueCouldBeUsedForRatingMetric() { Metric ratingMetric = new Metric.Builder("key.rating", "name.rating", Metric.ValueType.RATING).create(); Measure measureRatingMetric = new Measure(ratingMetric, 150d); |