}
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) {
}
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 ||
verify(context).saveMeasure(argThat(hasLevel(measureComplexity, Metric.Level.WARN)));
}
+ @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();