]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8743 Handle only leak period when computing new coverage measures
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 7 Feb 2017 16:30:53 +0000 (17:30 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 9 Feb 2017 11:15:11 +0000 (12:15 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/VariationSumFormula.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/CoverageUtils.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/CoverageVariationFormula.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/ElementsAndCoveredElementsVariationCounter.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/LinesAndConditionsWithUncoveredVariationCounter.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/SingleWithUncoveredVariationCounter.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewCoverageMeasuresStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/formula/coverage/CoverageUtilsTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportNewCoverageMeasuresStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ViewsNewCoverageMeasuresStepTest.java

index 249a03095d272ea141f92f678f60215d02f67c81..77d1730e26b1e9e6b9223d6991c73d94f60ebe36 100644 (file)
 package org.sonar.server.computation.task.projectanalysis.formula;
 
 import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
 import org.sonar.server.computation.task.projectanalysis.formula.counter.DoubleVariationValue;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
 
-import static com.google.common.collect.FluentIterable.from;
 import static java.util.Objects.requireNonNull;
 import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
 
@@ -39,46 +35,29 @@ import static org.sonar.server.computation.task.projectanalysis.measure.Measure.
  */
 public class VariationSumFormula implements Formula<VariationSumFormula.VariationSumCounter> {
   private final String metricKey;
-  private final Predicate<Period> supportedPeriods;
   @CheckForNull
   private final Double defaultInputValue;
 
-  public VariationSumFormula(String metricKey, Predicate<Period> supportedPeriods) {
-    this(metricKey, supportedPeriods, null);
+  public VariationSumFormula(String metricKey) {
+    this(metricKey, null);
   }
 
-  public VariationSumFormula(String metricKey, Predicate<Period> supportedPeriods, @Nullable Double defaultInputValue) {
+  public VariationSumFormula(String metricKey, @Nullable Double defaultInputValue) {
     this.metricKey = requireNonNull(metricKey, "Metric key cannot be null");
-    this.supportedPeriods = requireNonNull(supportedPeriods, "Period predicate cannot be null");
     this.defaultInputValue = defaultInputValue;
   }
 
   @Override
   public VariationSumCounter createNewCounter() {
-    return new VariationSumCounter(metricKey, supportedPeriods, defaultInputValue);
+    return new VariationSumCounter(metricKey, defaultInputValue);
   }
 
   @Override
   public Optional<Measure> createMeasure(VariationSumCounter counter, CreateMeasureContext context) {
-    if (!CrawlerDepthLimit.LEAVES.isDeeperThan(context.getComponent().getType())) {
+    if (!CrawlerDepthLimit.LEAVES.isDeeperThan(context.getComponent().getType()) || !counter.doubleValue.isSet()) {
       return Optional.absent();
     }
-    MeasureVariations.Builder variations = createAndPopulateBuilder(counter.array, context);
-    if (variations.isEmpty()) {
-      return Optional.absent();
-    }
-    return Optional.of(newMeasureBuilder().setVariations(variations.build()).createNoValue());
-  }
-
-  private MeasureVariations.Builder createAndPopulateBuilder(DoubleVariationValue.Array array, CreateMeasureContext context) {
-    MeasureVariations.Builder builder = MeasureVariations.newMeasureVariationsBuilder();
-    for (Period period : from(context.getPeriods()).filter(supportedPeriods)) {
-      DoubleVariationValue elements = array.get(period);
-      if (elements.isSet()) {
-        builder.setVariation(period, elements.getValue());
-      }
-    }
-    return builder;
+    return Optional.of(newMeasureBuilder().setVariation(counter.doubleValue.getValue()).createNoValue());
   }
 
   @Override
@@ -89,48 +68,39 @@ public class VariationSumFormula implements Formula<VariationSumFormula.Variatio
   public static final class VariationSumCounter implements Counter<VariationSumCounter> {
     @CheckForNull
     private final Double defaultInputValue;
-    private final DoubleVariationValue.Array array = DoubleVariationValue.newArray();
+    private final DoubleVariationValue doubleValue = new DoubleVariationValue();
     private final String metricKey;
-    private final Predicate<Period> supportedPeriods;
 
-    private VariationSumCounter(String metricKey, Predicate<Period> supportedPeriods, @Nullable Double defaultInputValue) {
+    private VariationSumCounter(String metricKey, @Nullable Double defaultInputValue) {
       this.metricKey = metricKey;
-      this.supportedPeriods = supportedPeriods;
       this.defaultInputValue = defaultInputValue;
     }
 
     @Override
     public void aggregate(VariationSumCounter counter) {
-      array.incrementAll(counter.array);
+      doubleValue.increment(counter.doubleValue);
     }
 
     @Override
     public void initialize(CounterInitializationContext context) {
       Optional<Measure> measure = context.getMeasure(metricKey);
-      if (!measure.isPresent() || !measure.get().hasVariations()) {
-        initializeWithDefaultInputValue(context);
+      if (!measure.isPresent() || !measure.get().hasVariation()) {
+        initializeWithDefaultInputValue();
         return;
       }
-      MeasureVariations variations = measure.get().getVariations();
-      for (Period period : from(context.getPeriods()).filter(supportedPeriods)) {
-        if (variations.hasVariation(period.getIndex())) {
-          double variation = variations.getVariation(period.getIndex());
-          if (variation > 0) {
-            array.increment(period, variation);
-          } else if (defaultInputValue != null) {
-            array.increment(period, defaultInputValue);
-          }
-        }
+      double variation = measure.get().getVariation();
+      if (variation > 0) {
+        doubleValue.increment(variation);
+      } else if (defaultInputValue != null) {
+        doubleValue.increment(defaultInputValue);
       }
     }
 
-    private void initializeWithDefaultInputValue(CounterInitializationContext context) {
+    private void initializeWithDefaultInputValue() {
       if (defaultInputValue == null) {
         return;
       }
-      for (Period period : from(context.getPeriods()).filter(supportedPeriods)) {
-        array.increment(period, defaultInputValue);
-      }
+      doubleValue.increment(defaultInputValue);
     }
   }
 }
index 2b125a11c22015a78394cc6a4cad64ac86103fb2..47e9d2e51e3c9be92b3521d3f00177a68a8689da 100644 (file)
 package org.sonar.server.computation.task.projectanalysis.formula.coverage;
 
 import com.google.common.base.Optional;
-import org.sonar.server.computation.task.projectanalysis.component.Component;
 import org.sonar.server.computation.task.projectanalysis.formula.CounterInitializationContext;
-import org.sonar.server.computation.task.projectanalysis.formula.CreateMeasureContext;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
 
-import static com.google.common.collect.FluentIterable.from;
 import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
-import static org.sonar.server.computation.task.projectanalysis.period.PeriodPredicates.viewsRestrictedPeriods;
 
 public final class CoverageUtils {
   private static final Measure DEFAULT_MEASURE = newMeasureBuilder().create(0L);
-  private static final MeasureVariations DEFAULT_VARIATIONS = new MeasureVariations(0d, 0d, 0d, 0d, 0d);
 
   private CoverageUtils() {
     // prevents instantiation
@@ -54,42 +47,12 @@ public final class CoverageUtils {
     return measure.getLongValue();
   }
 
-  static MeasureVariations getMeasureVariations(CounterInitializationContext counterContext, String metricKey) {
+  static double getMeasureVariations(CounterInitializationContext counterContext, String metricKey) {
     Optional<Measure> measure = counterContext.getMeasure(metricKey);
-    if (!measure.isPresent() || !measure.get().hasVariations()) {
-      return DEFAULT_VARIATIONS;
+    if (!measure.isPresent() || !measure.get().hasVariation()) {
+      return 0d;
     }
-    return measure.get().getVariations();
-  }
-
-  static long getLongVariation(MeasureVariations variations, Period period) {
-    if (variations.hasVariation(period.getIndex())) {
-      return (long) variations.getVariation(period.getIndex());
-    }
-    return 0L;
-  }
-
-  /**
-   * Since Periods 4 and 5 can be customized per project and/or per view/subview, aggregating values on this period
-   * will only generate garbage data which will make no sense. These Periods should be ignored when processing views/subviews.
-   */
-  static Iterable<Period> supportedPeriods(CreateMeasureContext context) {
-    return supportedPeriods(context.getComponent().getType(), context.getPeriods());
-  }
-
-  /**
-   * Since Periods 4 and 5 can be customized per project and/or per view/subview, aggregating values on this period
-   * will only generate garbage data which will make no sense. These Periods should be ignored when processing views/subviews.
-   */
-  public static Iterable<Period> supportedPeriods(CounterInitializationContext context) {
-    return supportedPeriods(context.getLeaf().getType(), context.getPeriods());
-  }
-
-  private static Iterable<Period> supportedPeriods(Component.Type type, Iterable<Period> periods) {
-    if (type.isReportType()) {
-      return periods;
-    }
-    return from(periods).filter(viewsRestrictedPeriods());
+    return measure.get().getVariation();
   }
 
 }
index 659cd3a54619505a9f5780db555b3f5473a19bf7..b5b717c41ff697c0d421c4d05dce867b5c15b8d6 100644 (file)
@@ -24,11 +24,8 @@ import org.sonar.server.computation.task.projectanalysis.formula.CreateMeasureCo
 import org.sonar.server.computation.task.projectanalysis.formula.Formula;
 import org.sonar.server.computation.task.projectanalysis.formula.counter.LongVariationValue;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
 
 import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.calculateCoverage;
-import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.supportedPeriods;
 import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
 
 /**
@@ -39,23 +36,13 @@ public abstract class CoverageVariationFormula<T extends ElementsAndCoveredEleme
 
   @Override
   public Optional<Measure> createMeasure(T counter, CreateMeasureContext context) {
-    MeasureVariations.Builder builder = createAndPopulateBuilder(counter, context);
-    if (!builder.isEmpty()) {
-      return Optional.of(newMeasureBuilder().setVariations(builder.build()).createNoValue());
+    LongVariationValue elements = counter.elements;
+    if (elements.isSet() && elements.getValue() > 0d) {
+      LongVariationValue coveredElements = counter.coveredElements;
+      double variation = calculateCoverage(coveredElements.getValue(), elements.getValue());
+      return Optional.of(newMeasureBuilder().setVariation(variation).createNoValue());
     }
-
     return Optional.absent();
   }
 
-  private MeasureVariations.Builder createAndPopulateBuilder(T counter, CreateMeasureContext context) {
-    MeasureVariations.Builder builder = MeasureVariations.newMeasureVariationsBuilder();
-    for (Period period : supportedPeriods(context)) {
-      LongVariationValue elements = counter.elements.get(period);
-      if (elements.isSet() && elements.getValue() > 0d) {
-        LongVariationValue coveredElements = counter.coveredElements.get(period);
-        builder.setVariation(period, calculateCoverage(coveredElements.getValue(), elements.getValue()));
-      }
-    }
-    return builder;
-  }
 }
index 4ecd3fcedb3e8c967ca7864fb4001b8afff7a18c..5c41fa06079bec1ca712337f089cc61686d6205d 100644 (file)
@@ -28,13 +28,13 @@ import org.sonar.server.computation.task.projectanalysis.formula.counter.LongVar
  * A counter used to create measure variations which are based on a count of elements and coveredElements.
  */
 public abstract class ElementsAndCoveredElementsVariationCounter implements Counter<ElementsAndCoveredElementsVariationCounter> {
-  protected final LongVariationValue.Array elements = LongVariationValue.newArray();
-  protected final LongVariationValue.Array coveredElements = LongVariationValue.newArray();
+  protected final LongVariationValue elements = new LongVariationValue();
+  protected final LongVariationValue coveredElements = new LongVariationValue();
 
   @Override
   public void aggregate(ElementsAndCoveredElementsVariationCounter counter) {
-    elements.incrementAll(counter.elements);
-    coveredElements.incrementAll(counter.coveredElements);
+    elements.increment(counter.elements);
+    coveredElements.increment(counter.coveredElements);
   }
 
   @Override
index 2fc02e9e664c0842207dfd689c267bb685583f63..d233c4bdb075843db3fd4bf9f5254a35ff921273 100644 (file)
@@ -22,11 +22,6 @@ package org.sonar.server.computation.task.projectanalysis.formula.coverage;
 import com.google.common.base.Optional;
 import org.sonar.server.computation.task.projectanalysis.formula.CounterInitializationContext;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
-
-import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getLongVariation;
-import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.supportedPeriods;
 
 public final class LinesAndConditionsWithUncoveredVariationCounter extends ElementsAndCoveredElementsVariationCounter {
   private final LinesAndConditionsWithUncoveredMetricKeys metricKeys;
@@ -38,23 +33,16 @@ public final class LinesAndConditionsWithUncoveredVariationCounter extends Eleme
   @Override
   public void initializeForSupportedLeaf(CounterInitializationContext counterContext) {
     Optional<Measure> newLinesMeasure = counterContext.getMeasure(metricKeys.getLines());
-    if (!newLinesMeasure.isPresent() || !newLinesMeasure.get().hasVariations()) {
+    if (!newLinesMeasure.isPresent() || !newLinesMeasure.get().hasVariation()) {
       return;
     }
+    double newLines = newLinesMeasure.get().getVariation();
+    long newConditions = (long) CoverageUtils.getMeasureVariations(counterContext, metricKeys.getConditions());
+    long uncoveredLines = (long) CoverageUtils.getMeasureVariations(counterContext, metricKeys.getUncoveredLines());
+    long uncoveredConditions = (long) CoverageUtils.getMeasureVariations(counterContext, metricKeys.getUncoveredConditions());
 
-    MeasureVariations newLines = newLinesMeasure.get().getVariations();
-    MeasureVariations newConditions = CoverageUtils.getMeasureVariations(counterContext, metricKeys.getConditions());
-    MeasureVariations uncoveredLines = CoverageUtils.getMeasureVariations(counterContext, metricKeys.getUncoveredLines());
-    MeasureVariations uncoveredConditions = CoverageUtils.getMeasureVariations(counterContext, metricKeys.getUncoveredConditions());
-    for (Period period : supportedPeriods(counterContext)) {
-      if (!newLines.hasVariation(period.getIndex())) {
-        continue;
-      }
-      long elements = (long) newLines.getVariation(period.getIndex()) + getLongVariation(newConditions, period);
-      this.elements.increment(period, elements);
-      coveredElements.increment(
-        period,
-        elements - getLongVariation(uncoveredConditions, period) - getLongVariation(uncoveredLines, period));
-    }
+    long elements = (long) newLines + newConditions;
+    this.elements.increment(elements);
+    coveredElements.increment(elements - uncoveredConditions - uncoveredLines);
   }
 }
index d948b03824b9136d356dbca846dc6c018b314d18..250c323227f5f1e0c44d59ef0dce5dcc3f31e0d6 100644 (file)
 package org.sonar.server.computation.task.projectanalysis.formula.coverage;
 
 import org.sonar.server.computation.task.projectanalysis.formula.CounterInitializationContext;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
 
 import static java.util.Objects.requireNonNull;
-import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getLongVariation;
 import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getMeasureVariations;
-import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.supportedPeriods;
 
 public final class SingleWithUncoveredVariationCounter extends ElementsAndCoveredElementsVariationCounter {
   private final SingleWithUncoveredMetricKeys metricKeys;
@@ -37,12 +33,9 @@ public final class SingleWithUncoveredVariationCounter extends ElementsAndCovere
 
   @Override
   protected void initializeForSupportedLeaf(CounterInitializationContext counterContext) {
-    MeasureVariations newConditions = getMeasureVariations(counterContext, metricKeys.getCovered());
-    MeasureVariations uncoveredConditions = getMeasureVariations(counterContext, metricKeys.getUncovered());
-    for (Period period : supportedPeriods(counterContext)) {
-      long elements = getLongVariation(newConditions, period);
-      this.elements.increment(period, elements);
-      coveredElements.increment(period, elements - getLongVariation(uncoveredConditions, period));
-    }
+    long newConditions = (long) getMeasureVariations(counterContext, metricKeys.getCovered());
+    long uncoveredConditions = (long) getMeasureVariations(counterContext, metricKeys.getUncovered());
+    this.elements.increment(newConditions);
+    coveredElements.increment(newConditions - uncoveredConditions);
   }
 }
index 0662d7ffd143f37e446da1ef9c843c86b48e8424..b2ca9560fc63c07e31361234e939fe51f7b270ff 100644 (file)
@@ -47,7 +47,6 @@ import org.sonar.server.computation.task.projectanalysis.formula.coverage.Single
 import org.sonar.server.computation.task.projectanalysis.formula.coverage.SingleWithUncoveredVariationFormula;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepository;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
 import org.sonar.server.computation.task.projectanalysis.metric.Metric;
 import org.sonar.server.computation.task.projectanalysis.metric.MetricRepository;
 import org.sonar.server.computation.task.projectanalysis.period.Period;
@@ -57,7 +56,6 @@ import org.sonar.server.computation.task.projectanalysis.scm.ScmInfoRepository;
 import org.sonar.server.computation.task.step.ComputationStep;
 
 import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
-import static org.sonar.server.computation.task.projectanalysis.period.PeriodPredicates.viewsRestrictedPeriods;
 
 /**
  * Computes measures related to the New Coverage. These measures do not have values, only variations.
@@ -143,10 +141,10 @@ public class NewCoverageMeasuresStep implements ComputationStep {
      */
     private static Iterable<Formula<?>> variationSumFormulas(NewCoverageOutputMetricKeys outputMetricKeys) {
       return ImmutableList.of(
-        new VariationSumFormula(outputMetricKeys.getNewLinesToCover(), viewsRestrictedPeriods()),
-        new VariationSumFormula(outputMetricKeys.getNewUncoveredLines(), viewsRestrictedPeriods()),
-        new VariationSumFormula(outputMetricKeys.getNewConditionsToCover(), viewsRestrictedPeriods()),
-        new VariationSumFormula(outputMetricKeys.getNewUncoveredConditions(), viewsRestrictedPeriods()));
+        new VariationSumFormula(outputMetricKeys.getNewLinesToCover()),
+        new VariationSumFormula(outputMetricKeys.getNewUncoveredLines()),
+        new VariationSumFormula(outputMetricKeys.getNewConditionsToCover()),
+        new VariationSumFormula(outputMetricKeys.getNewUncoveredConditions()));
     }
   }
 
@@ -194,31 +192,25 @@ public class NewCoverageMeasuresStep implements ComputationStep {
 
     @Override
     public Optional<Measure> createMeasure(NewCoverageCounter counter, CreateMeasureContext context) {
-      MeasureVariations.Builder builder = MeasureVariations.newMeasureVariationsBuilder();
-      for (Period period : context.getPeriods()) {
-        if (counter.hasNewCode(period)) {
-          int value = computeValueForMetric(counter, period, context.getMetric());
-          builder.setVariation(period, value);
-        }
+      if (counter.hasNewCode()) {
+        int value = computeValueForMetric(counter, context.getMetric());
+        return Optional.of(newMeasureBuilder().setVariation(value).createNoValue());
       }
-      if (builder.isEmpty()) {
-        return Optional.absent();
-      }
-      return Optional.of(newMeasureBuilder().setVariations(builder.build()).createNoValue());
+      return Optional.absent();
     }
 
-    private int computeValueForMetric(NewCoverageCounter counter, Period period, Metric metric) {
+    private int computeValueForMetric(NewCoverageCounter counter, Metric metric) {
       if (metric.getKey().equals(outputMetricKeys.getNewLinesToCover())) {
-        return counter.getNewLines(period);
+        return counter.getNewLines();
       }
       if (metric.getKey().equals(outputMetricKeys.getNewUncoveredLines())) {
-        return counter.getNewLines(period) - counter.getNewCoveredLines(period);
+        return counter.getNewLines() - counter.getNewCoveredLines();
       }
       if (metric.getKey().equals(outputMetricKeys.getNewConditionsToCover())) {
-        return counter.getNewConditions(period);
+        return counter.getNewConditions();
       }
       if (metric.getKey().equals(outputMetricKeys.getNewUncoveredConditions())) {
-        return counter.getNewConditions(period) - counter.getNewCoveredConditions(period);
+        return counter.getNewConditions() - counter.getNewCoveredConditions();
       }
       throw new IllegalArgumentException("Unsupported metric " + metric.getKey());
     }
@@ -235,10 +227,10 @@ public class NewCoverageMeasuresStep implements ComputationStep {
   }
 
   public static final class NewCoverageCounter implements org.sonar.server.computation.task.projectanalysis.formula.Counter<NewCoverageCounter> {
-    private final IntVariationValue.Array newLines = IntVariationValue.newArray();
-    private final IntVariationValue.Array newCoveredLines = IntVariationValue.newArray();
-    private final IntVariationValue.Array newConditions = IntVariationValue.newArray();
-    private final IntVariationValue.Array newCoveredConditions = IntVariationValue.newArray();
+    private final IntVariationValue newLines = new IntVariationValue();
+    private final IntVariationValue newCoveredLines = new IntVariationValue();
+    private final IntVariationValue newConditions = new IntVariationValue();
+    private final IntVariationValue newCoveredConditions = new IntVariationValue();
     private final ScmInfoRepository scmInfoRepository;
     private final NewCoverageInputMetricKeys metricKeys;
 
@@ -249,27 +241,25 @@ public class NewCoverageMeasuresStep implements ComputationStep {
 
     @Override
     public void aggregate(NewCoverageCounter counter) {
-      newLines.incrementAll(counter.newLines);
-      newCoveredLines.incrementAll(counter.newCoveredLines);
-      newConditions.incrementAll(counter.newConditions);
-      newCoveredConditions.incrementAll(counter.newCoveredConditions);
+      newLines.increment(counter.newLines);
+      newCoveredLines.increment(counter.newCoveredLines);
+      newConditions.increment(counter.newConditions);
+      newCoveredConditions.increment(counter.newCoveredConditions);
     }
 
     @Override
     public void initialize(CounterInitializationContext context) {
       Component fileComponent = context.getLeaf();
       Optional<ScmInfo> scmInfoOptional = scmInfoRepository.getScmInfo(fileComponent);
-      if (!scmInfoOptional.isPresent()) {
+      if (!scmInfoOptional.isPresent() || !context.hasPeriod()) {
         return;
       }
       ScmInfo componentScm = scmInfoOptional.get();
 
-      context.getPeriods().forEach(period -> {
-        newLines.increment(period, 0);
-        newCoveredLines.increment(period, 0);
-        newConditions.increment(period, 0);
-        newCoveredConditions.increment(period, 0);
-      });
+      newLines.increment(0);
+      newCoveredLines.increment(0);
+      newConditions.increment(0);
+      newCoveredConditions.increment(0);
 
       Optional<Measure> hitsByLineMeasure = context.getMeasure(metricKeys.getCoverageLineHitsData());
       Map<Integer, Integer> hitsByLine = parseCountByLine(hitsByLineMeasure);
@@ -282,7 +272,7 @@ public class NewCoverageMeasuresStep implements ComputationStep {
         int conditions = (Integer) ObjectUtils.defaultIfNull(conditionsByLine.get(lineId), 0);
         int coveredConditions = (Integer) ObjectUtils.defaultIfNull(coveredConditionsByLine.get(lineId), 0);
         long date = componentScm.getChangesetForLine(lineId).getDate();
-        analyze(context.getPeriods(), date, hits, conditions, coveredConditions);
+        analyze(context.getPeriod(), date, hits, conditions, coveredConditions);
       }
     }
 
@@ -293,15 +283,13 @@ public class NewCoverageMeasuresStep implements ComputationStep {
       return Collections.emptyMap();
     }
 
-    public void analyze(List<Period> periods, @Nullable Long lineDate, int hits, int conditions, int coveredConditions) {
+    void analyze(Period period, @Nullable Long lineDate, int hits, int conditions, int coveredConditions) {
       if (lineDate == null) {
         return;
       }
-      for (Period period : periods) {
-        if (isLineInPeriod(lineDate, period)) {
-          incrementLines(period, hits);
-          incrementConditions(period, conditions, coveredConditions);
-        }
+      if (isLineInPeriod(lineDate, period)) {
+        incrementLines(hits);
+        incrementConditions(conditions, coveredConditions);
       }
     }
 
@@ -312,38 +300,38 @@ public class NewCoverageMeasuresStep implements ComputationStep {
       return lineDate > period.getSnapshotDate();
     }
 
-    private void incrementLines(Period period, int hits) {
-      newLines.increment(period, 1);
+    private void incrementLines(int hits) {
+      newLines.increment(1);
       if (hits > 0) {
-        newCoveredLines.increment(period, 1);
+        newCoveredLines.increment(1);
       }
     }
 
-    private void incrementConditions(Period period, int conditions, int coveredConditions) {
-      newConditions.increment(period, conditions);
+    private void incrementConditions(int conditions, int coveredConditions) {
+      newConditions.increment(conditions);
       if (conditions > 0) {
-        newCoveredConditions.increment(period, coveredConditions);
+        newCoveredConditions.increment(coveredConditions);
       }
     }
 
-    public boolean hasNewCode(Period period) {
-      return newLines.get(period).isSet();
+    boolean hasNewCode() {
+      return newLines.isSet();
     }
 
-    public int getNewLines(Period period) {
-      return newLines.get(period).getValue();
+    int getNewLines() {
+      return newLines.getValue();
     }
 
-    public int getNewCoveredLines(Period period) {
-      return newCoveredLines.get(period).getValue();
+    int getNewCoveredLines() {
+      return newCoveredLines.getValue();
     }
 
-    public int getNewConditions(Period period) {
-      return newConditions.get(period).getValue();
+    int getNewConditions() {
+      return newConditions.getValue();
     }
 
-    public int getNewCoveredConditions(Period period) {
-      return newCoveredConditions.get(period).getValue();
+    int getNewCoveredConditions() {
+      return newCoveredConditions.getValue();
     }
   }
 
index 2116ec61e0573228fbd07b15f24a73f52db9f893..d8cdd2dc1cf64ce4940692a6f4806ab6828234ea 100644 (file)
@@ -30,21 +30,19 @@ import org.junit.rules.ExternalResource;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
 import org.sonar.server.computation.task.projectanalysis.formula.CounterInitializationContext;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
 import org.sonar.server.computation.task.projectanalysis.period.Period;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getLongMeasureValue;
-import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getLongVariation;
 import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getMeasureVariations;
 import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
 
 public class CoverageUtilsTest {
 
   private static final String SOME_METRIC_KEY = "some key";
-  public static final MeasureVariations DEFAULT_VARIATIONS = new MeasureVariations(0d, 0d, 0d, 0d, 0d);
+  public static final double DEFAULT_VARIATION = 0d;
 
   @Rule
   public CounterInitializationContextRule fileAggregateContext = new CounterInitializationContextRule();
@@ -94,37 +92,21 @@ public class CoverageUtilsTest {
 
   @Test
   public void getMeasureVariations_returns_0_in_all_MeasureVariations_if_there_is_no_measure() {
-    assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(DEFAULT_VARIATIONS);
+    assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(DEFAULT_VARIATION);
   }
 
   @Test
   public void getMeasureVariations_returns_0_in_all_MeasureVariations_if_there_is_measure_has_no_variations() {
     fileAggregateContext.put(SOME_METRIC_KEY, newMeasureBuilder().createNoValue());
 
-    assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(DEFAULT_VARIATIONS);
+    assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(DEFAULT_VARIATION);
   }
 
   @Test
   public void getMeasureVariations_returns_MeasureVariations_of_measure_when_it_has_one() {
-    MeasureVariations measureVariations = new MeasureVariations(null, 5d, null, null);
-    fileAggregateContext.put(SOME_METRIC_KEY, newMeasureBuilder().setVariations(measureVariations).createNoValue());
+    fileAggregateContext.put(SOME_METRIC_KEY, newMeasureBuilder().setVariation(5d).createNoValue());
 
-    assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isSameAs(measureVariations);
-  }
-
-  @Test
-  public void getLongVariation_returns_0_if_MeasureVariation_has_none_for_the_specified_period() {
-    MeasureVariations variations = new MeasureVariations(null, 2d, null, null, 5d);
-
-    assertThat(getLongVariation(variations, createPeriod(1))).isEqualTo(0L);
-    assertThat(getLongVariation(variations, createPeriod(2))).isEqualTo(2L);
-    assertThat(getLongVariation(variations, createPeriod(3))).isEqualTo(0L);
-    assertThat(getLongVariation(variations, createPeriod(4))).isEqualTo(0L);
-    assertThat(getLongVariation(variations, createPeriod(5))).isEqualTo(5L);
-  }
-
-  private Period createPeriod(int periodIndex) {
-    return new Period(periodIndex, "mode" + periodIndex, null, 963L + periodIndex, String.valueOf(9865L + periodIndex));
+    assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(5d);
   }
 
   private static class CounterInitializationContextRule extends ExternalResource implements CounterInitializationContext {
index e2e75ae45c9f43f1831379be54ee0206c42f9e80..67d24968b062f35c0884162adf6094de58b48c82 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.computation.task.projectanalysis.step;
 
-import javax.annotation.Nullable;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -32,7 +31,6 @@ import org.sonar.server.computation.task.projectanalysis.formula.coverage.LinesA
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepoEntry;
 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
 import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule;
 import org.sonar.server.computation.task.projectanalysis.period.Period;
 import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolderRule;
@@ -57,7 +55,6 @@ import static org.sonar.server.computation.task.projectanalysis.component.Report
 import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
 import static org.sonar.server.computation.task.projectanalysis.measure.MeasureRepoEntry.entryOf;
 import static org.sonar.server.computation.task.projectanalysis.measure.MeasureRepoEntry.toEntries;
-import static org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations.newMeasureVariationsBuilder;
 
 public class ReportNewCoverageMeasuresStepTest {
 
@@ -117,9 +114,7 @@ public class ReportNewCoverageMeasuresStepTest {
 
   @Before
   public void setUp() {
-    periodsHolder.setPeriods(
-      new Period(2, "mode_p_1", null, parseDate("2009-12-25").getTime(), "u1"),
-      new Period(5, "mode_p_5", null, parseDate("2011-02-18").getTime(), "u2"));
+    periodsHolder.setPeriod(new Period("mode_p_1", null, parseDate("2009-12-25").getTime(), "u1"));
   }
 
   @Test
@@ -224,10 +219,10 @@ public class ReportNewCoverageMeasuresStepTest {
     underTest.execute();
 
     assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_COMPONENT.getReportAttributes().getRef()))).contains(
-      entryOf(newLinesToCover, createMeasure(2d, 0d)),
-      entryOf(newUncoveredLines, createMeasure(1d, 0d)),
-      entryOf(newConditionsToCover, createMeasure(0d, 0d)),
-      entryOf(newUncoveredConditions, createMeasure(0d, 0d)));
+      entryOf(newLinesToCover, createMeasure(2d)),
+      entryOf(newUncoveredLines, createMeasure(1d)),
+      entryOf(newConditionsToCover, createMeasure(0d)),
+      entryOf(newUncoveredConditions, createMeasure(0d)));
   }
 
   @Test
@@ -266,36 +261,36 @@ public class ReportNewCoverageMeasuresStepTest {
 
     // files
     assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_1_REF))).contains(
-      entryOf(metricKeys.newLinesToCover, createMeasure(5d, 3d)),
-      entryOf(metricKeys.newUncoveredLines, createMeasure(3d, 2d)),
-      entryOf(metricKeys.newConditionsToCover, createMeasure(7d, 3d)),
-      entryOf(metricKeys.newUncoveredConditions, createMeasure(4d, 1d)));
+      entryOf(metricKeys.newLinesToCover, createMeasure(5d)),
+      entryOf(metricKeys.newUncoveredLines, createMeasure(3d)),
+      entryOf(metricKeys.newConditionsToCover, createMeasure(7d)),
+      entryOf(metricKeys.newUncoveredConditions, createMeasure(4d)));
     assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_2_REF))).contains(
-      entryOf(metricKeys.newLinesToCover, createMeasure(5d, 3d)),
-      entryOf(metricKeys.newUncoveredLines, createMeasure(4d, 2d)),
-      entryOf(metricKeys.newConditionsToCover, createMeasure(27d, 13d)),
-      entryOf(metricKeys.newUncoveredConditions, createMeasure(14d, 6d)));
+      entryOf(metricKeys.newLinesToCover, createMeasure(5d)),
+      entryOf(metricKeys.newUncoveredLines, createMeasure(4d)),
+      entryOf(metricKeys.newConditionsToCover, createMeasure(27d)),
+      entryOf(metricKeys.newUncoveredConditions, createMeasure(14d)));
     assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_3_REF))).contains(
-      entryOf(metricKeys.newLinesToCover, createMeasure(5d, 3d)),
-      entryOf(metricKeys.newUncoveredLines, createMeasure(2d, 1d)),
-      entryOf(metricKeys.newConditionsToCover, createMeasure(17d, 13d)),
-      entryOf(metricKeys.newUncoveredConditions, createMeasure(9d, 6d)));
+      entryOf(metricKeys.newLinesToCover, createMeasure(5d)),
+      entryOf(metricKeys.newUncoveredLines, createMeasure(2d)),
+      entryOf(metricKeys.newConditionsToCover, createMeasure(17d)),
+      entryOf(metricKeys.newUncoveredConditions, createMeasure(9d)));
     // directories
     assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_1_REF))).contains(
-      entryOf(metricKeys.newLinesToCover, createMeasure(5d, 3d)),
-      entryOf(metricKeys.newUncoveredLines, createMeasure(3d, 2d)),
-      entryOf(metricKeys.newConditionsToCover, createMeasure(7d, 3d)),
-      entryOf(metricKeys.newUncoveredConditions, createMeasure(4d, 1d)));
+      entryOf(metricKeys.newLinesToCover, createMeasure(5d)),
+      entryOf(metricKeys.newUncoveredLines, createMeasure(3d)),
+      entryOf(metricKeys.newConditionsToCover, createMeasure(7d)),
+      entryOf(metricKeys.newUncoveredConditions, createMeasure(4d)));
     assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_2_REF))).contains(
-      entryOf(metricKeys.newLinesToCover, createMeasure(10d, 6d)),
-      entryOf(metricKeys.newUncoveredLines, createMeasure(6d, 3d)),
-      entryOf(metricKeys.newConditionsToCover, createMeasure(44d, 26d)),
-      entryOf(metricKeys.newUncoveredConditions, createMeasure(23d, 12d)));
+      entryOf(metricKeys.newLinesToCover, createMeasure(10d)),
+      entryOf(metricKeys.newUncoveredLines, createMeasure(6d)),
+      entryOf(metricKeys.newConditionsToCover, createMeasure(44d)),
+      entryOf(metricKeys.newUncoveredConditions, createMeasure(23d)));
     // submodule
-    MeasureRepoEntry[] repoEntriesFromSubModuleUp = {entryOf(metricKeys.newLinesToCover, createMeasure(15d, 9d)),
-      entryOf(metricKeys.newUncoveredLines, createMeasure(9d, 5d)),
-      entryOf(metricKeys.newConditionsToCover, createMeasure(51d, 29d)),
-      entryOf(metricKeys.newUncoveredConditions, createMeasure(27d, 13d))};
+    MeasureRepoEntry[] repoEntriesFromSubModuleUp = {entryOf(metricKeys.newLinesToCover, createMeasure(15d)),
+      entryOf(metricKeys.newUncoveredLines, createMeasure(9d)),
+      entryOf(metricKeys.newConditionsToCover, createMeasure(51d)),
+      entryOf(metricKeys.newUncoveredConditions, createMeasure(27d))};
     assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).contains(repoEntriesFromSubModuleUp);
     // module
     assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).contains(repoEntriesFromSubModuleUp);
@@ -318,42 +313,42 @@ public class ReportNewCoverageMeasuresStepTest {
   private void verify_aggregates_variations(LinesAndConditionsWithUncoveredMetricKeys metricKeys, String codeCoverageKey, String lineCoverageKey, String branchCoverageKey) {
     treeRootHolder.setRoot(MULTIPLE_FILES_TREE);
     measureRepository
-      .addRawMeasure(FILE_1_REF, metricKeys.getLines(), createMeasure(3000d, 2000d))
-      .addRawMeasure(FILE_1_REF, metricKeys.getConditions(), createMeasure(300d, 400d))
-      .addRawMeasure(FILE_1_REF, metricKeys.getUncoveredLines(), createMeasure(30d, 200d))
-      .addRawMeasure(FILE_1_REF, metricKeys.getUncoveredConditions(), createMeasure(9d, 16d))
+      .addRawMeasure(FILE_1_REF, metricKeys.getLines(), createMeasure(3000d))
+      .addRawMeasure(FILE_1_REF, metricKeys.getConditions(), createMeasure(300d))
+      .addRawMeasure(FILE_1_REF, metricKeys.getUncoveredLines(), createMeasure(30d))
+      .addRawMeasure(FILE_1_REF, metricKeys.getUncoveredConditions(), createMeasure(9d))
 
-      .addRawMeasure(FILE_2_REF, metricKeys.getLines(), createMeasure(2000d, 3000d))
-      .addRawMeasure(FILE_2_REF, metricKeys.getConditions(), createMeasure(400d, 300d))
-      .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredLines(), createMeasure(200d, 30d))
-      .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredConditions(), createMeasure(16d, 9d));
+      .addRawMeasure(FILE_2_REF, metricKeys.getLines(), createMeasure(2000d))
+      .addRawMeasure(FILE_2_REF, metricKeys.getConditions(), createMeasure(400d))
+      .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredLines(), createMeasure(200d))
+      .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredConditions(), createMeasure(16d));
 
     underTest.execute();
 
     assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_1_REF))).containsOnly(
-      entryOf(codeCoverageKey, createMeasure(98.8d, 91d)),
-      entryOf(lineCoverageKey, createMeasure(99d, 90d)),
-      entryOf(branchCoverageKey, createMeasure(97d, 96d)));
+      entryOf(codeCoverageKey, createMeasure(98.8d)),
+      entryOf(lineCoverageKey, createMeasure(99d)),
+      entryOf(branchCoverageKey, createMeasure(97d)));
     assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_2_REF))).containsOnly(
-      entryOf(codeCoverageKey, createMeasure(91d, 98.8d)),
-      entryOf(lineCoverageKey, createMeasure(90d, 99d)),
-      entryOf(branchCoverageKey, createMeasure(96d, 97d)));
+      entryOf(codeCoverageKey, createMeasure(91d)),
+      entryOf(lineCoverageKey, createMeasure(90d)),
+      entryOf(branchCoverageKey, createMeasure(96d)));
     assertThat(measureRepository.getAddedRawMeasures(FILE_3_REF)).isEmpty();
 
     assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_1_REF))).containsOnly(
-      entryOf(codeCoverageKey, createMeasure(98.8d, 91d)),
-      entryOf(lineCoverageKey, createMeasure(99d, 90d)),
-      entryOf(branchCoverageKey, createMeasure(97d, 96d)));
+      entryOf(codeCoverageKey, createMeasure(98.8d)),
+      entryOf(lineCoverageKey, createMeasure(99d)),
+      entryOf(branchCoverageKey, createMeasure(97d)));
 
     assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_2_REF))).containsOnly(
-      entryOf(codeCoverageKey, createMeasure(91d, 98.8d)),
-      entryOf(lineCoverageKey, createMeasure(90d, 99d)),
-      entryOf(branchCoverageKey, createMeasure(96d, 97d)));
+      entryOf(codeCoverageKey, createMeasure(91d)),
+      entryOf(lineCoverageKey, createMeasure(90d)),
+      entryOf(branchCoverageKey, createMeasure(96d)));
 
     MeasureRepoEntry[] modulesAndProjectEntries = {
-      entryOf(codeCoverageKey, createMeasure(95.5d, 95.5d)),
-      entryOf(lineCoverageKey, createMeasure(95.4d, 95.4d)),
-      entryOf(branchCoverageKey, createMeasure(96.4d, 96.4d))
+      entryOf(codeCoverageKey, createMeasure(95.5d)),
+      entryOf(lineCoverageKey, createMeasure(95.4d)),
+      entryOf(branchCoverageKey, createMeasure(96.4d))
     };
 
     assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).containsOnly(modulesAndProjectEntries);
@@ -363,10 +358,10 @@ public class ReportNewCoverageMeasuresStepTest {
 
   private void verify_only_zero_measures_on_new_lines_and_conditions_measures(Component component) {
     assertThat(toEntries(measureRepository.getAddedRawMeasures(component.getReportAttributes().getRef()))).containsOnly(
-      entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(0d, 0d)),
-      entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(0d, 0d)),
-      entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(0d, 0d)),
-      entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(0d, 0d)));
+      entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(0d)),
+      entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(0d)),
+      entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(0d)),
+      entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(0d)));
   }
 
   private void defineChangeSetsAndMeasures(int componentRef, MetricKeys metricKeys, MeasureValues line4, MeasureValues line6) {
@@ -425,22 +420,15 @@ public class ReportNewCoverageMeasuresStepTest {
     underTest.execute();
 
     assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_COMPONENT.getReportAttributes().getRef()))).contains(
-      entryOf(metricKeys.newLinesToCover, createMeasure(5d, 3d)),
-      entryOf(metricKeys.newUncoveredLines, createMeasure(3d, 2d)),
-      entryOf(metricKeys.newConditionsToCover, createMeasure(7d, 3d)),
-      entryOf(metricKeys.newUncoveredConditions, createMeasure(4d, 1d)));
+      entryOf(metricKeys.newLinesToCover, createMeasure(5d)),
+      entryOf(metricKeys.newUncoveredLines, createMeasure(3d)),
+      entryOf(metricKeys.newConditionsToCover, createMeasure(7d)),
+      entryOf(metricKeys.newUncoveredConditions, createMeasure(4d)));
   }
 
-  private static Measure createMeasure(@Nullable Double variationPeriod2, @Nullable Double variationPeriod5) {
-    MeasureVariations.Builder variationBuilder = newMeasureVariationsBuilder();
-    if (variationPeriod2 != null) {
-      variationBuilder.setVariation(new Period(2, "", null, 1L, "u2"), variationPeriod2);
-    }
-    if (variationPeriod5 != null) {
-      variationBuilder.setVariation(new Period(5, "", null, 1L, "u2"), variationPeriod5);
-    }
+  private static Measure createMeasure(Double expectedVariation) {
     return newMeasureBuilder()
-      .setVariations(variationBuilder.build())
+      .setVariation(expectedVariation)
       .createNoValue();
   }
 
index 0b6fb13cabae2977612aff4e39d66ccb57dc06ec..83aeae2c191c96e5c390a716810f5ea693384e28 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.computation.task.projectanalysis.step;
 
-import javax.annotation.Nullable;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -29,7 +28,6 @@ import org.sonar.server.computation.task.projectanalysis.component.ViewsComponen
 import org.sonar.server.computation.task.projectanalysis.formula.coverage.LinesAndConditionsWithUncoveredMetricKeys;
 import org.sonar.server.computation.task.projectanalysis.measure.Measure;
 import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
 import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule;
 import org.sonar.server.computation.task.projectanalysis.period.Period;
 import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolderRule;
@@ -44,7 +42,6 @@ import static org.sonar.server.computation.task.projectanalysis.component.ViewsC
 import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
 import static org.sonar.server.computation.task.projectanalysis.measure.MeasureRepoEntry.entryOf;
 import static org.sonar.server.computation.task.projectanalysis.measure.MeasureRepoEntry.toEntries;
-import static org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations.newMeasureVariationsBuilder;
 
 public class ViewsNewCoverageMeasuresStepTest {
 
@@ -73,7 +70,6 @@ public class ViewsNewCoverageMeasuresStepTest {
           builder(PROJECT_VIEW, PROJECT_VIEW_4_REF).build())
         .build())
     .build();
-  private static final Double NO_PERIOD_4_OR_5_IN_VIEWS = null;
 
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@@ -99,9 +95,7 @@ public class ViewsNewCoverageMeasuresStepTest {
 
   @Before
   public void setUp() {
-    periodsHolder.setPeriods(
-      new Period(2, "mode_p_1", null, parseDate("2009-12-25").getTime(), "U1"),
-      new Period(5, "mode_p_5", null, parseDate("2011-02-18").getTime(), "U2"));
+    periodsHolder.setPeriod(new Period("mode_p_1", null, parseDate("2009-12-25").getTime(), "U1"));
   }
 
   @Test
@@ -115,33 +109,33 @@ public class ViewsNewCoverageMeasuresStepTest {
 
     treeRootHolder.setRoot(VIEWS_TREE);
     // PROJECT_VIEW_1_REF has no measure
-    measureRepository.addRawMeasure(PROJECT_VIEW_2_REF, newLinesToCover, createMeasure(1d, 2d));
-    measureRepository.addRawMeasure(PROJECT_VIEW_2_REF, newUncoveredLines, createMeasure(10d, 20d));
-    measureRepository.addRawMeasure(PROJECT_VIEW_2_REF, newConditionsToCover, createMeasure(4d, 5d));
-    measureRepository.addRawMeasure(PROJECT_VIEW_2_REF, newUncoveredConditions, createMeasure(40d, 50d));
-    measureRepository.addRawMeasure(PROJECT_VIEW_3_REF, newLinesToCover, createMeasure(11d, 12d));
-    measureRepository.addRawMeasure(PROJECT_VIEW_3_REF, newUncoveredLines, createMeasure(20d, 30d));
-    measureRepository.addRawMeasure(PROJECT_VIEW_3_REF, newConditionsToCover, createMeasure(14d, 15d));
-    measureRepository.addRawMeasure(PROJECT_VIEW_3_REF, newUncoveredConditions, createMeasure(50d, 60d));
-    measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newLinesToCover, createMeasure(21d, 22d));
-    measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newUncoveredLines, createMeasure(30d, 40d));
-    measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newConditionsToCover, createMeasure(24d, 25d));
-    measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newUncoveredConditions, createMeasure(60d, 70d));
+    measureRepository.addRawMeasure(PROJECT_VIEW_2_REF, newLinesToCover, createMeasure(1d));
+    measureRepository.addRawMeasure(PROJECT_VIEW_2_REF, newUncoveredLines, createMeasure(10d));
+    measureRepository.addRawMeasure(PROJECT_VIEW_2_REF, newConditionsToCover, createMeasure(4d));
+    measureRepository.addRawMeasure(PROJECT_VIEW_2_REF, newUncoveredConditions, createMeasure(40d));
+    measureRepository.addRawMeasure(PROJECT_VIEW_3_REF, newLinesToCover, createMeasure(11d));
+    measureRepository.addRawMeasure(PROJECT_VIEW_3_REF, newUncoveredLines, createMeasure(20d));
+    measureRepository.addRawMeasure(PROJECT_VIEW_3_REF, newConditionsToCover, createMeasure(14d));
+    measureRepository.addRawMeasure(PROJECT_VIEW_3_REF, newUncoveredConditions, createMeasure(50d));
+    measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newLinesToCover, createMeasure(21d));
+    measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newUncoveredLines, createMeasure(30d));
+    measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newConditionsToCover, createMeasure(24d));
+    measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newUncoveredConditions, createMeasure(60d));
 
     underTest.execute();
 
     assertNoAddedRawMeasureOnProjectViews();
     assertNoAddedRawMeasures(SUB_SUBVIEW_1_REF);
     assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_SUBVIEW_2_REF))).contains(
-      entryOf(metricKeys.newLinesToCover, createMeasure(12d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(metricKeys.newUncoveredLines, createMeasure(30d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(metricKeys.newConditionsToCover, createMeasure(18d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(metricKeys.newUncoveredConditions, createMeasure(90d, NO_PERIOD_4_OR_5_IN_VIEWS)));
+      entryOf(metricKeys.newLinesToCover, createMeasure(12d)),
+      entryOf(metricKeys.newUncoveredLines, createMeasure(30d)),
+      entryOf(metricKeys.newConditionsToCover, createMeasure(18d)),
+      entryOf(metricKeys.newUncoveredConditions, createMeasure(90d)));
     assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).contains(
-      entryOf(metricKeys.newLinesToCover, createMeasure(33d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(metricKeys.newUncoveredLines, createMeasure(60d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(metricKeys.newConditionsToCover, createMeasure(42d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(metricKeys.newUncoveredConditions, createMeasure(150d, NO_PERIOD_4_OR_5_IN_VIEWS)));
+      entryOf(metricKeys.newLinesToCover, createMeasure(33d)),
+      entryOf(metricKeys.newUncoveredLines, createMeasure(60d)),
+      entryOf(metricKeys.newConditionsToCover, createMeasure(42d)),
+      entryOf(metricKeys.newUncoveredConditions, createMeasure(150d)));
   }
 
   @Test
@@ -159,42 +153,42 @@ public class ViewsNewCoverageMeasuresStepTest {
   private void verify_aggregates_variations(LinesAndConditionsWithUncoveredMetricKeys metricKeys, String codeCoverageKey, String lineCoverageKey, String branchCoverageKey) {
     treeRootHolder.setRoot(VIEWS_TREE);
     measureRepository
-      .addRawMeasure(PROJECT_VIEW_1_REF, metricKeys.getLines(), createMeasure(3000d, 2000d))
-      .addRawMeasure(PROJECT_VIEW_1_REF, metricKeys.getConditions(), createMeasure(300d, 400d))
-      .addRawMeasure(PROJECT_VIEW_1_REF, metricKeys.getUncoveredLines(), createMeasure(30d, 200d))
-      .addRawMeasure(PROJECT_VIEW_1_REF, metricKeys.getUncoveredConditions(), createMeasure(9d, 16d))
+      .addRawMeasure(PROJECT_VIEW_1_REF, metricKeys.getLines(), createMeasure(3000d))
+      .addRawMeasure(PROJECT_VIEW_1_REF, metricKeys.getConditions(), createMeasure(300d))
+      .addRawMeasure(PROJECT_VIEW_1_REF, metricKeys.getUncoveredLines(), createMeasure(30d))
+      .addRawMeasure(PROJECT_VIEW_1_REF, metricKeys.getUncoveredConditions(), createMeasure(9d))
       // PROJECT_VIEW_2_REF
-      .addRawMeasure(PROJECT_VIEW_2_REF, metricKeys.getLines(), createMeasure(2000d, 3000d))
-      .addRawMeasure(PROJECT_VIEW_2_REF, metricKeys.getConditions(), createMeasure(400d, 300d))
-      .addRawMeasure(PROJECT_VIEW_2_REF, metricKeys.getUncoveredLines(), createMeasure(200d, 30d))
-      .addRawMeasure(PROJECT_VIEW_2_REF, metricKeys.getUncoveredConditions(), createMeasure(16d, 9d))
+      .addRawMeasure(PROJECT_VIEW_2_REF, metricKeys.getLines(), createMeasure(2000d))
+      .addRawMeasure(PROJECT_VIEW_2_REF, metricKeys.getConditions(), createMeasure(400d))
+      .addRawMeasure(PROJECT_VIEW_2_REF, metricKeys.getUncoveredLines(), createMeasure(200d))
+      .addRawMeasure(PROJECT_VIEW_2_REF, metricKeys.getUncoveredConditions(), createMeasure(16d))
       // PROJECT_VIEW_3_REF has no measure
       // PROJECT_VIEW_4_REF
-      .addRawMeasure(PROJECT_VIEW_4_REF, metricKeys.getLines(), createMeasure(1000d, 2000d))
-      .addRawMeasure(PROJECT_VIEW_4_REF, metricKeys.getConditions(), createMeasure(300d, 200d))
-      .addRawMeasure(PROJECT_VIEW_4_REF, metricKeys.getUncoveredLines(), createMeasure(100d, 20d))
-      .addRawMeasure(PROJECT_VIEW_4_REF, metricKeys.getUncoveredConditions(), createMeasure(6d, 9d));
+      .addRawMeasure(PROJECT_VIEW_4_REF, metricKeys.getLines(), createMeasure(1000d))
+      .addRawMeasure(PROJECT_VIEW_4_REF, metricKeys.getConditions(), createMeasure(300d))
+      .addRawMeasure(PROJECT_VIEW_4_REF, metricKeys.getUncoveredLines(), createMeasure(100d))
+      .addRawMeasure(PROJECT_VIEW_4_REF, metricKeys.getUncoveredConditions(), createMeasure(6d));
 
     underTest.execute();
 
     assertNoAddedRawMeasureOnProjectViews();
 
     assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_SUBVIEW_1_REF))).contains(
-      entryOf(codeCoverageKey, createMeasure(98.8d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(lineCoverageKey, createMeasure(99d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(branchCoverageKey, createMeasure(97d, NO_PERIOD_4_OR_5_IN_VIEWS)));
+      entryOf(codeCoverageKey, createMeasure(98.8d)),
+      entryOf(lineCoverageKey, createMeasure(99d)),
+      entryOf(branchCoverageKey, createMeasure(97d)));
     assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_SUBVIEW_2_REF))).contains(
-      entryOf(codeCoverageKey, createMeasure(91d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(lineCoverageKey, createMeasure(90d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(branchCoverageKey, createMeasure(96d, NO_PERIOD_4_OR_5_IN_VIEWS)));
+      entryOf(codeCoverageKey, createMeasure(91d)),
+      entryOf(lineCoverageKey, createMeasure(90d)),
+      entryOf(branchCoverageKey, createMeasure(96d)));
     assertThat(toEntries(measureRepository.getAddedRawMeasures(SUBVIEW_REF))).contains(
-      entryOf(codeCoverageKey, createMeasure(94.8d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(lineCoverageKey, createMeasure(94.5d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(branchCoverageKey, createMeasure(96.9d, NO_PERIOD_4_OR_5_IN_VIEWS)));
+      entryOf(codeCoverageKey, createMeasure(94.8d)),
+      entryOf(lineCoverageKey, createMeasure(94.5d)),
+      entryOf(branchCoverageKey, createMeasure(96.9d)));
     assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).contains(
-      entryOf(codeCoverageKey, createMeasure(94.8d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(lineCoverageKey, createMeasure(94.5d, NO_PERIOD_4_OR_5_IN_VIEWS)),
-      entryOf(branchCoverageKey, createMeasure(96.9d, NO_PERIOD_4_OR_5_IN_VIEWS)));
+      entryOf(codeCoverageKey, createMeasure(94.8d)),
+      entryOf(lineCoverageKey, createMeasure(94.5d)),
+      entryOf(branchCoverageKey, createMeasure(96.9d)));
   }
 
   private static final class MetricKeys {
@@ -211,16 +205,9 @@ public class ViewsNewCoverageMeasuresStepTest {
     }
   }
 
-  private static Measure createMeasure(@Nullable Double variationPeriod2, @Nullable Double variationPeriod5) {
-    MeasureVariations.Builder variationBuilder = newMeasureVariationsBuilder();
-    if (variationPeriod2 != null) {
-      variationBuilder.setVariation(new Period(2, "", null, 1L, "U2"), variationPeriod2);
-    }
-    if (variationPeriod5 != null) {
-      variationBuilder.setVariation(new Period(5, "", null, 1L, "U2"), variationPeriod5);
-    }
+  private static Measure createMeasure(Double expectedVariation) {
     return newMeasureBuilder()
-      .setVariations(variationBuilder.build())
+      .setVariation(expectedVariation)
       .createNoValue();
   }