diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-02-03 17:37:56 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-02-04 17:58:59 +0100 |
commit | 0161475560b18f9b0bb87a304a6b891d393091e2 (patch) | |
tree | 45819a4482c933c2a8b88c8043d4d73ba801517e | |
parent | 46a318695a8862a9d406b484ff5e3fa4e09d0366 (diff) | |
download | sonarqube-0161475560b18f9b0bb87a304a6b891d393091e2.tar.gz sonarqube-0161475560b18f9b0bb87a304a6b891d393091e2.zip |
SONAR-7169 Remove fallback from AverageFormula
5 files changed, 2 insertions, 77 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/formula/AverageFormula.java b/server/sonar-server/src/main/java/org/sonar/server/computation/formula/AverageFormula.java index f188506ce3d..b644c58fe3c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/formula/AverageFormula.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/formula/AverageFormula.java @@ -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); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComplexityMeasuresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComplexityMeasuresStep.java index 99e9e992974..f371a31253c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComplexityMeasuresStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ComplexityMeasuresStep.java @@ -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 diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/formula/AverageFormulaTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/formula/AverageFormulaTest.java index cedd21dffd6..404affd31ce 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/formula/AverageFormulaTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/formula/AverageFormulaTest.java @@ -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))); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComplexityMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComplexityMeasuresStepTest.java index c2bee1f676d..02c8a8172c9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComplexityMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportComplexityMeasuresStepTest.java @@ -180,20 +180,10 @@ public class ReportComplexityMeasuresStepTest { } @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)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComplexityMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComplexityMeasuresStepTest.java index 25b2aca2a32..d044c8b2426 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComplexityMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsComplexityMeasuresStepTest.java @@ -175,20 +175,10 @@ public class ViewsComplexityMeasuresStepTest { } @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); |