]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7169 Remove fallback from AverageFormula 759/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 3 Feb 2016 16:37:56 +0000 (17:37 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 4 Feb 2016 16:58:59 +0000 (17:58 +0100)
server/sonar-server/src/main/java/org/sonar/server/computation/formula/AverageFormula.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/ComplexityMeasuresStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/formula/AverageFormulaTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComplexityMeasuresStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComplexityMeasuresStepTest.java

index f188506ce3d7ddcf8e2ce6e23d5aaa50d4097121..b644c58fe3c4b503dfd6c97a5781f576d0ba6e1c 100644 (file)
@@ -20,8 +20,6 @@
 package org.sonar.server.computation.formula;
 
 import com.google.common.base.Optional;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
 import org.sonar.server.computation.measure.Measure;
 
 import static java.util.Objects.requireNonNull;
@@ -32,14 +30,11 @@ public class AverageFormula implements Formula<AverageFormula.AverageCounter> {
 
   private final String mainMetric;
   private final String byMetric;
-  @CheckForNull
-  private final String fallbackMetric;
 
   private AverageFormula(Builder builder) {
     this.outputMetricKey = builder.outputMetricKey;
     this.mainMetric = builder.mainMetric;
     this.byMetric = builder.byMetric;
-    this.fallbackMetric = builder.fallbackMetric;
   }
 
   @Override
@@ -70,8 +65,6 @@ public class AverageFormula implements Formula<AverageFormula.AverageCounter> {
     private String outputMetricKey;
     private String mainMetric;
     private String byMetric;
-    @CheckForNull
-    private String fallbackMetric;
 
     private Builder() {
       // prevents instantiation outside static method
@@ -96,11 +89,6 @@ public class AverageFormula implements Formula<AverageFormula.AverageCounter> {
       return this;
     }
 
-    public Builder setFallbackMetricKey(@Nullable String m) {
-      this.fallbackMetric = m;
-      return this;
-    }
-
     public AverageFormula build() {
       requireNonNull(outputMetricKey, "Output metric key cannot be null");
       requireNonNull(mainMetric, "Main metric Key cannot be null");
@@ -124,9 +112,6 @@ public class AverageFormula implements Formula<AverageFormula.AverageCounter> {
     @Override
     public void initialize(CounterInitializationContext context) {
       Optional<Double> mainValueOptional = getDoubleValue(context.getMeasure(mainMetric));
-      if (!mainValueOptional.isPresent() && fallbackMetric != null) {
-        mainValueOptional = getDoubleValue(context.getMeasure(fallbackMetric));
-      }
       Optional<Double> byValueOptional = getDoubleValue(context.getMeasure(byMetric));
       addValuesIfPresent(mainValueOptional, byValueOptional);
     }
index 99e9e99297439a6acb1c9813c6c2647b9ac5cf16..f371a31253cf5190e0535d1e222d4f54ba7b0b18 100644 (file)
@@ -62,12 +62,10 @@ public class ComplexityMeasuresStep implements ComputationStep {
     AverageFormula.Builder.newBuilder().setOutputMetricKey(CLASS_COMPLEXITY_KEY)
       .setMainMetricKey(COMPLEXITY_IN_CLASSES_KEY)
       .setByMetricKey(CLASSES_KEY)
-      .setFallbackMetricKey(COMPLEXITY_KEY)
       .build(),
     AverageFormula.Builder.newBuilder().setOutputMetricKey(FUNCTION_COMPLEXITY_KEY)
       .setMainMetricKey(COMPLEXITY_IN_FUNCTIONS_KEY)
       .setByMetricKey(FUNCTIONS_KEY)
-      .setFallbackMetricKey(COMPLEXITY_KEY)
       .build());
 
   private final TreeRootHolder treeRootHolder;
@@ -84,7 +82,7 @@ public class ComplexityMeasuresStep implements ComputationStep {
   public void execute() {
     new PathAwareCrawler<>(
       FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository).buildFor(FORMULAS))
-        .visit(treeRootHolder.getRoot());
+      .visit(treeRootHolder.getRoot());
   }
 
   @Override
index cedd21dffd64efa29d62efaaf6b47aa74a5bd2fc..404affd31ce63b8966ce5862a196ac6eb76ee321 100644 (file)
@@ -24,7 +24,6 @@ import org.assertj.guava.api.Assertions;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.api.measures.CoreMetrics;
 import org.sonar.server.computation.component.Component;
 import org.sonar.server.computation.component.ReportComponent;
 import org.sonar.server.computation.measure.Measure;
@@ -36,7 +35,6 @@ import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.api.measures.CoreMetrics.COMPLEXITY_IN_FUNCTIONS_KEY;
-import static org.sonar.api.measures.CoreMetrics.COMPLEXITY_KEY;
 import static org.sonar.api.measures.CoreMetrics.FUNCTIONS_KEY;
 import static org.sonar.api.measures.CoreMetrics.FUNCTION_COMPLEXITY_KEY;
 import static org.sonar.server.computation.formula.AverageFormula.Builder;
@@ -51,7 +49,7 @@ public class AverageFormulaTest {
 
   CounterInitializationContext counterInitializationContext = mock(CounterInitializationContext.class);
   CreateMeasureContext createMeasureContext = new DumbCreateMeasureContext(
-      ReportComponent.builder(Component.Type.PROJECT, 1).build(), mock(Metric.class), mock(PeriodsHolder.class));
+    ReportComponent.builder(Component.Type.PROJECT, 1).build(), mock(Metric.class), mock(PeriodsHolder.class));
 
   @Rule
   public ExpectedException thrown = ExpectedException.none();
@@ -207,42 +205,6 @@ public class AverageFormulaTest {
     Assertions.assertThat(BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext)).isAbsent();
   }
 
-  @Test
-  public void create_measure_from_fall_back_measure() {
-    AverageFormula underTest = Builder.newBuilder()
-      .setOutputMetricKey(FUNCTION_COMPLEXITY_KEY)
-      .setMainMetricKey(COMPLEXITY_IN_FUNCTIONS_KEY)
-      .setByMetricKey(FUNCTIONS_KEY)
-      .setFallbackMetricKey(CoreMetrics.COMPLEXITY_KEY)
-      .build();
-
-    AverageFormula.AverageCounter counter = underTest.createNewCounter();
-    when(counterInitializationContext.getMeasure(COMPLEXITY_IN_FUNCTIONS_KEY)).thenReturn(Optional.<Measure>absent());
-    addMeasure(COMPLEXITY_KEY, 10d);
-    addMeasure(FUNCTIONS_KEY, 2d);
-    counter.initialize(counterInitializationContext);
-
-    assertThat(underTest.createMeasure(counter, createMeasureContext).get().getDoubleValue()).isEqualTo(5d);
-  }
-
-  @Test
-  public void not_use_fallback_measure_if_main_measure_exists() {
-    AverageFormula underTest = Builder.newBuilder()
-      .setOutputMetricKey(FUNCTION_COMPLEXITY_KEY)
-      .setMainMetricKey(COMPLEXITY_IN_FUNCTIONS_KEY)
-      .setByMetricKey(FUNCTIONS_KEY)
-      .setFallbackMetricKey(CoreMetrics.COMPLEXITY_KEY)
-      .build();
-
-    AverageFormula.AverageCounter counter = underTest.createNewCounter();
-    addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10d);
-    addMeasure(COMPLEXITY_KEY, 12d);
-    addMeasure(FUNCTIONS_KEY, 2d);
-    counter.initialize(counterInitializationContext);
-
-    assertThat(underTest.createMeasure(counter, createMeasureContext).get().getDoubleValue()).isEqualTo(5d);
-  }
-
   private void addMeasure(String metricKey, double value) {
     when(counterInitializationContext.getMeasure(metricKey)).thenReturn(Optional.of(Measure.newMeasureBuilder().create(value, 1)));
   }
index c2bee1f676d92e69e5e889e62d74f14942a2e931..02c8a8172c90d1b8aaf51d8315c53333491b4d1b 100644 (file)
@@ -179,21 +179,11 @@ public class ReportComplexityMeasuresStepTest {
     verify_average_compute_and_aggregation(CLASS_COMPLEXITY_KEY, COMPLEXITY_IN_CLASSES_KEY, CLASSES_KEY);
   }
 
-  @Test
-  public void compute_and_aggregate_class_complexity_with_fallback_metric() throws Exception {
-    verify_average_compute_and_aggregation(CLASS_COMPLEXITY_KEY, COMPLEXITY_KEY, CLASSES_KEY);
-  }
-
   @Test
   public void compute_and_aggregate_function_complexity() throws Exception {
     verify_average_compute_and_aggregation(FUNCTION_COMPLEXITY_KEY, COMPLEXITY_IN_FUNCTIONS_KEY, FUNCTIONS_KEY);
   }
 
-  @Test
-  public void compute_and_aggregate_function_complexity_with_fallback_metric() throws Exception {
-    verify_average_compute_and_aggregation(FUNCTION_COMPLEXITY_KEY, COMPLEXITY_KEY, FUNCTIONS_KEY);
-  }
-
   private void verify_average_compute_and_aggregation(String metricKey, String mainMetric, String byMetric) {
     measureRepository.addRawMeasure(FILE_1_REF, mainMetric, newMeasureBuilder().create(5));
     measureRepository.addRawMeasure(FILE_1_REF, byMetric, newMeasureBuilder().create(2));
index 25b2aca2a327cba6860614f3f64926f129ef6855..d044c8b242658271efb0d80cfc3b7eea323edc13 100644 (file)
@@ -174,21 +174,11 @@ public class ViewsComplexityMeasuresStepTest {
     verify_average_compute_and_aggregation(CLASS_COMPLEXITY_KEY, COMPLEXITY_IN_CLASSES_KEY, CLASSES_KEY);
   }
 
-  @Test
-  public void compute_and_aggregate_class_complexity_with_fallback_metric() throws Exception {
-    verify_average_compute_and_aggregation(CLASS_COMPLEXITY_KEY, COMPLEXITY_KEY, CLASSES_KEY);
-  }
-
   @Test
   public void compute_and_aggregate_function_complexity() throws Exception {
     verify_average_compute_and_aggregation(FUNCTION_COMPLEXITY_KEY, COMPLEXITY_IN_FUNCTIONS_KEY, FUNCTIONS_KEY);
   }
 
-  @Test
-  public void compute_and_aggregate_function_complexity_with_fallback_metric() throws Exception {
-    verify_average_compute_and_aggregation(FUNCTION_COMPLEXITY_KEY, COMPLEXITY_KEY, FUNCTIONS_KEY);
-  }
-
   private void verify_average_compute_and_aggregation(String metricKey, String mainMetric, String byMetric) {
     addRawMeasureValue(PROJECT_VIEW_1_REF, mainMetric, 5);
     addRawMeasureValue(PROJECT_VIEW_1_REF, byMetric, 2);