package org.sonar.server.computation.task.projectanalysis.formula;
import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
import org.sonar.server.computation.task.projectanalysis.formula.counter.DoubleVariationValue;
import org.sonar.server.computation.task.projectanalysis.measure.Measure;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
-import static com.google.common.collect.FluentIterable.from;
import static java.util.Objects.requireNonNull;
import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
*/
public class VariationSumFormula implements Formula<VariationSumFormula.VariationSumCounter> {
private final String metricKey;
- private final Predicate<Period> supportedPeriods;
@CheckForNull
private final Double defaultInputValue;
- public VariationSumFormula(String metricKey, Predicate<Period> supportedPeriods) {
- this(metricKey, supportedPeriods, null);
+ public VariationSumFormula(String metricKey) {
+ this(metricKey, null);
}
- public VariationSumFormula(String metricKey, Predicate<Period> supportedPeriods, @Nullable Double defaultInputValue) {
+ public VariationSumFormula(String metricKey, @Nullable Double defaultInputValue) {
this.metricKey = requireNonNull(metricKey, "Metric key cannot be null");
- this.supportedPeriods = requireNonNull(supportedPeriods, "Period predicate cannot be null");
this.defaultInputValue = defaultInputValue;
}
@Override
public VariationSumCounter createNewCounter() {
- return new VariationSumCounter(metricKey, supportedPeriods, defaultInputValue);
+ return new VariationSumCounter(metricKey, defaultInputValue);
}
@Override
public Optional<Measure> createMeasure(VariationSumCounter counter, CreateMeasureContext context) {
- if (!CrawlerDepthLimit.LEAVES.isDeeperThan(context.getComponent().getType())) {
+ if (!CrawlerDepthLimit.LEAVES.isDeeperThan(context.getComponent().getType()) || !counter.doubleValue.isSet()) {
return Optional.absent();
}
- MeasureVariations.Builder variations = createAndPopulateBuilder(counter.array, context);
- if (variations.isEmpty()) {
- return Optional.absent();
- }
- return Optional.of(newMeasureBuilder().setVariations(variations.build()).createNoValue());
- }
-
- private MeasureVariations.Builder createAndPopulateBuilder(DoubleVariationValue.Array array, CreateMeasureContext context) {
- MeasureVariations.Builder builder = MeasureVariations.newMeasureVariationsBuilder();
- for (Period period : from(context.getPeriods()).filter(supportedPeriods)) {
- DoubleVariationValue elements = array.get(period);
- if (elements.isSet()) {
- builder.setVariation(period, elements.getValue());
- }
- }
- return builder;
+ return Optional.of(newMeasureBuilder().setVariation(counter.doubleValue.getValue()).createNoValue());
}
@Override
public static final class VariationSumCounter implements Counter<VariationSumCounter> {
@CheckForNull
private final Double defaultInputValue;
- private final DoubleVariationValue.Array array = DoubleVariationValue.newArray();
+ private final DoubleVariationValue doubleValue = new DoubleVariationValue();
private final String metricKey;
- private final Predicate<Period> supportedPeriods;
- private VariationSumCounter(String metricKey, Predicate<Period> supportedPeriods, @Nullable Double defaultInputValue) {
+ private VariationSumCounter(String metricKey, @Nullable Double defaultInputValue) {
this.metricKey = metricKey;
- this.supportedPeriods = supportedPeriods;
this.defaultInputValue = defaultInputValue;
}
@Override
public void aggregate(VariationSumCounter counter) {
- array.incrementAll(counter.array);
+ doubleValue.increment(counter.doubleValue);
}
@Override
public void initialize(CounterInitializationContext context) {
Optional<Measure> measure = context.getMeasure(metricKey);
- if (!measure.isPresent() || !measure.get().hasVariations()) {
- initializeWithDefaultInputValue(context);
+ if (!measure.isPresent() || !measure.get().hasVariation()) {
+ initializeWithDefaultInputValue();
return;
}
- MeasureVariations variations = measure.get().getVariations();
- for (Period period : from(context.getPeriods()).filter(supportedPeriods)) {
- if (variations.hasVariation(period.getIndex())) {
- double variation = variations.getVariation(period.getIndex());
- if (variation > 0) {
- array.increment(period, variation);
- } else if (defaultInputValue != null) {
- array.increment(period, defaultInputValue);
- }
- }
+ double variation = measure.get().getVariation();
+ if (variation > 0) {
+ doubleValue.increment(variation);
+ } else if (defaultInputValue != null) {
+ doubleValue.increment(defaultInputValue);
}
}
- private void initializeWithDefaultInputValue(CounterInitializationContext context) {
+ private void initializeWithDefaultInputValue() {
if (defaultInputValue == null) {
return;
}
- for (Period period : from(context.getPeriods()).filter(supportedPeriods)) {
- array.increment(period, defaultInputValue);
- }
+ doubleValue.increment(defaultInputValue);
}
}
}
package org.sonar.server.computation.task.projectanalysis.formula.coverage;
import com.google.common.base.Optional;
-import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.formula.CounterInitializationContext;
-import org.sonar.server.computation.task.projectanalysis.formula.CreateMeasureContext;
import org.sonar.server.computation.task.projectanalysis.measure.Measure;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
-import static com.google.common.collect.FluentIterable.from;
import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
-import static org.sonar.server.computation.task.projectanalysis.period.PeriodPredicates.viewsRestrictedPeriods;
public final class CoverageUtils {
private static final Measure DEFAULT_MEASURE = newMeasureBuilder().create(0L);
- private static final MeasureVariations DEFAULT_VARIATIONS = new MeasureVariations(0d, 0d, 0d, 0d, 0d);
private CoverageUtils() {
// prevents instantiation
return measure.getLongValue();
}
- static MeasureVariations getMeasureVariations(CounterInitializationContext counterContext, String metricKey) {
+ static double getMeasureVariations(CounterInitializationContext counterContext, String metricKey) {
Optional<Measure> measure = counterContext.getMeasure(metricKey);
- if (!measure.isPresent() || !measure.get().hasVariations()) {
- return DEFAULT_VARIATIONS;
+ if (!measure.isPresent() || !measure.get().hasVariation()) {
+ return 0d;
}
- return measure.get().getVariations();
- }
-
- static long getLongVariation(MeasureVariations variations, Period period) {
- if (variations.hasVariation(period.getIndex())) {
- return (long) variations.getVariation(period.getIndex());
- }
- return 0L;
- }
-
- /**
- * Since Periods 4 and 5 can be customized per project and/or per view/subview, aggregating values on this period
- * will only generate garbage data which will make no sense. These Periods should be ignored when processing views/subviews.
- */
- static Iterable<Period> supportedPeriods(CreateMeasureContext context) {
- return supportedPeriods(context.getComponent().getType(), context.getPeriods());
- }
-
- /**
- * Since Periods 4 and 5 can be customized per project and/or per view/subview, aggregating values on this period
- * will only generate garbage data which will make no sense. These Periods should be ignored when processing views/subviews.
- */
- public static Iterable<Period> supportedPeriods(CounterInitializationContext context) {
- return supportedPeriods(context.getLeaf().getType(), context.getPeriods());
- }
-
- private static Iterable<Period> supportedPeriods(Component.Type type, Iterable<Period> periods) {
- if (type.isReportType()) {
- return periods;
- }
- return from(periods).filter(viewsRestrictedPeriods());
+ return measure.get().getVariation();
}
}
import org.sonar.server.computation.task.projectanalysis.formula.Formula;
import org.sonar.server.computation.task.projectanalysis.formula.counter.LongVariationValue;
import org.sonar.server.computation.task.projectanalysis.measure.Measure;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.calculateCoverage;
-import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.supportedPeriods;
import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
/**
@Override
public Optional<Measure> createMeasure(T counter, CreateMeasureContext context) {
- MeasureVariations.Builder builder = createAndPopulateBuilder(counter, context);
- if (!builder.isEmpty()) {
- return Optional.of(newMeasureBuilder().setVariations(builder.build()).createNoValue());
+ LongVariationValue elements = counter.elements;
+ if (elements.isSet() && elements.getValue() > 0d) {
+ LongVariationValue coveredElements = counter.coveredElements;
+ double variation = calculateCoverage(coveredElements.getValue(), elements.getValue());
+ return Optional.of(newMeasureBuilder().setVariation(variation).createNoValue());
}
-
return Optional.absent();
}
- private MeasureVariations.Builder createAndPopulateBuilder(T counter, CreateMeasureContext context) {
- MeasureVariations.Builder builder = MeasureVariations.newMeasureVariationsBuilder();
- for (Period period : supportedPeriods(context)) {
- LongVariationValue elements = counter.elements.get(period);
- if (elements.isSet() && elements.getValue() > 0d) {
- LongVariationValue coveredElements = counter.coveredElements.get(period);
- builder.setVariation(period, calculateCoverage(coveredElements.getValue(), elements.getValue()));
- }
- }
- return builder;
- }
}
* A counter used to create measure variations which are based on a count of elements and coveredElements.
*/
public abstract class ElementsAndCoveredElementsVariationCounter implements Counter<ElementsAndCoveredElementsVariationCounter> {
- protected final LongVariationValue.Array elements = LongVariationValue.newArray();
- protected final LongVariationValue.Array coveredElements = LongVariationValue.newArray();
+ protected final LongVariationValue elements = new LongVariationValue();
+ protected final LongVariationValue coveredElements = new LongVariationValue();
@Override
public void aggregate(ElementsAndCoveredElementsVariationCounter counter) {
- elements.incrementAll(counter.elements);
- coveredElements.incrementAll(counter.coveredElements);
+ elements.increment(counter.elements);
+ coveredElements.increment(counter.coveredElements);
}
@Override
import com.google.common.base.Optional;
import org.sonar.server.computation.task.projectanalysis.formula.CounterInitializationContext;
import org.sonar.server.computation.task.projectanalysis.measure.Measure;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
-
-import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getLongVariation;
-import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.supportedPeriods;
public final class LinesAndConditionsWithUncoveredVariationCounter extends ElementsAndCoveredElementsVariationCounter {
private final LinesAndConditionsWithUncoveredMetricKeys metricKeys;
@Override
public void initializeForSupportedLeaf(CounterInitializationContext counterContext) {
Optional<Measure> newLinesMeasure = counterContext.getMeasure(metricKeys.getLines());
- if (!newLinesMeasure.isPresent() || !newLinesMeasure.get().hasVariations()) {
+ if (!newLinesMeasure.isPresent() || !newLinesMeasure.get().hasVariation()) {
return;
}
+ double newLines = newLinesMeasure.get().getVariation();
+ long newConditions = (long) CoverageUtils.getMeasureVariations(counterContext, metricKeys.getConditions());
+ long uncoveredLines = (long) CoverageUtils.getMeasureVariations(counterContext, metricKeys.getUncoveredLines());
+ long uncoveredConditions = (long) CoverageUtils.getMeasureVariations(counterContext, metricKeys.getUncoveredConditions());
- MeasureVariations newLines = newLinesMeasure.get().getVariations();
- MeasureVariations newConditions = CoverageUtils.getMeasureVariations(counterContext, metricKeys.getConditions());
- MeasureVariations uncoveredLines = CoverageUtils.getMeasureVariations(counterContext, metricKeys.getUncoveredLines());
- MeasureVariations uncoveredConditions = CoverageUtils.getMeasureVariations(counterContext, metricKeys.getUncoveredConditions());
- for (Period period : supportedPeriods(counterContext)) {
- if (!newLines.hasVariation(period.getIndex())) {
- continue;
- }
- long elements = (long) newLines.getVariation(period.getIndex()) + getLongVariation(newConditions, period);
- this.elements.increment(period, elements);
- coveredElements.increment(
- period,
- elements - getLongVariation(uncoveredConditions, period) - getLongVariation(uncoveredLines, period));
- }
+ long elements = (long) newLines + newConditions;
+ this.elements.increment(elements);
+ coveredElements.increment(elements - uncoveredConditions - uncoveredLines);
}
}
package org.sonar.server.computation.task.projectanalysis.formula.coverage;
import org.sonar.server.computation.task.projectanalysis.formula.CounterInitializationContext;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
import static java.util.Objects.requireNonNull;
-import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getLongVariation;
import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getMeasureVariations;
-import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.supportedPeriods;
public final class SingleWithUncoveredVariationCounter extends ElementsAndCoveredElementsVariationCounter {
private final SingleWithUncoveredMetricKeys metricKeys;
@Override
protected void initializeForSupportedLeaf(CounterInitializationContext counterContext) {
- MeasureVariations newConditions = getMeasureVariations(counterContext, metricKeys.getCovered());
- MeasureVariations uncoveredConditions = getMeasureVariations(counterContext, metricKeys.getUncovered());
- for (Period period : supportedPeriods(counterContext)) {
- long elements = getLongVariation(newConditions, period);
- this.elements.increment(period, elements);
- coveredElements.increment(period, elements - getLongVariation(uncoveredConditions, period));
- }
+ long newConditions = (long) getMeasureVariations(counterContext, metricKeys.getCovered());
+ long uncoveredConditions = (long) getMeasureVariations(counterContext, metricKeys.getUncovered());
+ this.elements.increment(newConditions);
+ coveredElements.increment(newConditions - uncoveredConditions);
}
}
import org.sonar.server.computation.task.projectanalysis.formula.coverage.SingleWithUncoveredVariationFormula;
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.Metric;
import org.sonar.server.computation.task.projectanalysis.metric.MetricRepository;
import org.sonar.server.computation.task.projectanalysis.period.Period;
import org.sonar.server.computation.task.step.ComputationStep;
import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
-import static org.sonar.server.computation.task.projectanalysis.period.PeriodPredicates.viewsRestrictedPeriods;
/**
* Computes measures related to the New Coverage. These measures do not have values, only variations.
*/
private static Iterable<Formula<?>> variationSumFormulas(NewCoverageOutputMetricKeys outputMetricKeys) {
return ImmutableList.of(
- new VariationSumFormula(outputMetricKeys.getNewLinesToCover(), viewsRestrictedPeriods()),
- new VariationSumFormula(outputMetricKeys.getNewUncoveredLines(), viewsRestrictedPeriods()),
- new VariationSumFormula(outputMetricKeys.getNewConditionsToCover(), viewsRestrictedPeriods()),
- new VariationSumFormula(outputMetricKeys.getNewUncoveredConditions(), viewsRestrictedPeriods()));
+ new VariationSumFormula(outputMetricKeys.getNewLinesToCover()),
+ new VariationSumFormula(outputMetricKeys.getNewUncoveredLines()),
+ new VariationSumFormula(outputMetricKeys.getNewConditionsToCover()),
+ new VariationSumFormula(outputMetricKeys.getNewUncoveredConditions()));
}
}
@Override
public Optional<Measure> createMeasure(NewCoverageCounter counter, CreateMeasureContext context) {
- MeasureVariations.Builder builder = MeasureVariations.newMeasureVariationsBuilder();
- for (Period period : context.getPeriods()) {
- if (counter.hasNewCode(period)) {
- int value = computeValueForMetric(counter, period, context.getMetric());
- builder.setVariation(period, value);
- }
+ if (counter.hasNewCode()) {
+ int value = computeValueForMetric(counter, context.getMetric());
+ return Optional.of(newMeasureBuilder().setVariation(value).createNoValue());
}
- if (builder.isEmpty()) {
- return Optional.absent();
- }
- return Optional.of(newMeasureBuilder().setVariations(builder.build()).createNoValue());
+ return Optional.absent();
}
- private int computeValueForMetric(NewCoverageCounter counter, Period period, Metric metric) {
+ private int computeValueForMetric(NewCoverageCounter counter, Metric metric) {
if (metric.getKey().equals(outputMetricKeys.getNewLinesToCover())) {
- return counter.getNewLines(period);
+ return counter.getNewLines();
}
if (metric.getKey().equals(outputMetricKeys.getNewUncoveredLines())) {
- return counter.getNewLines(period) - counter.getNewCoveredLines(period);
+ return counter.getNewLines() - counter.getNewCoveredLines();
}
if (metric.getKey().equals(outputMetricKeys.getNewConditionsToCover())) {
- return counter.getNewConditions(period);
+ return counter.getNewConditions();
}
if (metric.getKey().equals(outputMetricKeys.getNewUncoveredConditions())) {
- return counter.getNewConditions(period) - counter.getNewCoveredConditions(period);
+ return counter.getNewConditions() - counter.getNewCoveredConditions();
}
throw new IllegalArgumentException("Unsupported metric " + metric.getKey());
}
}
public static final class NewCoverageCounter implements org.sonar.server.computation.task.projectanalysis.formula.Counter<NewCoverageCounter> {
- private final IntVariationValue.Array newLines = IntVariationValue.newArray();
- private final IntVariationValue.Array newCoveredLines = IntVariationValue.newArray();
- private final IntVariationValue.Array newConditions = IntVariationValue.newArray();
- private final IntVariationValue.Array newCoveredConditions = IntVariationValue.newArray();
+ private final IntVariationValue newLines = new IntVariationValue();
+ private final IntVariationValue newCoveredLines = new IntVariationValue();
+ private final IntVariationValue newConditions = new IntVariationValue();
+ private final IntVariationValue newCoveredConditions = new IntVariationValue();
private final ScmInfoRepository scmInfoRepository;
private final NewCoverageInputMetricKeys metricKeys;
@Override
public void aggregate(NewCoverageCounter counter) {
- newLines.incrementAll(counter.newLines);
- newCoveredLines.incrementAll(counter.newCoveredLines);
- newConditions.incrementAll(counter.newConditions);
- newCoveredConditions.incrementAll(counter.newCoveredConditions);
+ newLines.increment(counter.newLines);
+ newCoveredLines.increment(counter.newCoveredLines);
+ newConditions.increment(counter.newConditions);
+ newCoveredConditions.increment(counter.newCoveredConditions);
}
@Override
public void initialize(CounterInitializationContext context) {
Component fileComponent = context.getLeaf();
Optional<ScmInfo> scmInfoOptional = scmInfoRepository.getScmInfo(fileComponent);
- if (!scmInfoOptional.isPresent()) {
+ if (!scmInfoOptional.isPresent() || !context.hasPeriod()) {
return;
}
ScmInfo componentScm = scmInfoOptional.get();
- context.getPeriods().forEach(period -> {
- newLines.increment(period, 0);
- newCoveredLines.increment(period, 0);
- newConditions.increment(period, 0);
- newCoveredConditions.increment(period, 0);
- });
+ newLines.increment(0);
+ newCoveredLines.increment(0);
+ newConditions.increment(0);
+ newCoveredConditions.increment(0);
Optional<Measure> hitsByLineMeasure = context.getMeasure(metricKeys.getCoverageLineHitsData());
Map<Integer, Integer> hitsByLine = parseCountByLine(hitsByLineMeasure);
int conditions = (Integer) ObjectUtils.defaultIfNull(conditionsByLine.get(lineId), 0);
int coveredConditions = (Integer) ObjectUtils.defaultIfNull(coveredConditionsByLine.get(lineId), 0);
long date = componentScm.getChangesetForLine(lineId).getDate();
- analyze(context.getPeriods(), date, hits, conditions, coveredConditions);
+ analyze(context.getPeriod(), date, hits, conditions, coveredConditions);
}
}
return Collections.emptyMap();
}
- public void analyze(List<Period> periods, @Nullable Long lineDate, int hits, int conditions, int coveredConditions) {
+ void analyze(Period period, @Nullable Long lineDate, int hits, int conditions, int coveredConditions) {
if (lineDate == null) {
return;
}
- for (Period period : periods) {
- if (isLineInPeriod(lineDate, period)) {
- incrementLines(period, hits);
- incrementConditions(period, conditions, coveredConditions);
- }
+ if (isLineInPeriod(lineDate, period)) {
+ incrementLines(hits);
+ incrementConditions(conditions, coveredConditions);
}
}
return lineDate > period.getSnapshotDate();
}
- private void incrementLines(Period period, int hits) {
- newLines.increment(period, 1);
+ private void incrementLines(int hits) {
+ newLines.increment(1);
if (hits > 0) {
- newCoveredLines.increment(period, 1);
+ newCoveredLines.increment(1);
}
}
- private void incrementConditions(Period period, int conditions, int coveredConditions) {
- newConditions.increment(period, conditions);
+ private void incrementConditions(int conditions, int coveredConditions) {
+ newConditions.increment(conditions);
if (conditions > 0) {
- newCoveredConditions.increment(period, coveredConditions);
+ newCoveredConditions.increment(coveredConditions);
}
}
- public boolean hasNewCode(Period period) {
- return newLines.get(period).isSet();
+ boolean hasNewCode() {
+ return newLines.isSet();
}
- public int getNewLines(Period period) {
- return newLines.get(period).getValue();
+ int getNewLines() {
+ return newLines.getValue();
}
- public int getNewCoveredLines(Period period) {
- return newCoveredLines.get(period).getValue();
+ int getNewCoveredLines() {
+ return newCoveredLines.getValue();
}
- public int getNewConditions(Period period) {
- return newConditions.get(period).getValue();
+ int getNewConditions() {
+ return newConditions.getValue();
}
- public int getNewCoveredConditions(Period period) {
- return newCoveredConditions.get(period).getValue();
+ int getNewCoveredConditions() {
+ return newCoveredConditions.getValue();
}
}
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.formula.CounterInitializationContext;
import org.sonar.server.computation.task.projectanalysis.measure.Measure;
-import org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations;
import org.sonar.server.computation.task.projectanalysis.period.Period;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getLongMeasureValue;
-import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getLongVariation;
import static org.sonar.server.computation.task.projectanalysis.formula.coverage.CoverageUtils.getMeasureVariations;
import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
public class CoverageUtilsTest {
private static final String SOME_METRIC_KEY = "some key";
- public static final MeasureVariations DEFAULT_VARIATIONS = new MeasureVariations(0d, 0d, 0d, 0d, 0d);
+ public static final double DEFAULT_VARIATION = 0d;
@Rule
public CounterInitializationContextRule fileAggregateContext = new CounterInitializationContextRule();
@Test
public void getMeasureVariations_returns_0_in_all_MeasureVariations_if_there_is_no_measure() {
- assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(DEFAULT_VARIATIONS);
+ assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(DEFAULT_VARIATION);
}
@Test
public void getMeasureVariations_returns_0_in_all_MeasureVariations_if_there_is_measure_has_no_variations() {
fileAggregateContext.put(SOME_METRIC_KEY, newMeasureBuilder().createNoValue());
- assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(DEFAULT_VARIATIONS);
+ assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(DEFAULT_VARIATION);
}
@Test
public void getMeasureVariations_returns_MeasureVariations_of_measure_when_it_has_one() {
- MeasureVariations measureVariations = new MeasureVariations(null, 5d, null, null);
- fileAggregateContext.put(SOME_METRIC_KEY, newMeasureBuilder().setVariations(measureVariations).createNoValue());
+ fileAggregateContext.put(SOME_METRIC_KEY, newMeasureBuilder().setVariation(5d).createNoValue());
- assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isSameAs(measureVariations);
- }
-
- @Test
- public void getLongVariation_returns_0_if_MeasureVariation_has_none_for_the_specified_period() {
- MeasureVariations variations = new MeasureVariations(null, 2d, null, null, 5d);
-
- assertThat(getLongVariation(variations, createPeriod(1))).isEqualTo(0L);
- assertThat(getLongVariation(variations, createPeriod(2))).isEqualTo(2L);
- assertThat(getLongVariation(variations, createPeriod(3))).isEqualTo(0L);
- assertThat(getLongVariation(variations, createPeriod(4))).isEqualTo(0L);
- assertThat(getLongVariation(variations, createPeriod(5))).isEqualTo(5L);
- }
-
- private Period createPeriod(int periodIndex) {
- return new Period(periodIndex, "mode" + periodIndex, null, 963L + periodIndex, String.valueOf(9865L + periodIndex));
+ assertThat(getMeasureVariations(fileAggregateContext, SOME_METRIC_KEY)).isEqualTo(5d);
}
private static class CounterInitializationContextRule extends ExternalResource implements CounterInitializationContext {
*/
package org.sonar.server.computation.task.projectanalysis.step;
-import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.server.computation.task.projectanalysis.measure.Measure;
import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepoEntry;
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;
import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
import static org.sonar.server.computation.task.projectanalysis.measure.MeasureRepoEntry.entryOf;
import static org.sonar.server.computation.task.projectanalysis.measure.MeasureRepoEntry.toEntries;
-import static org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations.newMeasureVariationsBuilder;
public class ReportNewCoverageMeasuresStepTest {
@Before
public void setUp() {
- periodsHolder.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"));
+ periodsHolder.setPeriod(new Period("mode_p_1", null, parseDate("2009-12-25").getTime(), "u1"));
}
@Test
underTest.execute();
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_COMPONENT.getReportAttributes().getRef()))).contains(
- entryOf(newLinesToCover, createMeasure(2d, 0d)),
- entryOf(newUncoveredLines, createMeasure(1d, 0d)),
- entryOf(newConditionsToCover, createMeasure(0d, 0d)),
- entryOf(newUncoveredConditions, createMeasure(0d, 0d)));
+ entryOf(newLinesToCover, createMeasure(2d)),
+ entryOf(newUncoveredLines, createMeasure(1d)),
+ entryOf(newConditionsToCover, createMeasure(0d)),
+ entryOf(newUncoveredConditions, createMeasure(0d)));
}
@Test
// files
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_1_REF))).contains(
- entryOf(metricKeys.newLinesToCover, createMeasure(5d, 3d)),
- entryOf(metricKeys.newUncoveredLines, createMeasure(3d, 2d)),
- entryOf(metricKeys.newConditionsToCover, createMeasure(7d, 3d)),
- entryOf(metricKeys.newUncoveredConditions, createMeasure(4d, 1d)));
+ entryOf(metricKeys.newLinesToCover, createMeasure(5d)),
+ entryOf(metricKeys.newUncoveredLines, createMeasure(3d)),
+ entryOf(metricKeys.newConditionsToCover, createMeasure(7d)),
+ entryOf(metricKeys.newUncoveredConditions, createMeasure(4d)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_2_REF))).contains(
- entryOf(metricKeys.newLinesToCover, createMeasure(5d, 3d)),
- entryOf(metricKeys.newUncoveredLines, createMeasure(4d, 2d)),
- entryOf(metricKeys.newConditionsToCover, createMeasure(27d, 13d)),
- entryOf(metricKeys.newUncoveredConditions, createMeasure(14d, 6d)));
+ entryOf(metricKeys.newLinesToCover, createMeasure(5d)),
+ entryOf(metricKeys.newUncoveredLines, createMeasure(4d)),
+ entryOf(metricKeys.newConditionsToCover, createMeasure(27d)),
+ entryOf(metricKeys.newUncoveredConditions, createMeasure(14d)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_3_REF))).contains(
- entryOf(metricKeys.newLinesToCover, createMeasure(5d, 3d)),
- entryOf(metricKeys.newUncoveredLines, createMeasure(2d, 1d)),
- entryOf(metricKeys.newConditionsToCover, createMeasure(17d, 13d)),
- entryOf(metricKeys.newUncoveredConditions, createMeasure(9d, 6d)));
+ entryOf(metricKeys.newLinesToCover, createMeasure(5d)),
+ entryOf(metricKeys.newUncoveredLines, createMeasure(2d)),
+ entryOf(metricKeys.newConditionsToCover, createMeasure(17d)),
+ entryOf(metricKeys.newUncoveredConditions, createMeasure(9d)));
// directories
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_1_REF))).contains(
- entryOf(metricKeys.newLinesToCover, createMeasure(5d, 3d)),
- entryOf(metricKeys.newUncoveredLines, createMeasure(3d, 2d)),
- entryOf(metricKeys.newConditionsToCover, createMeasure(7d, 3d)),
- entryOf(metricKeys.newUncoveredConditions, createMeasure(4d, 1d)));
+ entryOf(metricKeys.newLinesToCover, createMeasure(5d)),
+ entryOf(metricKeys.newUncoveredLines, createMeasure(3d)),
+ entryOf(metricKeys.newConditionsToCover, createMeasure(7d)),
+ entryOf(metricKeys.newUncoveredConditions, createMeasure(4d)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_2_REF))).contains(
- entryOf(metricKeys.newLinesToCover, createMeasure(10d, 6d)),
- entryOf(metricKeys.newUncoveredLines, createMeasure(6d, 3d)),
- entryOf(metricKeys.newConditionsToCover, createMeasure(44d, 26d)),
- entryOf(metricKeys.newUncoveredConditions, createMeasure(23d, 12d)));
+ entryOf(metricKeys.newLinesToCover, createMeasure(10d)),
+ entryOf(metricKeys.newUncoveredLines, createMeasure(6d)),
+ entryOf(metricKeys.newConditionsToCover, createMeasure(44d)),
+ entryOf(metricKeys.newUncoveredConditions, createMeasure(23d)));
// submodule
- MeasureRepoEntry[] repoEntriesFromSubModuleUp = {entryOf(metricKeys.newLinesToCover, createMeasure(15d, 9d)),
- entryOf(metricKeys.newUncoveredLines, createMeasure(9d, 5d)),
- entryOf(metricKeys.newConditionsToCover, createMeasure(51d, 29d)),
- entryOf(metricKeys.newUncoveredConditions, createMeasure(27d, 13d))};
+ MeasureRepoEntry[] repoEntriesFromSubModuleUp = {entryOf(metricKeys.newLinesToCover, createMeasure(15d)),
+ entryOf(metricKeys.newUncoveredLines, createMeasure(9d)),
+ entryOf(metricKeys.newConditionsToCover, createMeasure(51d)),
+ entryOf(metricKeys.newUncoveredConditions, createMeasure(27d))};
assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).contains(repoEntriesFromSubModuleUp);
// module
assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).contains(repoEntriesFromSubModuleUp);
private void verify_aggregates_variations(LinesAndConditionsWithUncoveredMetricKeys metricKeys, String codeCoverageKey, String lineCoverageKey, String branchCoverageKey) {
treeRootHolder.setRoot(MULTIPLE_FILES_TREE);
measureRepository
- .addRawMeasure(FILE_1_REF, metricKeys.getLines(), createMeasure(3000d, 2000d))
- .addRawMeasure(FILE_1_REF, metricKeys.getConditions(), createMeasure(300d, 400d))
- .addRawMeasure(FILE_1_REF, metricKeys.getUncoveredLines(), createMeasure(30d, 200d))
- .addRawMeasure(FILE_1_REF, metricKeys.getUncoveredConditions(), createMeasure(9d, 16d))
+ .addRawMeasure(FILE_1_REF, metricKeys.getLines(), createMeasure(3000d))
+ .addRawMeasure(FILE_1_REF, metricKeys.getConditions(), createMeasure(300d))
+ .addRawMeasure(FILE_1_REF, metricKeys.getUncoveredLines(), createMeasure(30d))
+ .addRawMeasure(FILE_1_REF, metricKeys.getUncoveredConditions(), createMeasure(9d))
- .addRawMeasure(FILE_2_REF, metricKeys.getLines(), createMeasure(2000d, 3000d))
- .addRawMeasure(FILE_2_REF, metricKeys.getConditions(), createMeasure(400d, 300d))
- .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredLines(), createMeasure(200d, 30d))
- .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredConditions(), createMeasure(16d, 9d));
+ .addRawMeasure(FILE_2_REF, metricKeys.getLines(), createMeasure(2000d))
+ .addRawMeasure(FILE_2_REF, metricKeys.getConditions(), createMeasure(400d))
+ .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredLines(), createMeasure(200d))
+ .addRawMeasure(FILE_2_REF, metricKeys.getUncoveredConditions(), createMeasure(16d));
underTest.execute();
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_1_REF))).containsOnly(
- entryOf(codeCoverageKey, createMeasure(98.8d, 91d)),
- entryOf(lineCoverageKey, createMeasure(99d, 90d)),
- entryOf(branchCoverageKey, createMeasure(97d, 96d)));
+ entryOf(codeCoverageKey, createMeasure(98.8d)),
+ entryOf(lineCoverageKey, createMeasure(99d)),
+ entryOf(branchCoverageKey, createMeasure(97d)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_2_REF))).containsOnly(
- entryOf(codeCoverageKey, createMeasure(91d, 98.8d)),
- entryOf(lineCoverageKey, createMeasure(90d, 99d)),
- entryOf(branchCoverageKey, createMeasure(96d, 97d)));
+ entryOf(codeCoverageKey, createMeasure(91d)),
+ entryOf(lineCoverageKey, createMeasure(90d)),
+ entryOf(branchCoverageKey, createMeasure(96d)));
assertThat(measureRepository.getAddedRawMeasures(FILE_3_REF)).isEmpty();
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_1_REF))).containsOnly(
- entryOf(codeCoverageKey, createMeasure(98.8d, 91d)),
- entryOf(lineCoverageKey, createMeasure(99d, 90d)),
- entryOf(branchCoverageKey, createMeasure(97d, 96d)));
+ entryOf(codeCoverageKey, createMeasure(98.8d)),
+ entryOf(lineCoverageKey, createMeasure(99d)),
+ entryOf(branchCoverageKey, createMeasure(97d)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_2_REF))).containsOnly(
- entryOf(codeCoverageKey, createMeasure(91d, 98.8d)),
- entryOf(lineCoverageKey, createMeasure(90d, 99d)),
- entryOf(branchCoverageKey, createMeasure(96d, 97d)));
+ entryOf(codeCoverageKey, createMeasure(91d)),
+ entryOf(lineCoverageKey, createMeasure(90d)),
+ entryOf(branchCoverageKey, createMeasure(96d)));
MeasureRepoEntry[] modulesAndProjectEntries = {
- entryOf(codeCoverageKey, createMeasure(95.5d, 95.5d)),
- entryOf(lineCoverageKey, createMeasure(95.4d, 95.4d)),
- entryOf(branchCoverageKey, createMeasure(96.4d, 96.4d))
+ entryOf(codeCoverageKey, createMeasure(95.5d)),
+ entryOf(lineCoverageKey, createMeasure(95.4d)),
+ entryOf(branchCoverageKey, createMeasure(96.4d))
};
assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).containsOnly(modulesAndProjectEntries);
private void verify_only_zero_measures_on_new_lines_and_conditions_measures(Component component) {
assertThat(toEntries(measureRepository.getAddedRawMeasures(component.getReportAttributes().getRef()))).containsOnly(
- entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(0d, 0d)),
- entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(0d, 0d)),
- entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(0d, 0d)),
- entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(0d, 0d)));
+ entryOf(NEW_LINES_TO_COVER_KEY, createMeasure(0d)),
+ entryOf(NEW_UNCOVERED_LINES_KEY, createMeasure(0d)),
+ entryOf(NEW_CONDITIONS_TO_COVER_KEY, createMeasure(0d)),
+ entryOf(NEW_UNCOVERED_CONDITIONS_KEY, createMeasure(0d)));
}
private void defineChangeSetsAndMeasures(int componentRef, MetricKeys metricKeys, MeasureValues line4, MeasureValues line6) {
underTest.execute();
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_COMPONENT.getReportAttributes().getRef()))).contains(
- entryOf(metricKeys.newLinesToCover, createMeasure(5d, 3d)),
- entryOf(metricKeys.newUncoveredLines, createMeasure(3d, 2d)),
- entryOf(metricKeys.newConditionsToCover, createMeasure(7d, 3d)),
- entryOf(metricKeys.newUncoveredConditions, createMeasure(4d, 1d)));
+ entryOf(metricKeys.newLinesToCover, createMeasure(5d)),
+ entryOf(metricKeys.newUncoveredLines, createMeasure(3d)),
+ entryOf(metricKeys.newConditionsToCover, createMeasure(7d)),
+ entryOf(metricKeys.newUncoveredConditions, createMeasure(4d)));
}
- private static Measure createMeasure(@Nullable Double variationPeriod2, @Nullable Double variationPeriod5) {
- MeasureVariations.Builder variationBuilder = newMeasureVariationsBuilder();
- if (variationPeriod2 != null) {
- variationBuilder.setVariation(new Period(2, "", null, 1L, "u2"), variationPeriod2);
- }
- if (variationPeriod5 != null) {
- variationBuilder.setVariation(new Period(5, "", null, 1L, "u2"), variationPeriod5);
- }
+ private static Measure createMeasure(Double expectedVariation) {
return newMeasureBuilder()
- .setVariations(variationBuilder.build())
+ .setVariation(expectedVariation)
.createNoValue();
}
*/
package org.sonar.server.computation.task.projectanalysis.step;
-import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.server.computation.task.projectanalysis.formula.coverage.LinesAndConditionsWithUncoveredMetricKeys;
import org.sonar.server.computation.task.projectanalysis.measure.Measure;
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;
import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
import static org.sonar.server.computation.task.projectanalysis.measure.MeasureRepoEntry.entryOf;
import static org.sonar.server.computation.task.projectanalysis.measure.MeasureRepoEntry.toEntries;
-import static org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations.newMeasureVariationsBuilder;
public class ViewsNewCoverageMeasuresStepTest {
builder(PROJECT_VIEW, PROJECT_VIEW_4_REF).build())
.build())
.build();
- private static final Double NO_PERIOD_4_OR_5_IN_VIEWS = null;
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
@Before
public void setUp() {
- periodsHolder.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"));
+ periodsHolder.setPeriod(new Period("mode_p_1", null, parseDate("2009-12-25").getTime(), "U1"));
}
@Test
treeRootHolder.setRoot(VIEWS_TREE);
// PROJECT_VIEW_1_REF has no measure
- measureRepository.addRawMeasure(PROJECT_VIEW_2_REF, newLinesToCover, createMeasure(1d, 2d));
- measureRepository.addRawMeasure(PROJECT_VIEW_2_REF, newUncoveredLines, createMeasure(10d, 20d));
- measureRepository.addRawMeasure(PROJECT_VIEW_2_REF, newConditionsToCover, createMeasure(4d, 5d));
- measureRepository.addRawMeasure(PROJECT_VIEW_2_REF, newUncoveredConditions, createMeasure(40d, 50d));
- measureRepository.addRawMeasure(PROJECT_VIEW_3_REF, newLinesToCover, createMeasure(11d, 12d));
- measureRepository.addRawMeasure(PROJECT_VIEW_3_REF, newUncoveredLines, createMeasure(20d, 30d));
- measureRepository.addRawMeasure(PROJECT_VIEW_3_REF, newConditionsToCover, createMeasure(14d, 15d));
- measureRepository.addRawMeasure(PROJECT_VIEW_3_REF, newUncoveredConditions, createMeasure(50d, 60d));
- measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newLinesToCover, createMeasure(21d, 22d));
- measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newUncoveredLines, createMeasure(30d, 40d));
- measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newConditionsToCover, createMeasure(24d, 25d));
- measureRepository.addRawMeasure(PROJECT_VIEW_4_REF, newUncoveredConditions, createMeasure(60d, 70d));
+ 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();
assertNoAddedRawMeasureOnProjectViews();
assertNoAddedRawMeasures(SUB_SUBVIEW_1_REF);
assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_SUBVIEW_2_REF))).contains(
- entryOf(metricKeys.newLinesToCover, createMeasure(12d, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(metricKeys.newUncoveredLines, createMeasure(30d, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(metricKeys.newConditionsToCover, createMeasure(18d, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(metricKeys.newUncoveredConditions, createMeasure(90d, NO_PERIOD_4_OR_5_IN_VIEWS)));
+ 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, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(metricKeys.newUncoveredLines, createMeasure(60d, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(metricKeys.newConditionsToCover, createMeasure(42d, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(metricKeys.newUncoveredConditions, createMeasure(150d, NO_PERIOD_4_OR_5_IN_VIEWS)));
+ entryOf(metricKeys.newLinesToCover, createMeasure(33d)),
+ entryOf(metricKeys.newUncoveredLines, createMeasure(60d)),
+ entryOf(metricKeys.newConditionsToCover, createMeasure(42d)),
+ entryOf(metricKeys.newUncoveredConditions, createMeasure(150d)));
}
@Test
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, 2000d))
- .addRawMeasure(PROJECT_VIEW_1_REF, metricKeys.getConditions(), createMeasure(300d, 400d))
- .addRawMeasure(PROJECT_VIEW_1_REF, metricKeys.getUncoveredLines(), createMeasure(30d, 200d))
- .addRawMeasure(PROJECT_VIEW_1_REF, metricKeys.getUncoveredConditions(), createMeasure(9d, 16d))
+ .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, 3000d))
- .addRawMeasure(PROJECT_VIEW_2_REF, metricKeys.getConditions(), createMeasure(400d, 300d))
- .addRawMeasure(PROJECT_VIEW_2_REF, metricKeys.getUncoveredLines(), createMeasure(200d, 30d))
- .addRawMeasure(PROJECT_VIEW_2_REF, metricKeys.getUncoveredConditions(), createMeasure(16d, 9d))
+ .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, 2000d))
- .addRawMeasure(PROJECT_VIEW_4_REF, metricKeys.getConditions(), createMeasure(300d, 200d))
- .addRawMeasure(PROJECT_VIEW_4_REF, metricKeys.getUncoveredLines(), createMeasure(100d, 20d))
- .addRawMeasure(PROJECT_VIEW_4_REF, metricKeys.getUncoveredConditions(), createMeasure(6d, 9d));
+ .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();
assertNoAddedRawMeasureOnProjectViews();
assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_SUBVIEW_1_REF))).contains(
- entryOf(codeCoverageKey, createMeasure(98.8d, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(lineCoverageKey, createMeasure(99d, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(branchCoverageKey, createMeasure(97d, NO_PERIOD_4_OR_5_IN_VIEWS)));
+ 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, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(lineCoverageKey, createMeasure(90d, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(branchCoverageKey, createMeasure(96d, NO_PERIOD_4_OR_5_IN_VIEWS)));
+ entryOf(codeCoverageKey, createMeasure(91d)),
+ entryOf(lineCoverageKey, createMeasure(90d)),
+ entryOf(branchCoverageKey, createMeasure(96d)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(SUBVIEW_REF))).contains(
- entryOf(codeCoverageKey, createMeasure(94.8d, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(lineCoverageKey, createMeasure(94.5d, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(branchCoverageKey, createMeasure(96.9d, NO_PERIOD_4_OR_5_IN_VIEWS)));
+ 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, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(lineCoverageKey, createMeasure(94.5d, NO_PERIOD_4_OR_5_IN_VIEWS)),
- entryOf(branchCoverageKey, createMeasure(96.9d, NO_PERIOD_4_OR_5_IN_VIEWS)));
+ entryOf(codeCoverageKey, createMeasure(94.8d)),
+ entryOf(lineCoverageKey, createMeasure(94.5d)),
+ entryOf(branchCoverageKey, createMeasure(96.9d)));
}
private static final class MetricKeys {
}
}
- private static Measure createMeasure(@Nullable Double variationPeriod2, @Nullable Double variationPeriod5) {
- MeasureVariations.Builder variationBuilder = newMeasureVariationsBuilder();
- if (variationPeriod2 != null) {
- variationBuilder.setVariation(new Period(2, "", null, 1L, "U2"), variationPeriod2);
- }
- if (variationPeriod5 != null) {
- variationBuilder.setVariation(new Period(5, "", null, 1L, "U2"), variationPeriod5);
- }
+ private static Measure createMeasure(Double expectedVariation) {
return newMeasureBuilder()
- .setVariations(variationBuilder.build())
+ .setVariation(expectedVariation)
.createNoValue();
}