From 0cfc4132e690b08efdf8ff7e38326b68312b806c Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 7 Feb 2017 17:08:27 +0100 Subject: [PATCH] SONAR-8743 Handle only leak period when computing new size measures --- .../step/NewSizeMeasuresStep.java | 134 +++++++---------- .../step/NewSizeMeasuresStepTest.java | 139 ++++++++---------- 2 files changed, 116 insertions(+), 157 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java index 5cbf0445e01..5728fd552c3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStep.java @@ -21,20 +21,12 @@ package org.sonar.server.computation.task.projectanalysis.step; import com.google.common.base.Optional; -import com.google.common.collect.HashMultiset; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; -import com.google.common.collect.LinkedHashMultimap; -import com.google.common.collect.Multiset; -import com.google.common.collect.SetMultimap; import java.util.HashSet; -import java.util.List; -import java.util.Map; import java.util.Set; -import java.util.function.Function; -import java.util.stream.Collectors; import java.util.stream.IntStream; +import java.util.stream.StreamSupport; import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.component.PathAwareCrawler; import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder; @@ -47,11 +39,9 @@ import org.sonar.server.computation.task.projectanalysis.formula.CounterInitiali import org.sonar.server.computation.task.projectanalysis.formula.CreateMeasureContext; import org.sonar.server.computation.task.projectanalysis.formula.Formula; import org.sonar.server.computation.task.projectanalysis.formula.FormulaExecutorComponentVisitor; -import org.sonar.server.computation.task.projectanalysis.formula.counter.DoubleVariationValue; import org.sonar.server.computation.task.projectanalysis.formula.counter.IntVariationValue; import org.sonar.server.computation.task.projectanalysis.measure.Measure; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepository; -import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepository; import org.sonar.server.computation.task.projectanalysis.period.Period; import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolder; @@ -60,7 +50,6 @@ import org.sonar.server.computation.task.projectanalysis.scm.ScmInfo; import org.sonar.server.computation.task.projectanalysis.scm.ScmInfoRepository; import org.sonar.server.computation.task.step.ComputationStep; -import static java.util.stream.Collectors.toMap; import static org.sonar.api.measures.CoreMetrics.NEW_BLOCKS_DUPLICATED_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY; import static org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_KEY; @@ -103,9 +92,9 @@ public class NewSizeMeasuresStep implements ComputationStep { private static class NewSizeCounter implements Counter { private final DuplicationRepository duplicationRepository; private final ScmInfoRepository scmInfoRepository; - private final IntVariationValue.Array newLines = IntVariationValue.newArray(); - private final IntVariationValue.Array newDuplicatedLines = IntVariationValue.newArray(); - private final IntVariationValue.Array newDuplicatedBlocks = IntVariationValue.newArray(); + private final IntVariationValue newLines = new IntVariationValue(); + private final IntVariationValue newDuplicatedLines = new IntVariationValue(); + private final IntVariationValue newDuplicatedBlocks = new IntVariationValue(); private NewSizeCounter(DuplicationRepository duplicationRepository, ScmInfoRepository scmInfoRepository) { @@ -115,40 +104,38 @@ public class NewSizeMeasuresStep implements ComputationStep { @Override public void aggregate(NewSizeCounter counter) { - this.newDuplicatedLines.incrementAll(counter.newDuplicatedLines); - this.newDuplicatedBlocks.incrementAll(counter.newDuplicatedBlocks); - this.newLines.incrementAll(counter.newLines); + this.newDuplicatedLines.increment(counter.newDuplicatedLines); + this.newDuplicatedBlocks.increment(counter.newDuplicatedBlocks); + this.newLines.increment(counter.newLines); } @Override public void initialize(CounterInitializationContext context) { Component leaf = context.getLeaf(); Optional scmInfo = scmInfoRepository.getScmInfo(leaf); - if (!scmInfo.isPresent()) { + if (!scmInfo.isPresent() || !context.hasPeriod()) { return; } - context.getPeriods().forEach(period -> newLines.increment(period, 0)); + newLines.increment(0); if (leaf.getType() != Component.Type.FILE) { - context.getPeriods().forEach(period -> { - newDuplicatedLines.increment(period, 0); - newDuplicatedBlocks.increment(period, 0); - }); + newDuplicatedLines.increment(0); + newDuplicatedBlocks.increment(0); return; } - initNewLines(scmInfo.get(), context.getPeriods()); - initNewDuplicated(leaf, scmInfo.get(), context.getPeriods()); + initNewLines(scmInfo.get(), context.getPeriod()); + initNewDuplicated(leaf, scmInfo.get(), context.getPeriod()); } - private void initNewLines(ScmInfo scmInfo, List periods) { - scmInfo.getAllChangesets().forEach(changeset -> periods.stream() - .filter(period -> isLineInPeriod(changeset, period)) - .forEach(period -> newLines.increment(period, 1))); + private void initNewLines(ScmInfo scmInfo, Period period) { + StreamSupport.stream(scmInfo.getAllChangesets().spliterator(), false) + .filter(changeset -> isLineInPeriod(changeset, period)) + .forEach(changeset -> newLines.increment(1)); } - private void initNewDuplicated(Component component, ScmInfo scmInfo, List periods) { - DuplicationCounters duplicationCounters = new DuplicationCounters(scmInfo, periods); + private void initNewDuplicated(Component component, ScmInfo scmInfo, Period period) { + DuplicationCounters duplicationCounters = new DuplicationCounters(scmInfo, period); Iterable duplications = duplicationRepository.getDuplications(component); for (Duplication duplication : duplications) { duplicationCounters.addBlock(duplication.getOriginal()); @@ -158,11 +145,8 @@ public class NewSizeMeasuresStep implements ComputationStep { .forEach(duplicate -> duplicationCounters.addBlock(duplicate.getTextBlock())); } - Map newLinesDuplicatedByPeriod = duplicationCounters.getNewLinesDuplicated(); - periods.forEach(period -> { - newDuplicatedLines.increment(period, newLinesDuplicatedByPeriod.getOrDefault(period, 0)); - newDuplicatedBlocks.increment(period, duplicationCounters.getNewBlocksDuplicated().getOrDefault(period, 0)); - }); + newDuplicatedLines.increment(duplicationCounters.getNewLinesDuplicated()); + newDuplicatedBlocks.increment(duplicationCounters.getNewBlocksDuplicated()); } private static boolean isLineInPeriod(Changeset changeset, Period period) { @@ -172,35 +156,35 @@ public class NewSizeMeasuresStep implements ComputationStep { private static class DuplicationCounters { private final ScmInfo scmInfo; - private final List periods; - private final SetMultimap lineCounts; - private final Multiset blockCounts; + private final Period period; + private final Set lineCounts; + private int blockCounts; - private DuplicationCounters(ScmInfo scmInfo, List periods) { + private DuplicationCounters(ScmInfo scmInfo, Period period) { this.scmInfo = scmInfo; - this.periods = periods; - this.lineCounts = LinkedHashMultimap.create(periods.size(), Iterables.size(scmInfo.getAllChangesets())); - this.blockCounts = HashMultiset.create(); + this.period = period; + this.lineCounts = new HashSet<>(Iterables.size(scmInfo.getAllChangesets())); } void addBlock(TextBlock textBlock) { - Set periodWithNewCode = new HashSet<>(); + Boolean[] newBlock = new Boolean[] {false}; IntStream.rangeClosed(textBlock.getStart(), textBlock.getEnd()) - .forEach(line -> periods.stream() - .filter(period -> isLineInPeriod(line, period)) - .forEach(period -> { - lineCounts.put(period, line); - periodWithNewCode.add(period); - })); - blockCounts.addAll(periodWithNewCode); + .filter(line -> isLineInPeriod(line, period)) + .forEach(line -> { + lineCounts.add(line); + newBlock[0] = true; + }); + if (newBlock[0]) { + blockCounts++; + } } - Map getNewLinesDuplicated() { - return ImmutableMap.copyOf(lineCounts.keySet().stream().collect(toMap(Function.identity(), period -> lineCounts.get(period).size()))); + int getNewLinesDuplicated() { + return lineCounts.size(); } - Map getNewBlocksDuplicated() { - return blockCounts.entrySet().stream().collect(Collectors.toMap(Multiset.Entry::getElement, Multiset.Entry::getCount)); + int getNewBlocksDuplicated() { + return blockCounts; } private boolean isLineInPeriod(int lineNumber, Period period) { @@ -228,40 +212,36 @@ public class NewSizeMeasuresStep implements ComputationStep { String metricKey = context.getMetric().getKey(); switch (metricKey) { case NEW_LINES_KEY: - return createMeasure(counter.newLines.toMeasureVariations()); + return createMeasure(counter.newLines); case NEW_DUPLICATED_LINES_KEY: - return createMeasure(counter.newDuplicatedLines.toMeasureVariations()); + return createMeasure(counter.newDuplicatedLines); case NEW_DUPLICATED_LINES_DENSITY_KEY: - return createNewDuplicatedLinesDensityMeasure(counter, context); + return createNewDuplicatedLinesDensityMeasure(counter); case NEW_BLOCKS_DUPLICATED_KEY: - return createMeasure(counter.newDuplicatedBlocks.toMeasureVariations()); + return createMeasure(counter.newDuplicatedBlocks); default: throw new IllegalArgumentException("Unsupported metric " + context.getMetric()); } } - private static Optional createMeasure(Optional measure) { - return measure.isPresent() - ? Optional.of(Measure.newMeasureBuilder().setVariations(measure.get()).createNoValue()) + private static Optional createMeasure(IntVariationValue intValue) { + return intValue.isSet() + ? Optional.of(Measure.newMeasureBuilder().setVariation(intValue.getValue()).createNoValue()) : Optional.absent(); } - private static Optional createNewDuplicatedLinesDensityMeasure(NewSizeCounter counter, CreateMeasureContext context) { - Optional newLines = counter.newLines.toMeasureVariations(); - Optional newDuplicatedLines = counter.newDuplicatedLines.toMeasureVariations(); - DoubleVariationValue.Array newDuplicatedLinesDensity = DoubleVariationValue.newArray(); - if (newLines.isPresent() && newDuplicatedLines.isPresent()) { - MeasureVariations newLinesVariations = newLines.get(); - MeasureVariations newDuplicatedLinesVariations = newDuplicatedLines.get(); - for (Period period : context.getPeriods()) { - double currentNewLines = newLinesVariations.getVariation(period.getIndex()); - if (currentNewLines > 0d) { - double density = Math.min(100d, 100d * newDuplicatedLinesVariations.getVariation(period.getIndex()) / currentNewLines); - newDuplicatedLinesDensity.increment(period, density); - } + private static Optional createNewDuplicatedLinesDensityMeasure(NewSizeCounter counter) { + IntVariationValue newLines = counter.newLines; + IntVariationValue newDuplicatedLines = counter.newDuplicatedLines; + if (newLines.isSet() && newDuplicatedLines.isSet()) { + int newLinesVariations = newLines.getValue(); + int newDuplicatedLinesVariations = newDuplicatedLines.getValue(); + if (newLinesVariations > 0d) { + double density = Math.min(100d, 100d * newDuplicatedLinesVariations / newLinesVariations); + return Optional.of(Measure.newMeasureBuilder().setVariation(density).createNoValue()); } } - return createMeasure(newDuplicatedLinesDensity.toMeasureVariations()); + return Optional.absent(); } @Override diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStepTest.java index 227b7b6c0ed..9e0ce3c5979 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/NewSizeMeasuresStepTest.java @@ -21,7 +21,6 @@ package org.sonar.server.computation.task.projectanalysis.step; import java.util.Arrays; -import javax.annotation.Nullable; import org.assertj.core.data.Offset; import org.junit.Rule; import org.junit.Test; @@ -29,7 +28,6 @@ import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolde import org.sonar.server.computation.task.projectanalysis.duplication.DuplicationRepositoryRule; import org.sonar.server.computation.task.projectanalysis.duplication.TextBlock; import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule; -import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule; import org.sonar.server.computation.task.projectanalysis.period.Period; import org.sonar.server.computation.task.projectanalysis.period.PeriodsHolderRule; @@ -95,9 +93,8 @@ public class NewSizeMeasuresStepTest { .build()); @Rule - public PeriodsHolderRule periodsHolder = new PeriodsHolderRule().setPeriods( - new Period(2, "mode_p_1", null, parseDate("2009-12-25").getTime(), "u1"), - new Period(5, "mode_p_5", null, parseDate("2011-02-18").getTime(), "u2")); + public PeriodsHolderRule periodsHolder = new PeriodsHolderRule().setPeriod( + new Period("mode_p_1", null, parseDate("2009-12-25").getTime(), "u1")); @Rule public ScmInfoRepositoryRule scmInfoRepository = new ScmInfoRepositoryRule(); @@ -124,16 +121,16 @@ public class NewSizeMeasuresStepTest { underTest.execute(); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_LINES_KEY, 11); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_2_REF, NEW_LINES_KEY, 11); + assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_LINES_KEY, 11); + assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_LINES_KEY, 11); assertNoRawMeasure(FILE_3_REF, NEW_LINES_KEY); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_4_REF, NEW_LINES_KEY, 11); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(DIRECTORY_REF, NEW_LINES_KEY, 22); + assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_LINES_KEY, 11); + assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_LINES_KEY, 22); assertNoRawMeasure(DIRECTORY_2_REF, NEW_LINES_KEY); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(SUB_MODULE_1_REF, NEW_LINES_KEY, 22); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(SUB_MODULE_2_REF, NEW_LINES_KEY, 11); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(MODULE_REF, NEW_LINES_KEY, 33); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(ROOT_REF, NEW_LINES_KEY, 33); + assertRawMeasureValueOnPeriod(SUB_MODULE_1_REF, NEW_LINES_KEY, 22); + assertRawMeasureValueOnPeriod(SUB_MODULE_2_REF, NEW_LINES_KEY, 11); + assertRawMeasureValueOnPeriod(MODULE_REF, NEW_LINES_KEY, 33); + assertRawMeasureValueOnPeriod(ROOT_REF, NEW_LINES_KEY, 33); } @Test @@ -150,7 +147,7 @@ public class NewSizeMeasuresStepTest { underTest.execute(); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d); + assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d); } @Test @@ -161,7 +158,7 @@ public class NewSizeMeasuresStepTest { underTest.execute(); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1d); + assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1d); } @Test @@ -172,7 +169,7 @@ public class NewSizeMeasuresStepTest { underTest.execute(); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1d); + assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1d); } @Test @@ -183,7 +180,7 @@ public class NewSizeMeasuresStepTest { underTest.execute(); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 6d); + assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 6d); } @Test @@ -195,20 +192,7 @@ public class NewSizeMeasuresStepTest { underTest.execute(); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 11d); - } - - @Test - public void compute_new_duplicated_lines_on_different_periods() { - TextBlock original = new TextBlock(1, 1); - duplicationRepository.addDuplication(FILE_1_REF, original, new TextBlock(2, 2)); - scmInfoRepository.setScmInfo(FILE_1_REF, - Changeset.newChangesetBuilder().setDate(parseDate("2012-01-01").getTime()).setRevision("rev-1").build(), - Changeset.newChangesetBuilder().setDate(parseDate("2011-01-01").getTime()).setRevision("rev-2").build()); - - underTest.execute(); - - assertRawMeasureValue(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d, 1d); + assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 11d); } @Test @@ -223,16 +207,16 @@ public class NewSizeMeasuresStepTest { underTest.execute(); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_2_REF, NEW_DUPLICATED_LINES_KEY, 0d); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_3_REF, NEW_DUPLICATED_LINES_KEY, 9d); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_4_REF, NEW_DUPLICATED_LINES_KEY, 11d); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(DIRECTORY_REF, NEW_DUPLICATED_LINES_KEY, 2d); + assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d); + assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_DUPLICATED_LINES_KEY, 0d); + assertRawMeasureValueOnPeriod(FILE_3_REF, NEW_DUPLICATED_LINES_KEY, 9d); + assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_DUPLICATED_LINES_KEY, 11d); + assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_DUPLICATED_LINES_KEY, 2d); assertNoRawMeasure(DIRECTORY_2_REF, NEW_DUPLICATED_LINES_KEY); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(SUB_MODULE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(SUB_MODULE_2_REF, NEW_DUPLICATED_LINES_KEY, 20d); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(MODULE_REF, NEW_DUPLICATED_LINES_KEY, 22d); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(ROOT_REF, NEW_DUPLICATED_LINES_KEY, 22d); + assertRawMeasureValueOnPeriod(SUB_MODULE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d); + assertRawMeasureValueOnPeriod(SUB_MODULE_2_REF, NEW_DUPLICATED_LINES_KEY, 20d); + assertRawMeasureValueOnPeriod(MODULE_REF, NEW_DUPLICATED_LINES_KEY, 22d); + assertRawMeasureValueOnPeriod(ROOT_REF, NEW_DUPLICATED_LINES_KEY, 22d); } @Test @@ -255,7 +239,7 @@ public class NewSizeMeasuresStepTest { underTest.execute(); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4); + assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4); } @Test @@ -266,7 +250,7 @@ public class NewSizeMeasuresStepTest { underTest.execute(); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4); + assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4); } @Test @@ -276,7 +260,7 @@ public class NewSizeMeasuresStepTest { underTest.execute(); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1); + assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1); } @Test @@ -286,7 +270,7 @@ public class NewSizeMeasuresStepTest { underTest.execute(); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1); + assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1); } @Test @@ -298,15 +282,15 @@ public class NewSizeMeasuresStepTest { underTest.execute(); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 10); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_2_REF, NEW_BLOCKS_DUPLICATED_KEY, 2); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_3_REF, NEW_BLOCKS_DUPLICATED_KEY, 0); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_4_REF, NEW_BLOCKS_DUPLICATED_KEY, 6); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(DIRECTORY_REF, NEW_BLOCKS_DUPLICATED_KEY, 12); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(SUB_MODULE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 12); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(SUB_MODULE_2_REF, NEW_BLOCKS_DUPLICATED_KEY, 6); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(MODULE_REF, NEW_BLOCKS_DUPLICATED_KEY, 18); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(ROOT_REF, NEW_BLOCKS_DUPLICATED_KEY, 18); + assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 10); + assertRawMeasureValueOnPeriod(FILE_2_REF, NEW_BLOCKS_DUPLICATED_KEY, 2); + assertRawMeasureValueOnPeriod(FILE_3_REF, NEW_BLOCKS_DUPLICATED_KEY, 0); + assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_BLOCKS_DUPLICATED_KEY, 6); + assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_BLOCKS_DUPLICATED_KEY, 12); + assertRawMeasureValueOnPeriod(SUB_MODULE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 12); + assertRawMeasureValueOnPeriod(SUB_MODULE_2_REF, NEW_BLOCKS_DUPLICATED_KEY, 6); + assertRawMeasureValueOnPeriod(MODULE_REF, NEW_BLOCKS_DUPLICATED_KEY, 18); + assertRawMeasureValueOnPeriod(ROOT_REF, NEW_BLOCKS_DUPLICATED_KEY, 18); } @Test @@ -327,16 +311,16 @@ public class NewSizeMeasuresStepTest { underTest.execute(); - assertRawMeasureValue(FILE_1_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 18.2d, null); - assertRawMeasureValue(FILE_2_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 0d, null); + assertRawMeasureValue(FILE_1_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 18.2d); + assertRawMeasureValue(FILE_2_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 0d); assertNoRawMeasure(FILE_3_REF, NEW_DUPLICATED_LINES_DENSITY_KEY); - assertRawMeasureValue(FILE_4_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 100d, null); - assertRawMeasureValue(DIRECTORY_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 9.1d, null); + assertRawMeasureValue(FILE_4_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 100d); + assertRawMeasureValue(DIRECTORY_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 9.1d); assertNoRawMeasure(DIRECTORY_2_REF, NEW_DUPLICATED_LINES_DENSITY_KEY); - assertRawMeasureValue(SUB_MODULE_1_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 9.1d, null); - assertRawMeasureValue(SUB_MODULE_2_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 100d, null); - assertRawMeasureValue(MODULE_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 39.4d, null); - assertRawMeasureValue(ROOT_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 39.4d, null); + assertRawMeasureValue(SUB_MODULE_1_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 9.1d); + assertRawMeasureValue(SUB_MODULE_2_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 100d); + assertRawMeasureValue(MODULE_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 39.4d); + assertRawMeasureValue(ROOT_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 39.4d); } @Test @@ -379,30 +363,25 @@ public class NewSizeMeasuresStepTest { Changeset.newChangesetBuilder().setDate(parseDate("2011-01-01").getTime()).setRevision("rev-1").build())); } - private void assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(int componentRef, String metricKey, double period2Value) { - assertRawMeasureValue(componentRef, metricKey, period2Value, 0d); + private void assertRawMeasureValueOnPeriod(int componentRef, String metricKey, double expectedVariation) { + assertRawMeasureValue(componentRef, metricKey, expectedVariation); } - private void assertRawMeasureValue(int componentRef, String metricKey, double period2Value, @Nullable Double period5Value) { - MeasureVariations variations = measureRepository.getAddedRawMeasure(componentRef, metricKey).get().getVariations(); - assertThat(variations.getVariation2()).isEqualTo(period2Value, DEFAULT_OFFSET); - if (period5Value != null) { - assertThat(variations.getVariation5()).isEqualTo(period5Value, DEFAULT_OFFSET); - } else { - assertThat(variations.hasVariation5()).isFalse(); - } + private void assertRawMeasureValue(int componentRef, String metricKey, double expectedVariation) { + double variation = measureRepository.getAddedRawMeasure(componentRef, metricKey).get().getVariation(); + assertThat(variation).isEqualTo(expectedVariation, DEFAULT_OFFSET); } private void assertComputedAndAggregatedToZeroInt(String metricKey) { - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, metricKey, 0); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_2_REF, metricKey, 0); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_3_REF, metricKey, 0); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_4_REF, metricKey, 0); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(DIRECTORY_REF, metricKey, 0); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(SUB_MODULE_1_REF, metricKey, 0); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(SUB_MODULE_2_REF, metricKey, 0); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(MODULE_REF, metricKey, 0); - assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(ROOT_REF, metricKey, 0); + assertRawMeasureValueOnPeriod(FILE_1_REF, metricKey, 0); + assertRawMeasureValueOnPeriod(FILE_2_REF, metricKey, 0); + assertRawMeasureValueOnPeriod(FILE_3_REF, metricKey, 0); + assertRawMeasureValueOnPeriod(FILE_4_REF, metricKey, 0); + assertRawMeasureValueOnPeriod(DIRECTORY_REF, metricKey, 0); + assertRawMeasureValueOnPeriod(SUB_MODULE_1_REF, metricKey, 0); + assertRawMeasureValueOnPeriod(SUB_MODULE_2_REF, metricKey, 0); + assertRawMeasureValueOnPeriod(MODULE_REF, metricKey, 0); + assertRawMeasureValueOnPeriod(ROOT_REF, metricKey, 0); } private void assertNoRawMeasure(int componentRef, String metricKey) { -- 2.39.5