aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2019-03-14 11:50:42 +0100
committerSonarTech <sonartech@sonarsource.com>2019-03-14 20:21:40 +0100
commit11321c380539992f43101e2690e53baa2340efa9 (patch)
tree721a21f2b662cb8ce46f8819fabe04b203da023e /server
parent7956765bfa4685bb031b9e37a7a2fa046fadc0f6 (diff)
downloadsonarqube-11321c380539992f43101e2690e53baa2340efa9.tar.gz
sonarqube-11321c380539992f43101e2690e53baa2340efa9.zip
SONAR-10722 Clean code by removing portfolios in NewCoverageMeasuresStep
Diffstat (limited to 'server')
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java42
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStepTest.java (renamed from server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportNewCoverageMeasuresStepTest.java)2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsNewCoverageMeasuresStepTest.java211
3 files changed, 7 insertions, 248 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java
index ff71dc779ec..133da1a4503 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStep.java
@@ -25,7 +25,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
-import javax.annotation.Nullable;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
import org.sonar.ce.task.projectanalysis.component.Component;
@@ -36,7 +35,6 @@ import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext;
import org.sonar.ce.task.projectanalysis.formula.CreateMeasureContext;
import org.sonar.ce.task.projectanalysis.formula.Formula;
import org.sonar.ce.task.projectanalysis.formula.FormulaExecutorComponentVisitor;
-import org.sonar.ce.task.projectanalysis.formula.VariationSumFormula;
import org.sonar.ce.task.projectanalysis.formula.counter.IntValue;
import org.sonar.ce.task.projectanalysis.formula.coverage.LinesAndConditionsWithUncoveredMetricKeys;
import org.sonar.ce.task.projectanalysis.formula.coverage.LinesAndConditionsWithUncoveredVariationFormula;
@@ -72,14 +70,9 @@ public class NewCoverageMeasuresStep implements ComputationStep {
private final TreeRootHolder treeRootHolder;
private final MetricRepository metricRepository;
private final MeasureRepository measureRepository;
- @Nullable
private final NewLinesRepository newLinesRepository;
- @Nullable
private final BatchReportReader reportReader;
- /**
- * Constructor used when processing a Report (ie. a {@link NewLinesRepository} instance is available in the container)
- */
public NewCoverageMeasuresStep(TreeRootHolder treeRootHolder,
MeasureRepository measureRepository, MetricRepository metricRepository, NewLinesRepository newLinesRepository, BatchReportReader reportReader) {
this.treeRootHolder = treeRootHolder;
@@ -89,17 +82,6 @@ public class NewCoverageMeasuresStep implements ComputationStep {
this.reportReader = reportReader;
}
- /**
- * Constructor used when processing Views (ie. no {@link NewLinesRepository} instance is available in the container)
- */
- public NewCoverageMeasuresStep(TreeRootHolder treeRootHolder, MeasureRepository measureRepository, MetricRepository metricRepository) {
- this.treeRootHolder = treeRootHolder;
- this.metricRepository = metricRepository;
- this.measureRepository = measureRepository;
- this.newLinesRepository = null;
- this.reportReader = null;
- }
-
@Override
public void execute(ComputationStep.Context context) {
new PathAwareCrawler<>(
@@ -115,7 +97,7 @@ public class NewCoverageMeasuresStep implements ComputationStep {
}
private static class NewCoverageFormula extends LinesAndConditionsWithUncoveredVariationFormula {
- public NewCoverageFormula() {
+ NewCoverageFormula() {
super(
new LinesAndConditionsWithUncoveredMetricKeys(
NEW_LINES_TO_COVER_KEY, NEW_CONDITIONS_TO_COVER_KEY,
@@ -125,7 +107,7 @@ public class NewCoverageMeasuresStep implements ComputationStep {
}
private static class NewBranchCoverageFormula extends SingleWithUncoveredVariationFormula {
- public NewBranchCoverageFormula() {
+ NewBranchCoverageFormula() {
super(
new SingleWithUncoveredMetricKeys(NEW_CONDITIONS_TO_COVER_KEY, NEW_UNCOVERED_CONDITIONS_KEY),
CoreMetrics.NEW_BRANCH_COVERAGE_KEY);
@@ -133,7 +115,7 @@ public class NewCoverageMeasuresStep implements ComputationStep {
}
private static class NewLineCoverageFormula extends SingleWithUncoveredVariationFormula {
- public NewLineCoverageFormula() {
+ NewLineCoverageFormula() {
super(
new SingleWithUncoveredMetricKeys(NEW_LINES_TO_COVER_KEY, NEW_UNCOVERED_LINES_KEY),
CoreMetrics.NEW_LINE_COVERAGE_KEY);
@@ -143,28 +125,16 @@ public class NewCoverageMeasuresStep implements ComputationStep {
public static class NewLinesAndConditionsCoverageFormula implements Formula<NewCoverageCounter> {
private final NewLinesRepository newLinesRepository;
private final BatchReportReader reportReader;
- private static final Iterable<Formula<?>> VIEWS_FORMULAS = variationSumFormulas();
private NewLinesAndConditionsCoverageFormula(NewLinesRepository newLinesRepository, BatchReportReader reportReader) {
this.newLinesRepository = newLinesRepository;
this.reportReader = reportReader;
}
- public static Iterable<Formula<?>> from(@Nullable NewLinesRepository newLinesRepository, @Nullable BatchReportReader reportReader) {
- if (newLinesRepository == null || reportReader == null) {
- return VIEWS_FORMULAS;
- }
+ public static Iterable<Formula<NewCoverageCounter>> from(NewLinesRepository newLinesRepository, BatchReportReader reportReader) {
return Collections.singleton(new NewLinesAndConditionsCoverageFormula(newLinesRepository, reportReader));
}
- private static Iterable<Formula<?>> variationSumFormulas() {
- return ImmutableList.of(
- new VariationSumFormula(NEW_LINES_TO_COVER_KEY),
- new VariationSumFormula(NEW_UNCOVERED_LINES_KEY),
- new VariationSumFormula(NEW_CONDITIONS_TO_COVER_KEY),
- new VariationSumFormula(NEW_UNCOVERED_CONDITIONS_KEY));
- }
-
@Override
public NewCoverageCounter createNewCounter() {
return new NewCoverageCounter(newLinesRepository, reportReader);
@@ -179,7 +149,7 @@ public class NewCoverageMeasuresStep implements ComputationStep {
return Optional.empty();
}
- private int computeValueForMetric(NewCoverageCounter counter, Metric metric) {
+ private static int computeValueForMetric(NewCoverageCounter counter, Metric metric) {
if (metric.getKey().equals(NEW_LINES_TO_COVER_KEY)) {
return counter.getNewLines();
}
@@ -214,7 +184,7 @@ public class NewCoverageMeasuresStep implements ComputationStep {
private final NewLinesRepository newLinesRepository;
private final BatchReportReader reportReader;
- public NewCoverageCounter(NewLinesRepository newLinesRepository, BatchReportReader reportReader) {
+ NewCoverageCounter(NewLinesRepository newLinesRepository, BatchReportReader reportReader) {
this.newLinesRepository = newLinesRepository;
this.reportReader = reportReader;
}
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportNewCoverageMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStepTest.java
index 9721f72e7a0..f14c11af75c 100644
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportNewCoverageMeasuresStepTest.java
+++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/NewCoverageMeasuresStepTest.java
@@ -57,7 +57,7 @@ import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilde
import static org.sonar.ce.task.projectanalysis.measure.MeasureRepoEntry.entryOf;
import static org.sonar.ce.task.projectanalysis.measure.MeasureRepoEntry.toEntries;
-public class ReportNewCoverageMeasuresStepTest {
+public class NewCoverageMeasuresStepTest {
private static final int ROOT_REF = 1;
private static final int DIRECTORY_1_REF = 1111;
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsNewCoverageMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsNewCoverageMeasuresStepTest.java
deleted file mode 100644
index 110b509e901..00000000000
--- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsNewCoverageMeasuresStepTest.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.ce.task.projectanalysis.step;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule;
-import org.sonar.ce.task.projectanalysis.component.ViewsComponent;
-import org.sonar.ce.task.projectanalysis.formula.coverage.LinesAndConditionsWithUncoveredMetricKeys;
-import org.sonar.ce.task.projectanalysis.measure.Measure;
-import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule;
-import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule;
-import org.sonar.ce.task.step.TestComputationStepContext;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT_VIEW;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.SUBVIEW;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.VIEW;
-import static org.sonar.ce.task.projectanalysis.component.ViewsComponent.builder;
-import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
-import static org.sonar.ce.task.projectanalysis.measure.MeasureRepoEntry.entryOf;
-import static org.sonar.ce.task.projectanalysis.measure.MeasureRepoEntry.toEntries;
-
-public class ViewsNewCoverageMeasuresStepTest {
-
- private static final int ROOT_REF = 1;
- private static final int SUBVIEW_REF = 11;
- private static final int SUB_SUBVIEW_1_REF = 111;
- private static final int PROJECT_VIEW_1_REF = 1111;
- private static final int SUB_SUBVIEW_2_REF = 112;
- private static final int PROJECT_VIEW_2_REF = 1121;
- private static final int PROJECT_VIEW_3_REF = 1122;
- private static final int PROJECT_VIEW_4_REF = 12;
-
- private static final ViewsComponent VIEWS_TREE = builder(VIEW, ROOT_REF)
- .addChildren(
- builder(SUBVIEW, SUBVIEW_REF)
- .addChildren(
- builder(SUBVIEW, SUB_SUBVIEW_1_REF)
- .addChildren(
- builder(PROJECT_VIEW, PROJECT_VIEW_1_REF).build())
- .build(),
- builder(SUBVIEW, SUB_SUBVIEW_2_REF)
- .addChildren(
- builder(PROJECT_VIEW, PROJECT_VIEW_2_REF).build(),
- builder(PROJECT_VIEW, PROJECT_VIEW_3_REF).build())
- .build(),
- builder(PROJECT_VIEW, PROJECT_VIEW_4_REF).build())
- .build())
- .build();
-
- @Rule
- public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
-
- @Rule
- public MetricRepositoryRule metricRepository = new MetricRepositoryRule()
- .add(CoreMetrics.NEW_LINES_TO_COVER)
- .add(CoreMetrics.NEW_UNCOVERED_LINES)
- .add(CoreMetrics.NEW_CONDITIONS_TO_COVER)
- .add(CoreMetrics.NEW_UNCOVERED_CONDITIONS)
- .add(CoreMetrics.NEW_COVERAGE)
- .add(CoreMetrics.NEW_BRANCH_COVERAGE)
- .add(CoreMetrics.NEW_LINE_COVERAGE);
- @Rule
- public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository);
-
- private NewCoverageMeasuresStep underTest = new NewCoverageMeasuresStep(treeRootHolder, measureRepository, metricRepository);
-
- @Test
- public void verify_aggregation_of_measures_for_new_conditions() {
- String newLinesToCover = CoreMetrics.NEW_LINES_TO_COVER_KEY;
- String newUncoveredLines = CoreMetrics.NEW_UNCOVERED_LINES_KEY;
- String newConditionsToCover = CoreMetrics.NEW_CONDITIONS_TO_COVER_KEY;
- String newUncoveredConditions = CoreMetrics.NEW_UNCOVERED_CONDITIONS_KEY;
-
- MetricKeys metricKeys = new MetricKeys(newLinesToCover, newUncoveredLines, newConditionsToCover, newUncoveredConditions);
-
- treeRootHolder.setRoot(VIEWS_TREE);
- // PROJECT_VIEW_1_REF has no measure
- 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(new TestComputationStepContext());
-
- assertNoAddedRawMeasureOnProjectViews();
- assertNoAddedRawMeasures(SUB_SUBVIEW_1_REF);
- assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_SUBVIEW_2_REF))).contains(
- 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)),
- entryOf(metricKeys.newUncoveredLines, createMeasure(60d)),
- entryOf(metricKeys.newConditionsToCover, createMeasure(42d)),
- entryOf(metricKeys.newUncoveredConditions, createMeasure(150d)));
- }
-
- @Test
- public void verify_aggregates_variations_for_new_code_line_and_branch_Coverage() {
- LinesAndConditionsWithUncoveredMetricKeys metricKeys = new LinesAndConditionsWithUncoveredMetricKeys(
- CoreMetrics.NEW_LINES_TO_COVER_KEY, CoreMetrics.NEW_CONDITIONS_TO_COVER_KEY,
- CoreMetrics.NEW_UNCOVERED_LINES_KEY, CoreMetrics.NEW_UNCOVERED_CONDITIONS_KEY);
- String codeCoverageKey = CoreMetrics.NEW_COVERAGE_KEY;
- String lineCoverageKey = CoreMetrics.NEW_LINE_COVERAGE_KEY;
- String branchCoverageKey = CoreMetrics.NEW_BRANCH_COVERAGE_KEY;
-
- verify_aggregates_variations(metricKeys, codeCoverageKey, lineCoverageKey, branchCoverageKey);
- }
-
- 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))
- .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))
- .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))
- .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(new TestComputationStepContext());
-
- assertNoAddedRawMeasureOnProjectViews();
-
- assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_SUBVIEW_1_REF))).contains(
- 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)),
- entryOf(lineCoverageKey, createMeasure(90d)),
- entryOf(branchCoverageKey, createMeasure(96d)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(SUBVIEW_REF))).contains(
- 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)),
- entryOf(lineCoverageKey, createMeasure(94.5d)),
- entryOf(branchCoverageKey, createMeasure(96.9d)));
- }
-
- private static final class MetricKeys {
- private final String newLinesToCover;
- private final String newUncoveredLines;
- private final String newConditionsToCover;
- private final String newUncoveredConditions;
-
- public MetricKeys(String newLinesToCover, String newUncoveredLines, String newConditionsToCover, String newUncoveredConditions) {
- this.newLinesToCover = newLinesToCover;
- this.newUncoveredLines = newUncoveredLines;
- this.newConditionsToCover = newConditionsToCover;
- this.newUncoveredConditions = newUncoveredConditions;
- }
- }
-
- private static Measure createMeasure(Double expectedVariation) {
- return newMeasureBuilder()
- .setVariation(expectedVariation)
- .createNoValue();
- }
-
- private void assertNoAddedRawMeasureOnProjectViews() {
- assertNoAddedRawMeasures(PROJECT_VIEW_1_REF);
- assertNoAddedRawMeasures(PROJECT_VIEW_2_REF);
- assertNoAddedRawMeasures(PROJECT_VIEW_3_REF);
- }
-
- private void assertNoAddedRawMeasures(int componentRef) {
- assertThat(measureRepository.getAddedRawMeasures(componentRef)).isEmpty();
- }
-
-}