]> source.dussan.org Git - sonarqube.git/commitdiff
rename Counter#aggregate(LeafContext) to initialize(InitContext)
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 24 Aug 2015 16:17:36 +0000 (18:17 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Sat, 29 Aug 2015 13:58:41 +0000 (15:58 +0200)
this emphasis that this is really an initialization method and that it can be called on FILE or PROJECT_VIEW component but also, in the futur on a SUBVIEW (case of processing of partial trees of Views Components)

29 files changed:
server/sonar-server/src/main/java/org/sonar/server/computation/formula/AverageFormula.java
server/sonar-server/src/main/java/org/sonar/server/computation/formula/Counter.java
server/sonar-server/src/main/java/org/sonar/server/computation/formula/CounterInitializationContext.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/formula/DistributionFormula.java
server/sonar-server/src/main/java/org/sonar/server/computation/formula/FormulaExecutorComponentVisitor.java
server/sonar-server/src/main/java/org/sonar/server/computation/formula/LeafAggregateContext.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/computation/formula/counter/IntSumCounter.java
server/sonar-server/src/main/java/org/sonar/server/computation/formula/counter/LongSumCounter.java
server/sonar-server/src/main/java/org/sonar/server/computation/formula/coverage/CoverageUtils.java
server/sonar-server/src/main/java/org/sonar/server/computation/formula/coverage/ElementsAndCoveredElementsCounter.java
server/sonar-server/src/main/java/org/sonar/server/computation/formula/coverage/ElementsAndCoveredElementsVariationCounter.java
server/sonar-server/src/main/java/org/sonar/server/computation/formula/coverage/LinesAndConditionsWithUncoveredCounter.java
server/sonar-server/src/main/java/org/sonar/server/computation/formula/coverage/LinesAndConditionsWithUncoveredVariationCounter.java
server/sonar-server/src/main/java/org/sonar/server/computation/formula/coverage/SingleWithUncoveredCounter.java
server/sonar-server/src/main/java/org/sonar/server/computation/formula/coverage/SingleWithUncoveredVariationCounter.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/CommentMeasuresStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/DuplicationMeasuresStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/LanguageDistributionMeasuresStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/NewCoverageMeasuresStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/UnitTestMeasuresStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/formula/AverageFormulaTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/formula/DistributionFormulaTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/formula/IntSumFormulaTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/formula/LongSumFormulaTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/formula/ReportFormulaExecutorComponentVisitorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/formula/ViewsFormulaExecutorComponentVisitorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/formula/counter/IntSumCounterTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/formula/counter/LongSumCounterTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/formula/coverage/CoverageUtilsTest.java

index 1d8a4fa042b8e908b22e935d6d8afdd9d95d6d6d..1506751c82e8876fe6212a33242870d2bb00411c 100644 (file)
@@ -123,7 +123,7 @@ public class AverageFormula implements Formula<AverageFormula.AverageCounter> {
     }
 
     @Override
-    public void aggregate(LeafAggregateContext context) {
+    public void initialize(CounterInitializationContext context) {
       Optional<Double> mainValueOptional = getDoubleValue(context.getMeasure(mainMetric));
       if (!mainValueOptional.isPresent() && fallbackMetric != null) {
         mainValueOptional = getDoubleValue(context.getMeasure(fallbackMetric));
index 3c5df5503cb14cce37bc1d640e7c0cce0fabff13..35a9526eafddc36a823c4d6aa8001b928c318e5d 100644 (file)
@@ -28,14 +28,15 @@ import static org.sonar.server.computation.component.Component.Type;
 public interface Counter<T extends Counter<T>> {
 
   /**
-   * This method is used on not leaf levels, to aggregate the value of counter from a child
+   * This method is used on not leaf levels, to aggregate the value of the specified counter of a child to the counter
+   * of the current component.
    */
   void aggregate(T counter);
 
   /**
-   * This method is called on {@link Type#FILE} or {@link Type#PROJECT_VIEW} levels (aka. leaf levels), in order to
-   * populate the counter with one or more leaf measures.
+   * This method is called on leaves of the Component tree (usually a {@link Type#FILE} or a {@link Type#PROJECT_VIEW}
+   * but can also be a {@link Type#SUBVIEW} or {@link Type#VIEW}) to initialize the counter.
    */
-  void aggregate(LeafAggregateContext context);
+  void initialize(CounterInitializationContext context);
 
 }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/formula/CounterInitializationContext.java b/server/sonar-server/src/main/java/org/sonar/server/computation/formula/CounterInitializationContext.java
new file mode 100644 (file)
index 0000000..467e4fd
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.computation.formula;
+
+import com.google.common.base.Optional;
+import java.util.List;
+import org.sonar.server.computation.component.Component;
+import org.sonar.server.computation.measure.Measure;
+import org.sonar.server.computation.period.Period;
+
+/**
+ * The context passing information to {@link Counter#initialize(CounterInitializationContext)}.
+ */
+public interface CounterInitializationContext {
+
+  /**
+   * The Component representing the currently processed leaf.
+   */
+  Component getLeaf();
+
+  /**
+   * Retrieve the measure for the current component for the specified metric key if it exists.
+   */
+  Optional<Measure> getMeasure(String metricKey);
+
+  /**
+   * Lists of Periods defined for the current project. They can be used to retrieve variations Measure.
+   */
+  List<Period> getPeriods();
+
+}
index 3f9ce4b0cb33dfeebec757d6b95faa689b9456a2..27c6229e0b08ac2908617ede4528f64169334e5e 100644 (file)
@@ -68,7 +68,7 @@ public class DistributionFormula implements Formula<DistributionFormula.Distribu
     }
 
     @Override
-    public void aggregate(LeafAggregateContext context) {
+    public void initialize(CounterInitializationContext context) {
       Optional<Measure> measureOptional = context.getMeasure(metricKey);
       String data = measureOptional.isPresent() ? measureOptional.get().getData() : null;
       if (data != null) {
index ec8476722f0cec159ac341b10e27ed2f3f8a6588..d5039b00107c2e6248550c8b3b3b1aed21d9674d 100644 (file)
@@ -151,10 +151,10 @@ public class FormulaExecutorComponentVisitor extends PathAwareVisitorAdapter<For
   }
 
   private void processLeaf(Component file, Path<FormulaExecutorComponentVisitor.Counters> path) {
-    LeafAggregateContext counterContext = new LeafAggregateContextImpl(file);
+    CounterInitializationContext counterContext = new CounterInitializationContextImpl(file);
     for (Formula formula : formulas) {
       Counter counter = formula.createNewCounter();
-      counter.aggregate(counterContext);
+      counter.initialize(counterContext);
       for (String metricKey : formula.getOutputMetricKeys()) {
         addNewMeasure(file, metricKey, formula, counter);
       }
@@ -180,10 +180,10 @@ public class FormulaExecutorComponentVisitor extends PathAwareVisitorAdapter<For
     }
   }
 
-  private class LeafAggregateContextImpl implements LeafAggregateContext {
+  private class CounterInitializationContextImpl implements CounterInitializationContext {
     private final Component file;
 
-    public LeafAggregateContextImpl(Component file) {
+    public CounterInitializationContextImpl(Component file) {
       this.file = file;
     }
 
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/formula/LeafAggregateContext.java b/server/sonar-server/src/main/java/org/sonar/server/computation/formula/LeafAggregateContext.java
deleted file mode 100644 (file)
index a70e61a..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.sonar.server.computation.formula;
-
-import com.google.common.base.Optional;
-import java.util.List;
-import org.sonar.server.computation.component.Component;
-import org.sonar.server.computation.measure.Measure;
-import org.sonar.server.computation.period.Period;
-
-/**
- * The context passing information to {@link Counter#aggregate(LeafAggregateContext)}.
- */
-public interface LeafAggregateContext {
-
-  /**
-   * The Component representing the currently processed leaf.
-   */
-  Component getLeaf();
-
-  /**
-   * Retrieve the measure for the current component for the specified metric key if it exists.
-   */
-  Optional<Measure> getMeasure(String metricKey);
-
-  /**
-   * Lists of Periods defined for the current project. They can be used to retrieve variations Measure.
-   */
-  List<Period> getPeriods();
-
-}
index c5dd1c5f8e223dd61d9f5e94f91d4db329812b33..7ea3853ebac6a4a11c256b4fbe7d827fc4c804b3 100644 (file)
@@ -21,7 +21,7 @@
 package org.sonar.server.computation.formula.counter;
 
 import com.google.common.base.Optional;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.measure.Measure;
 
 /**
@@ -46,7 +46,7 @@ public class IntSumCounter implements SumCounter<Integer, IntSumCounter> {
   }
 
   @Override
-  public void aggregate(LeafAggregateContext context) {
+  public void initialize(CounterInitializationContext context) {
     Optional<Measure> measureOptional = context.getMeasure(metricKey);
     if (measureOptional.isPresent()) {
       addValue(measureOptional.get().getIntValue());
index 30af1009ef7e65d1db7d0aceb4d343c2b6a61a46..4731f9b59a7d95f368dd51b20e27489c1ae911e0 100644 (file)
@@ -21,7 +21,7 @@
 package org.sonar.server.computation.formula.counter;
 
 import com.google.common.base.Optional;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.measure.Measure;
 
 /**
@@ -46,7 +46,7 @@ public class LongSumCounter implements SumCounter<Long, LongSumCounter> {
   }
 
   @Override
-  public void aggregate(LeafAggregateContext context) {
+  public void initialize(CounterInitializationContext context) {
     Optional<Measure> measureOptional = context.getMeasure(metricKey);
     if (measureOptional.isPresent()) {
       addValue(measureOptional.get().getLongValue());
index 7a72461d795962bba0ea1ffc19275d714585fab4..4646c06bd9b7ec62f87c8d673ecba785dd06ceac 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.server.computation.formula.coverage;
 
 import com.google.common.base.Optional;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.measure.Measure;
 import org.sonar.server.computation.measure.MeasureVariations;
 import org.sonar.server.computation.period.Period;
@@ -39,7 +39,7 @@ public final class CoverageUtils {
     return (100.0 * coveredLines) / lines;
   }
 
-  static long getLongMeasureValue(LeafAggregateContext counterContext, String metricKey) {
+  static long getLongMeasureValue(CounterInitializationContext counterContext, String metricKey) {
     Measure measure = counterContext.getMeasure(metricKey).or(DEFAULT_MEASURE);
     if (measure.getValueType() == Measure.ValueType.NO_VALUE) {
       return 0L;
@@ -50,7 +50,7 @@ public final class CoverageUtils {
     return measure.getLongValue();
   }
 
-  static MeasureVariations getMeasureVariations(LeafAggregateContext counterContext, String metricKey) {
+  static MeasureVariations getMeasureVariations(CounterInitializationContext counterContext, String metricKey) {
     Optional<Measure> measure = counterContext.getMeasure(metricKey);
     if (!measure.isPresent() || !measure.get().hasVariations()) {
       return DEFAULT_VARIATIONS;
index b78ec62fee308c7f1c608393c1d8238be3fba542..9bf7c3ebec2514faef9a4622a528e88f09ecb55a 100644 (file)
@@ -21,7 +21,7 @@ package org.sonar.server.computation.formula.coverage;
 
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.formula.Counter;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 
 /**
  * A counter used to create a measure which are based on a count of elements and coveredElements.
@@ -37,13 +37,13 @@ public abstract class ElementsAndCoveredElementsCounter implements Counter<Eleme
   }
 
   @Override
-  public void aggregate(LeafAggregateContext context) {
+  public void initialize(CounterInitializationContext context) {
     Component component = context.getLeaf();
     if (component.getType().isReportType() && component.getFileAttributes().isUnitTest()) {
       return;
     }
-    aggregateForSupportedLeaf(context);
+    initializeForSupportedLeaf(context);
   }
 
-  protected abstract void aggregateForSupportedLeaf(LeafAggregateContext counterContext);
+  protected abstract void initializeForSupportedLeaf(CounterInitializationContext counterContext);
 }
index f60c0a231709814721cfa1b344bbec3d90b42003..f260bb6ac47739f27faf9c5082c514c0b13c8403 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.server.computation.formula.coverage;
 
 import org.sonar.server.computation.formula.Counter;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.formula.counter.LongVariationValue;
 
 /**
@@ -37,12 +37,12 @@ public abstract class ElementsAndCoveredElementsVariationCounter implements Coun
   }
 
   @Override
-  public void aggregate(LeafAggregateContext context) {
+  public void initialize(CounterInitializationContext context) {
     if (context.getLeaf().getFileAttributes().isUnitTest()) {
       return;
     }
-    aggregateForSupportedFile(context);
+    initializeForSupportedLeaf(context);
   }
 
-  protected abstract void aggregateForSupportedFile(LeafAggregateContext counterContext);
+  protected abstract void initializeForSupportedLeaf(CounterInitializationContext counterContext);
 }
index eed56193cecffb1e12f848e2797640f7a56bfc36..e0ec922b801f5f6d23cc853a932d963e37593f33 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.computation.formula.coverage;
 
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 
 import static org.sonar.server.computation.formula.coverage.CoverageUtils.getLongMeasureValue;
 
@@ -31,7 +31,7 @@ public final class LinesAndConditionsWithUncoveredCounter extends ElementsAndCov
   }
 
   @Override
-  protected void aggregateForSupportedLeaf(LeafAggregateContext counterContext) {
+  protected void initializeForSupportedLeaf(CounterInitializationContext counterContext) {
     this.elements = getLongMeasureValue(counterContext, metricKeys.getLines())
       + getLongMeasureValue(counterContext, metricKeys.getConditions());
     this.coveredElements = this.elements
index e54e6d233a5173927b58cff5d5b993829e923692..bb28272c194179271f95e9b2e9d15bed8075fff3 100644 (file)
@@ -20,7 +20,7 @@
 package org.sonar.server.computation.formula.coverage;
 
 import com.google.common.base.Optional;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.measure.Measure;
 import org.sonar.server.computation.measure.MeasureVariations;
 import org.sonar.server.computation.period.Period;
@@ -33,7 +33,7 @@ public final class LinesAndConditionsWithUncoveredVariationCounter extends Eleme
   }
 
   @Override
-  public void aggregateForSupportedFile(LeafAggregateContext counterContext) {
+  public void initializeForSupportedLeaf(CounterInitializationContext counterContext) {
     Optional<Measure> newLinesMeasure = counterContext.getMeasure(metricKeys.getLines());
     if (!newLinesMeasure.isPresent() || !newLinesMeasure.get().hasVariations()) {
       return;
index 9b3908316aae3b53e3fe3a73a2c68679406a5a91..ddbf3931981d8a8d4bbf25e4dd16f29cf4979e18 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.computation.formula.coverage;
 
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 
 import static org.sonar.server.computation.formula.coverage.CoverageUtils.getLongMeasureValue;
 
@@ -31,7 +31,7 @@ public final class SingleWithUncoveredCounter extends ElementsAndCoveredElements
   }
 
   @Override
-  protected void aggregateForSupportedLeaf(LeafAggregateContext counterContext) {
+  protected void initializeForSupportedLeaf(CounterInitializationContext counterContext) {
     this.elements = getLongMeasureValue(counterContext, metricKeys.getCovered());
     this.coveredElements = this.elements - getLongMeasureValue(counterContext, metricKeys.getUncovered());
   }
index dd49f51287304c3092582f50c3d60c8283f33934..4009600977bbe9080d4564c6682e6dbaea556800 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.computation.formula.coverage;
 
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.measure.MeasureVariations;
 import org.sonar.server.computation.period.Period;
 
@@ -35,7 +35,7 @@ public final class SingleWithUncoveredVariationCounter extends ElementsAndCovere
   }
 
   @Override
-  protected void aggregateForSupportedFile(LeafAggregateContext counterContext) {
+  protected void initializeForSupportedLeaf(CounterInitializationContext counterContext) {
     MeasureVariations newConditions = getMeasureVariations(counterContext, metricKeys.getCovered());
     MeasureVariations uncoveredConditions = getMeasureVariations(counterContext, metricKeys.getUncovered());
     for (Period period : counterContext.getPeriods()) {
index 3a41699c5eac8174617eb70847aaa24182ac1375..f097f8d5d0f4d33fe75728dc0e9a58e8378cce92 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.server.computation.formula.Counter;
 import org.sonar.server.computation.formula.CreateMeasureContext;
 import org.sonar.server.computation.formula.Formula;
 import org.sonar.server.computation.formula.FormulaExecutorComponentVisitor;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.formula.counter.IntSumCounter;
 import org.sonar.server.computation.formula.counter.SumCounter;
 import org.sonar.server.computation.measure.Measure;
@@ -184,9 +184,9 @@ public class CommentMeasuresStep implements ComputationStep {
     }
 
     @Override
-    public void aggregate(LeafAggregateContext context) {
-      publicApiCounter.aggregate(context);
-      publicUndocumentedApiCounter.aggregate(context);
+    public void initialize(CounterInitializationContext context) {
+      publicApiCounter.initialize(context);
+      publicUndocumentedApiCounter.initialize(context);
     }
 
     public Optional<Integer> getPublicApiValue() {
index 6c688cdcc93796fbe5f6696ed9d185abba4942d2..ae7020cb558c51295a355938dd6f459f457fa09e 100644 (file)
@@ -31,7 +31,7 @@ import org.sonar.server.computation.formula.CreateMeasureContext;
 import org.sonar.server.computation.formula.Formula;
 import org.sonar.server.computation.formula.FormulaExecutorComponentVisitor;
 import org.sonar.server.computation.formula.counter.IntSumCounter;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.measure.Measure;
 import org.sonar.server.computation.measure.MeasureRepository;
 import org.sonar.server.computation.metric.Metric;
@@ -187,7 +187,7 @@ public class DuplicationMeasuresStep implements ComputationStep {
     }
 
     @Override
-    public void aggregate(LeafAggregateContext context) {
+    public void initialize(CounterInitializationContext context) {
       Optional<Measure> measureOptional = context.getMeasure(metricKey);
       if (measureOptional.isPresent()) {
         value += measureOptional.get().getIntValue();
index a02d08c1bea28245ab2b9d022608f2a0ccc23ae2..b4665b4721942bd13a6afbd12b7ed30bc2ee80dd 100644 (file)
@@ -32,7 +32,7 @@ import org.sonar.server.computation.component.PathAwareCrawler;
 import org.sonar.server.computation.component.TreeRootHolder;
 import org.sonar.server.computation.formula.Counter;
 import org.sonar.server.computation.formula.CreateMeasureContext;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.formula.Formula;
 import org.sonar.server.computation.formula.FormulaExecutorComponentVisitor;
 import org.sonar.server.computation.measure.Measure;
@@ -115,7 +115,7 @@ public class LanguageDistributionMeasuresStep implements ComputationStep {
     }
 
     @Override
-    public void aggregate(LeafAggregateContext context) {
+    public void initialize(CounterInitializationContext context) {
       String language = context.getLeaf().getFileAttributes().getLanguageKey();
       Optional<Measure> ncloc = context.getMeasure(CoreMetrics.NCLOC_KEY);
       if (ncloc.isPresent()) {
index 86b0a22e819460f69187f7c48d21f19260a2d143..5e2de9e9525626697f84a8f9fad446e9b0bf217b 100644 (file)
@@ -36,7 +36,7 @@ import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.PathAwareCrawler;
 import org.sonar.server.computation.component.TreeRootHolder;
 import org.sonar.server.computation.formula.CreateMeasureContext;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.formula.Formula;
 import org.sonar.server.computation.formula.FormulaExecutorComponentVisitor;
 import org.sonar.server.computation.formula.counter.IntVariationValue;
@@ -297,7 +297,7 @@ public class NewCoverageMeasuresStep implements ComputationStep {
     }
 
     @Override
-    public void aggregate(LeafAggregateContext context) {
+    public void initialize(CounterInitializationContext context) {
       Component fileComponent = context.getLeaf();
       BatchReport.Changesets componentScm = batchReportReader.readChangesets(fileComponent.getReportAttributes().getRef());
       if (componentScm == null) {
index 97e110ff0dfdea8a99709df1b35e461c9469cfe7..34bfb28cc857f4daafdc2a3b4c59d82b431283aa 100644 (file)
@@ -29,7 +29,7 @@ import org.sonar.server.computation.formula.Counter;
 import org.sonar.server.computation.formula.CreateMeasureContext;
 import org.sonar.server.computation.formula.Formula;
 import org.sonar.server.computation.formula.FormulaExecutorComponentVisitor;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.formula.counter.IntSumCounter;
 import org.sonar.server.computation.measure.Measure;
 import org.sonar.server.computation.measure.MeasureRepository;
@@ -138,10 +138,10 @@ public class UnitTestMeasuresStep implements ComputationStep {
     }
 
     @Override
-    public void aggregate(LeafAggregateContext context) {
-      testsCounter.aggregate(context);
-      testsErrorsCounter.aggregate(context);
-      testsFailuresCounter.aggregate(context);
+    public void initialize(CounterInitializationContext context) {
+      testsCounter.initialize(context);
+      testsErrorsCounter.initialize(context);
+      testsFailuresCounter.initialize(context);
     }
   }
 
index 32c4d748261ce6d57bcf357589aeecc8367333a6..32ad48aac48c54c88598c2065d8007f2d08b58ba 100644 (file)
@@ -50,7 +50,7 @@ public class AverageFormulaTest {
     .setByMetricKey(FUNCTIONS_KEY)
     .build();
 
-  LeafAggregateContext leafAggregateContext = mock(LeafAggregateContext.class);
+  CounterInitializationContext counterInitializationContext = mock(CounterInitializationContext.class);
   CreateMeasureContext createMeasureContext = new DumbCreateMeasureContext(
       ReportComponent.builder(Component.Type.PROJECT, 1).build(), mock(Metric.class), mock(PeriodsHolder.class));
 
@@ -108,7 +108,7 @@ public class AverageFormulaTest {
     AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter();
     addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10d);
     addMeasure(FUNCTIONS_KEY, 2d);
-    counter.aggregate(leafAggregateContext);
+    counter.initialize(counterInitializationContext);
 
     assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext).get().getDoubleValue()).isEqualTo(5d);
   }
@@ -118,7 +118,7 @@ public class AverageFormulaTest {
     AverageFormula.AverageCounter anotherCounter = BASIC_AVERAGE_FORMULA.createNewCounter();
     addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10d);
     addMeasure(FUNCTIONS_KEY, 2d);
-    anotherCounter.aggregate(leafAggregateContext);
+    anotherCounter.initialize(counterInitializationContext);
 
     AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter();
     counter.aggregate(anotherCounter);
@@ -131,7 +131,7 @@ public class AverageFormulaTest {
     AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter();
     addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10d);
     addMeasure(FUNCTIONS_KEY, 2d);
-    counter.aggregate(leafAggregateContext);
+    counter.initialize(counterInitializationContext);
 
     assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext).get().getDoubleValue()).isEqualTo(5d);
   }
@@ -141,7 +141,7 @@ public class AverageFormulaTest {
     AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter();
     addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10);
     addMeasure(FUNCTIONS_KEY, 2);
-    counter.aggregate(leafAggregateContext);
+    counter.initialize(counterInitializationContext);
 
     assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext).get().getDoubleValue()).isEqualTo(5);
   }
@@ -151,7 +151,7 @@ public class AverageFormulaTest {
     AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter();
     addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10L);
     addMeasure(FUNCTIONS_KEY, 2L);
-    counter.aggregate(leafAggregateContext);
+    counter.initialize(counterInitializationContext);
 
     assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext).get().getDoubleValue()).isEqualTo(5L);
   }
@@ -160,8 +160,8 @@ public class AverageFormulaTest {
   public void not_create_measure_when_aggregated_measure_has_no_value() {
     AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter();
     addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10L);
-    when(leafAggregateContext.getMeasure(FUNCTIONS_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().createNoValue()));
-    counter.aggregate(leafAggregateContext);
+    when(counterInitializationContext.getMeasure(FUNCTIONS_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().createNoValue()));
+    counter.initialize(counterInitializationContext);
 
     Assertions.assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext)).isAbsent();
   }
@@ -173,8 +173,8 @@ public class AverageFormulaTest {
 
     AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter();
     addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10L);
-    when(leafAggregateContext.getMeasure(FUNCTIONS_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().create("data")));
-    counter.aggregate(leafAggregateContext);
+    when(counterInitializationContext.getMeasure(FUNCTIONS_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().create("data")));
+    counter.initialize(counterInitializationContext);
 
     BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext);
   }
@@ -182,8 +182,8 @@ public class AverageFormulaTest {
   @Test
   public void no_measure_created_when_counter_has_no_value() {
     AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter();
-    when(leafAggregateContext.getMeasure(anyString())).thenReturn(Optional.<Measure>absent());
-    counter.aggregate(leafAggregateContext);
+    when(counterInitializationContext.getMeasure(anyString())).thenReturn(Optional.<Measure>absent());
+    counter.initialize(counterInitializationContext);
 
     Assertions.assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext)).isAbsent();
   }
@@ -192,8 +192,8 @@ public class AverageFormulaTest {
   public void not_create_measure_when_only_one_measure() {
     AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter();
     addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10L);
-    when(leafAggregateContext.getMeasure(FUNCTIONS_KEY)).thenReturn(Optional.<Measure>absent());
-    counter.aggregate(leafAggregateContext);
+    when(counterInitializationContext.getMeasure(FUNCTIONS_KEY)).thenReturn(Optional.<Measure>absent());
+    counter.initialize(counterInitializationContext);
 
     Assertions.assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext)).isAbsent();
   }
@@ -203,7 +203,7 @@ public class AverageFormulaTest {
     AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter();
     addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10d);
     addMeasure(FUNCTIONS_KEY, 0d);
-    counter.aggregate(leafAggregateContext);
+    counter.initialize(counterInitializationContext);
 
     Assertions.assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext)).isAbsent();
   }
@@ -218,10 +218,10 @@ public class AverageFormulaTest {
       .build();
 
     AverageFormula.AverageCounter counter = underTest.createNewCounter();
-    when(leafAggregateContext.getMeasure(COMPLEXITY_IN_FUNCTIONS_KEY)).thenReturn(Optional.<Measure>absent());
+    when(counterInitializationContext.getMeasure(COMPLEXITY_IN_FUNCTIONS_KEY)).thenReturn(Optional.<Measure>absent());
     addMeasure(COMPLEXITY_KEY, 10d);
     addMeasure(FUNCTIONS_KEY, 2d);
-    counter.aggregate(leafAggregateContext);
+    counter.initialize(counterInitializationContext);
 
     assertThat(underTest.createMeasure(counter, createMeasureContext).get().getDoubleValue()).isEqualTo(5d);
   }
@@ -239,21 +239,21 @@ public class AverageFormulaTest {
     addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10d);
     addMeasure(COMPLEXITY_KEY, 12d);
     addMeasure(FUNCTIONS_KEY, 2d);
-    counter.aggregate(leafAggregateContext);
+    counter.initialize(counterInitializationContext);
 
     assertThat(underTest.createMeasure(counter, createMeasureContext).get().getDoubleValue()).isEqualTo(5d);
   }
 
   private void addMeasure(String metricKey, double value) {
-    when(leafAggregateContext.getMeasure(metricKey)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(value)));
+    when(counterInitializationContext.getMeasure(metricKey)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(value)));
   }
 
   private void addMeasure(String metricKey, int value) {
-    when(leafAggregateContext.getMeasure(metricKey)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(value)));
+    when(counterInitializationContext.getMeasure(metricKey)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(value)));
   }
 
   private void addMeasure(String metricKey, long value) {
-    when(leafAggregateContext.getMeasure(metricKey)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(value)));
+    when(counterInitializationContext.getMeasure(metricKey)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(value)));
   }
 
 }
index b6379b7df981c890a2465dcbaa668cb4b5195343..34964ba009e2480f3b51313e38de6d24c964ca23 100644 (file)
@@ -43,7 +43,7 @@ public class DistributionFormulaTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  LeafAggregateContext leafAggregateContext = mock(LeafAggregateContext.class);
+  CounterInitializationContext counterInitializationContext = mock(CounterInitializationContext.class);
   CreateMeasureContext projectCreateMeasureContext = new DumbCreateMeasureContext(
       ReportComponent.builder(Component.Type.PROJECT, 1).build(), mock(Metric.class), mock(PeriodsHolder.class));
   CreateMeasureContext fileCreateMeasureContext = new DumbCreateMeasureContext(
@@ -71,7 +71,7 @@ public class DistributionFormulaTest {
   public void create_measure() {
     DistributionFormula.DistributionCounter counter = BASIC_DISTRIBUTION_FORMULA.createNewCounter();
     addMeasure(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, "0=3;3=7;6=10");
-    counter.aggregate(leafAggregateContext);
+    counter.initialize(counterInitializationContext);
 
     assertThat(BASIC_DISTRIBUTION_FORMULA.createMeasure(counter, projectCreateMeasureContext).get().getData()).isEqualTo("0=3;3=7;6=10");
   }
@@ -80,7 +80,7 @@ public class DistributionFormulaTest {
   public void create_measure_when_counter_is_aggregating_from_another_counter() {
     DistributionFormula.DistributionCounter anotherCounter = BASIC_DISTRIBUTION_FORMULA.createNewCounter();
     addMeasure(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, "0=3;3=7;6=10");
-    anotherCounter.aggregate(leafAggregateContext);
+    anotherCounter.initialize(counterInitializationContext);
 
     DistributionFormula.DistributionCounter counter = BASIC_DISTRIBUTION_FORMULA.createNewCounter();
     counter.aggregate(anotherCounter);
@@ -91,8 +91,8 @@ public class DistributionFormulaTest {
   @Test
   public void create_no_measure_when_no_value() {
     DistributionFormula.DistributionCounter counter = BASIC_DISTRIBUTION_FORMULA.createNewCounter();
-    when(leafAggregateContext.getMeasure(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(Optional.<Measure>absent());
-    counter.aggregate(leafAggregateContext);
+    when(counterInitializationContext.getMeasure(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(Optional.<Measure>absent());
+    counter.initialize(counterInitializationContext);
 
     Assertions.assertThat(BASIC_DISTRIBUTION_FORMULA.createMeasure(counter, projectCreateMeasureContext)).isAbsent();
   }
@@ -101,13 +101,13 @@ public class DistributionFormulaTest {
   public void not_create_measure_when_on_file() {
     DistributionFormula.DistributionCounter counter = BASIC_DISTRIBUTION_FORMULA.createNewCounter();
     addMeasure(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY, "0=3;3=7;6=10");
-    counter.aggregate(leafAggregateContext);
+    counter.initialize(counterInitializationContext);
 
     Assertions.assertThat(BASIC_DISTRIBUTION_FORMULA.createMeasure(counter, fileCreateMeasureContext)).isAbsent();
   }
 
   private void addMeasure(String metricKey, String value) {
-    when(leafAggregateContext.getMeasure(metricKey)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(value)));
+    when(counterInitializationContext.getMeasure(metricKey)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(value)));
   }
 
 }
index c6343d7801084f3c8712a1602324f5b4596a2926..7c2878db2dd83a0d645e1bd6ce05fe666593504d 100644 (file)
@@ -46,7 +46,7 @@ public class IntSumFormulaTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  LeafAggregateContext leafAggregateContext = mock(LeafAggregateContext.class);
+  CounterInitializationContext counterInitializationContext = mock(CounterInitializationContext.class);
   CreateMeasureContext projectCreateMeasureContext = new DumbCreateMeasureContext(
     ReportComponent.builder(Component.Type.PROJECT, 1).build(), mock(Metric.class), mock(PeriodsHolder.class));
   CreateMeasureContext fileCreateMeasureContext = new DumbCreateMeasureContext(
@@ -74,7 +74,7 @@ public class IntSumFormulaTest {
   public void create_measure() {
     IntSumCounter counter = INT_SUM_FORMULA.createNewCounter();
     addMeasure(LINES_KEY, 10);
-    counter.aggregate(leafAggregateContext);
+    counter.initialize(counterInitializationContext);
 
     assertThat(INT_SUM_FORMULA.createMeasure(counter, projectCreateMeasureContext).get().getIntValue()).isEqualTo(10);
   }
@@ -83,7 +83,7 @@ public class IntSumFormulaTest {
   public void create_measure_when_counter_is_aggregating_from_another_counter() {
     IntSumCounter anotherCounter = INT_SUM_FORMULA.createNewCounter();
     addMeasure(LINES_KEY, 10);
-    anotherCounter.aggregate(leafAggregateContext);
+    anotherCounter.initialize(counterInitializationContext);
 
     IntSumCounter counter = INT_SUM_FORMULA.createNewCounter();
     counter.aggregate(anotherCounter);
@@ -95,7 +95,7 @@ public class IntSumFormulaTest {
   public void not_create_measure_on_file() {
     IntSumCounter counter = INT_SUM_FORMULA.createNewCounter();
     addMeasure(LINES_KEY, 10);
-    counter.aggregate(leafAggregateContext);
+    counter.initialize(counterInitializationContext);
 
     Assertions.assertThat(INT_SUM_FORMULA.createMeasure(counter, fileCreateMeasureContext)).isAbsent();
   }
@@ -103,14 +103,14 @@ public class IntSumFormulaTest {
   @Test
   public void do_not_create_measures_when_no_values() {
     IntSumCounter counter = INT_SUM_FORMULA.createNewCounter();
-    when(leafAggregateContext.getMeasure(LINES_KEY)).thenReturn(Optional.<Measure>absent());
-    counter.aggregate(leafAggregateContext);
+    when(counterInitializationContext.getMeasure(LINES_KEY)).thenReturn(Optional.<Measure>absent());
+    counter.initialize(counterInitializationContext);
 
     Assertions.assertThat(INT_SUM_FORMULA.createMeasure(counter, projectCreateMeasureContext)).isAbsent();
   }
 
   private void addMeasure(String metricKey, int value) {
-    when(leafAggregateContext.getMeasure(metricKey)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(value)));
+    when(counterInitializationContext.getMeasure(metricKey)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(value)));
   }
 
 }
index 20d28b6ff9df28e4a02a021b70df3543c5da00e2..10b8ee5a69279edb93307acc0090e593ffd5be29 100644 (file)
@@ -47,7 +47,7 @@ public class LongSumFormulaTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  LeafAggregateContext leafAggregateContext = mock(LeafAggregateContext.class);
+  CounterInitializationContext counterInitializationContext = mock(CounterInitializationContext.class);
   CreateMeasureContext projectCreateMeasureContext = new DumbCreateMeasureContext(
     ReportComponent.builder(Component.Type.PROJECT, 1).build(), mock(Metric.class), mock(PeriodsHolder.class));
   CreateMeasureContext fileCreateMeasureContext = new DumbCreateMeasureContext(
@@ -75,7 +75,7 @@ public class LongSumFormulaTest {
   public void create_measure() {
     LongSumCounter counter = LONG_SUM_FORMULA.createNewCounter();
     addMeasure(LINES_KEY, MEASURE_VALUE);
-    counter.aggregate(leafAggregateContext);
+    counter.initialize(counterInitializationContext);
 
     assertThat(LONG_SUM_FORMULA.createMeasure(counter, projectCreateMeasureContext).get().getLongValue()).isEqualTo(MEASURE_VALUE);
   }
@@ -84,7 +84,7 @@ public class LongSumFormulaTest {
   public void create_measure_when_counter_is_aggregating_from_another_counter() {
     LongSumCounter anotherCounter = LONG_SUM_FORMULA.createNewCounter();
     addMeasure(LINES_KEY, MEASURE_VALUE);
-    anotherCounter.aggregate(leafAggregateContext);
+    anotherCounter.initialize(counterInitializationContext);
 
     LongSumCounter counter = LONG_SUM_FORMULA.createNewCounter();
     counter.aggregate(anotherCounter);
@@ -96,7 +96,7 @@ public class LongSumFormulaTest {
   public void not_create_measure_on_file() {
     LongSumCounter counter = LONG_SUM_FORMULA.createNewCounter();
     addMeasure(LINES_KEY, MEASURE_VALUE);
-    counter.aggregate(leafAggregateContext);
+    counter.initialize(counterInitializationContext);
 
     Assertions.assertThat(LONG_SUM_FORMULA.createMeasure(counter, fileCreateMeasureContext)).isAbsent();
   }
@@ -104,14 +104,14 @@ public class LongSumFormulaTest {
   @Test
   public void do_not_create_measures_when_no_values() {
     LongSumCounter counter = LONG_SUM_FORMULA.createNewCounter();
-    when(leafAggregateContext.getMeasure(LINES_KEY)).thenReturn(Optional.<Measure>absent());
-    counter.aggregate(leafAggregateContext);
+    when(counterInitializationContext.getMeasure(LINES_KEY)).thenReturn(Optional.<Measure>absent());
+    counter.initialize(counterInitializationContext);
 
     Assertions.assertThat(LONG_SUM_FORMULA.createMeasure(counter, projectCreateMeasureContext)).isAbsent();
   }
 
   private void addMeasure(String metricKey, long value) {
-    when(leafAggregateContext.getMeasure(metricKey)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(value)));
+    when(counterInitializationContext.getMeasure(metricKey)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(value)));
   }
 
 }
index 730e26cd6ee5b24735ec495fe46fc2c3782226f7..b9f42a59ba50fe718ee1788313078dbeaa8245f7 100644 (file)
@@ -286,7 +286,7 @@ public class ReportFormulaExecutorComponentVisitorTest {
     }
 
     @Override
-    public void aggregate(LeafAggregateContext context) {
+    public void initialize(CounterInitializationContext context) {
       // verify the context which is passed to the method
       assertThat(context.getLeaf().getReportAttributes().getRef()).isIn(1111, 1112, 1211);
       assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods());
@@ -337,7 +337,7 @@ public class ReportFormulaExecutorComponentVisitorTest {
     }
 
     @Override
-    public void aggregate(LeafAggregateContext context) {
+    public void initialize(CounterInitializationContext context) {
       // verify the context which is passed to the method
       assertThat(context.getLeaf().getReportAttributes().getRef()).isIn(1111, 1112, 1211);
       assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods());
index 568460ecd7357e32ef1248c6b741eeb1fb6c8bd9..6103e0e8d8040a3d174e2d777a9002d1e9188ded 100644 (file)
@@ -283,7 +283,7 @@ public class ViewsFormulaExecutorComponentVisitorTest {
     }
 
     @Override
-    public void aggregate(LeafAggregateContext context) {
+    public void initialize(CounterInitializationContext context) {
       verifyLeafContext(context);
 
       Optional<Measure> measureOptional = context.getMeasure(LINES_KEY);
@@ -332,7 +332,7 @@ public class ViewsFormulaExecutorComponentVisitorTest {
     }
 
     @Override
-    public void aggregate(LeafAggregateContext context) {
+    public void initialize(CounterInitializationContext context) {
       verifyLeafContext(context);
 
       Optional<Measure> measureOptional = context.getMeasure(NEW_LINES_TO_COVER_KEY);
@@ -366,7 +366,7 @@ public class ViewsFormulaExecutorComponentVisitorTest {
             entryOf(NEW_IT_COVERAGE_KEY, newMeasureBuilder().create(valueItCoverage)));
   }
 
-  private void verifyLeafContext(LeafAggregateContext context) {
+  private void verifyLeafContext(CounterInitializationContext context) {
     assertThat(context.getLeaf().getKey()).isIn(String.valueOf(PROJECT_VIEW_1_REF), String.valueOf(PROJECT_VIEW_2_REF), String.valueOf(PROJECT_VIEW_3_REF),
       String.valueOf(PROJECT_VIEW_4_REF));
     assertThat(context.getPeriods()).isEqualTo(periodsHolder.getPeriods());
index a2e22822c659541c933f488b6263fc935d46f055..f291db6860222aba81ab7aeabb100ffe8fd9d52f 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.computation.formula.counter;
 
 import com.google.common.base.Optional;
 import org.junit.Test;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.measure.Measure;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -35,7 +35,7 @@ public class IntSumCounterTest {
 
   private final static String METRIC_KEY = "metric";
 
-  LeafAggregateContext leafAggregateContext = mock(LeafAggregateContext.class);
+  CounterInitializationContext counterInitializationContext = mock(CounterInitializationContext.class);
 
   SumCounter sumCounter = new IntSumCounter(METRIC_KEY);
 
@@ -46,27 +46,27 @@ public class IntSumCounterTest {
 
   @Test
   public void aggregate_from_context() {
-    when(leafAggregateContext.getMeasure(METRIC_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(10)));
+    when(counterInitializationContext.getMeasure(METRIC_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(10)));
 
-    sumCounter.aggregate(leafAggregateContext);
+    sumCounter.initialize(counterInitializationContext);
 
     assertThat(sumCounter.getValue().get()).isEqualTo(10);
   }
 
   @Test
   public void no_value_when_aggregate_from_context_but_no_measure() {
-    when(leafAggregateContext.getMeasure(anyString())).thenReturn(Optional.<Measure>absent());
+    when(counterInitializationContext.getMeasure(anyString())).thenReturn(Optional.<Measure>absent());
 
-    sumCounter.aggregate(leafAggregateContext);
+    sumCounter.initialize(counterInitializationContext);
 
     assertThat(sumCounter.getValue()).isAbsent();
   }
 
   @Test
   public void aggregate_from_counter() {
-    when(leafAggregateContext.getMeasure(METRIC_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(10)));
+    when(counterInitializationContext.getMeasure(METRIC_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(10)));
     SumCounter anotherCounter = new IntSumCounter(METRIC_KEY);
-    anotherCounter.aggregate(leafAggregateContext);
+    anotherCounter.initialize(counterInitializationContext);
 
     sumCounter.aggregate(anotherCounter);
 
index b79513a09724fd86c59ca23b5e3dd9030a8f0470..e2d0112cb8b03c019e4c1b1f4699067f2df117dd 100644 (file)
@@ -22,7 +22,7 @@ package org.sonar.server.computation.formula.counter;
 
 import com.google.common.base.Optional;
 import org.junit.Test;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.measure.Measure;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -36,7 +36,7 @@ public class LongSumCounterTest {
   private static final String METRIC_KEY = "metric";
   private static final long MEASURE_VALUE = 10L;
 
-  LeafAggregateContext leafAggregateContext = mock(LeafAggregateContext.class);
+  CounterInitializationContext counterInitializationContext = mock(CounterInitializationContext.class);
 
   SumCounter sumCounter = new LongSumCounter(METRIC_KEY);
 
@@ -47,27 +47,27 @@ public class LongSumCounterTest {
 
   @Test
   public void aggregate_from_context() {
-    when(leafAggregateContext.getMeasure(METRIC_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(MEASURE_VALUE)));
+    when(counterInitializationContext.getMeasure(METRIC_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(MEASURE_VALUE)));
 
-    sumCounter.aggregate(leafAggregateContext);
+    sumCounter.initialize(counterInitializationContext);
 
     assertThat(sumCounter.getValue().get()).isEqualTo(MEASURE_VALUE);
   }
 
   @Test
   public void no_value_when_aggregate_from_context_but_no_measure() {
-    when(leafAggregateContext.getMeasure(anyString())).thenReturn(Optional.<Measure>absent());
+    when(counterInitializationContext.getMeasure(anyString())).thenReturn(Optional.<Measure>absent());
 
-    sumCounter.aggregate(leafAggregateContext);
+    sumCounter.initialize(counterInitializationContext);
 
     assertThat(sumCounter.getValue()).isAbsent();
   }
 
   @Test
   public void aggregate_from_counter() {
-    when(leafAggregateContext.getMeasure(METRIC_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(MEASURE_VALUE)));
+    when(counterInitializationContext.getMeasure(METRIC_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(MEASURE_VALUE)));
     SumCounter anotherCounter = new LongSumCounter(METRIC_KEY);
-    anotherCounter.aggregate(leafAggregateContext);
+    anotherCounter.initialize(counterInitializationContext);
 
     sumCounter.aggregate(anotherCounter);
 
index 5037f8150835ff14ef4671982954cba6a0714c00..9be8edbbae1f0bb0b0b147cad2a2c6c57fd1cea1 100644 (file)
@@ -28,7 +28,7 @@ import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.ExternalResource;
 import org.sonar.server.computation.component.Component;
-import org.sonar.server.computation.formula.LeafAggregateContext;
+import org.sonar.server.computation.formula.CounterInitializationContext;
 import org.sonar.server.computation.measure.Measure;
 import org.sonar.server.computation.measure.MeasureVariations;
 import org.sonar.server.computation.period.Period;
@@ -47,7 +47,7 @@ public class CoverageUtilsTest {
   public static final MeasureVariations DEFAULT_VARIATIONS = new MeasureVariations(0d, 0d, 0d, 0d, 0d);
 
   @Rule
-  public LeafAggregateContextRule fileAggregateContext = new LeafAggregateContextRule();
+  public CounterInitializationContextRule fileAggregateContext = new CounterInitializationContextRule();
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
@@ -127,10 +127,10 @@ public class CoverageUtilsTest {
     return new Period(periodIndex, "mode" + periodIndex, null, 963L + periodIndex, 9865L + periodIndex);
   }
 
-  private static class LeafAggregateContextRule extends ExternalResource implements LeafAggregateContext {
+  private static class CounterInitializationContextRule extends ExternalResource implements CounterInitializationContext {
     private final Map<String, Measure> measures = new HashMap<>();
 
-    public LeafAggregateContextRule put(String metricKey, Measure measure) {
+    public CounterInitializationContextRule put(String metricKey, Measure measure) {
       checkNotNull(metricKey);
       checkNotNull(measure);
       checkState(!measures.containsKey(metricKey));