]> source.dussan.org Git - sonarqube.git/commitdiff
do not persist measures with null value, null variations and "best-value" metric
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 21 Dec 2010 22:32:44 +0000 (22:32 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 21 Dec 2010 22:32:44 +0000 (22:32 +0000)
sonar-batch/src/main/java/org/sonar/batch/DefaultTimeMachine.java
sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
sonar-batch/src/test/java/org/sonar/batch/index/MeasurePersisterTest.java

index d15de3d2e6bfb6237d5ec66e2d739f7850ce6366..8c22431ce838b04860308cb4834699f3aa7e3aec 100644 (file)
@@ -149,8 +149,10 @@ public class DefaultTimeMachine implements TimeMachine {
     measure.setVariation1(model.getVariationValue1());
     measure.setVariation2(model.getVariationValue2());
     measure.setVariation3(model.getVariationValue3());
+    measure.setVariation4(model.getVariationValue4());
+    measure.setVariation5(model.getVariationValue5());
     measure.setUrl(model.getUrl());
     measure.setCharacteristic(model.getCharacteristic());
     return measure;
   }
-}
+}
\ No newline at end of file
index 19d118db5cae1eab4facad262ad557ce62092359..39737571315dc02b08f0e73c516d0d139e677323 100644 (file)
@@ -90,12 +90,11 @@ public final class MeasurePersister {
         !(ResourceUtils.isEntity(resource) && isBestValueMeasure(measure, metric));
   }
 
-  private static boolean isBestValueMeasure(Measure measure, Metric metric) {
+  static boolean isBestValueMeasure(Measure measure, Metric metric) {
     return measure.getId() == null &&
         metric.isOptimizedBestValue() == Boolean.TRUE &&
         metric.getBestValue() != null &&
-        measure.getValue() != null &
-        NumberUtils.compare(metric.getBestValue(), measure.getValue()) == 0 &&
+        (measure.getValue()==null || NumberUtils.compare(metric.getBestValue(), measure.getValue()) == 0) &&
         measure.getAlertStatus() == null &&
         measure.getDescription() == null &&
         measure.getTendency() == null &&
index c14b147d84dadb1e930dd3e31a63fcd90d510e2f..90d597908c5cdf098193abd051ce54064542a581 100644 (file)
@@ -201,6 +201,11 @@ public class MeasurePersisterTest extends AbstractDbUnitTestCase {
 
     duplicatedLines.setVariation1(-3.0);
     assertThat(MeasurePersister.shouldPersistMeasure(file, duplicatedLines), is(true));
+  }
 
+  @Test
+  public void nullValueAndNullVariationsShouldBeConsideredAsBestValue() {
+    Measure measure = new Measure(CoreMetrics.NEW_VIOLATIONS_KEY);
+    assertThat(MeasurePersister.isBestValueMeasure(measure, CoreMetrics.NEW_VIOLATIONS), is(true));
   }
 }