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;
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;
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;
private static class NewSizeCounter implements Counter<NewSizeCounter> {
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) {
@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> 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<Period> 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<Period> periods) {
- DuplicationCounters duplicationCounters = new DuplicationCounters(scmInfo, periods);
+ private void initNewDuplicated(Component component, ScmInfo scmInfo, Period period) {
+ DuplicationCounters duplicationCounters = new DuplicationCounters(scmInfo, period);
Iterable<Duplication> duplications = duplicationRepository.getDuplications(component);
for (Duplication duplication : duplications) {
duplicationCounters.addBlock(duplication.getOriginal());
.forEach(duplicate -> duplicationCounters.addBlock(duplicate.getTextBlock()));
}
- Map<Period, Integer> 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) {
private static class DuplicationCounters {
private final ScmInfo scmInfo;
- private final List<Period> periods;
- private final SetMultimap<Period, Integer> lineCounts;
- private final Multiset<Period> blockCounts;
+ private final Period period;
+ private final Set<Integer> lineCounts;
+ private int blockCounts;
- private DuplicationCounters(ScmInfo scmInfo, List<Period> 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<Period> 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<Period, Integer> getNewLinesDuplicated() {
- return ImmutableMap.copyOf(lineCounts.keySet().stream().collect(toMap(Function.identity(), period -> lineCounts.get(period).size())));
+ int getNewLinesDuplicated() {
+ return lineCounts.size();
}
- Map<Period, Integer> 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) {
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<Measure> createMeasure(Optional<MeasureVariations> measure) {
- return measure.isPresent()
- ? Optional.of(Measure.newMeasureBuilder().setVariations(measure.get()).createNoValue())
+ private static Optional<Measure> createMeasure(IntVariationValue intValue) {
+ return intValue.isSet()
+ ? Optional.of(Measure.newMeasureBuilder().setVariation(intValue.getValue()).createNoValue())
: Optional.absent();
}
- private static Optional<Measure> createNewDuplicatedLinesDensityMeasure(NewSizeCounter counter, CreateMeasureContext context) {
- Optional<MeasureVariations> newLines = counter.newLines.toMeasureVariations();
- Optional<MeasureVariations> 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<Measure> 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
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;
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;
.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();
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
underTest.execute();
- assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d);
+ assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d);
}
@Test
underTest.execute();
- assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1d);
+ assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1d);
}
@Test
underTest.execute();
- assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1d);
+ assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 1d);
}
@Test
underTest.execute();
- assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 6d);
+ assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_DUPLICATED_LINES_KEY, 6d);
}
@Test
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
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
underTest.execute();
- assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4);
+ assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4);
}
@Test
underTest.execute();
- assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4);
+ assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 4);
}
@Test
underTest.execute();
- assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1);
+ assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1);
}
@Test
underTest.execute();
- assertRawMeasureValueOnPeriod2AndZeroOnPeriod5(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1);
+ assertRawMeasureValueOnPeriod(FILE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 1);
}
@Test
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
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
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) {