From 01b74f89e9de79e82b524a0be3efcf201daf395b Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 7 Feb 2017 15:19:55 +0100 Subject: [PATCH] SONAR-8743 Handle only leak period when computing issues related measures --- .../projectanalysis/issue/IssueCounter.java | 110 ++++---- .../issue/NewEffortAggregator.java | 32 +-- .../NewMaintainabilityMeasuresVisitor.java | 82 +++--- ...ilityAndSecurityRatingMeasuresVisitor.java | 43 ++- .../issue/IssueCounterTest.java | 62 ++--- .../issue/NewEffortAggregatorTest.java | 29 +- .../measure/MeasureAssert.java | 162 ++--------- .../period/PeriodsHolderRule.java | 3 +- ...NewMaintainabilityMeasuresVisitorTest.java | 251 +++++++----------- ...yAndSecurityRatingMeasuresVisitorTest.java | 8 +- 10 files changed, 282 insertions(+), 500 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCounter.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCounter.java index 3bf49cab4c7..0807e699aab 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCounter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCounter.java @@ -32,7 +32,6 @@ import org.sonar.core.issue.DefaultIssue; import org.sonar.server.computation.task.projectanalysis.component.Component; 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; @@ -83,16 +82,14 @@ public class IssueCounter extends IssueVisitor { CRITICAL, CRITICAL_VIOLATIONS_KEY, MAJOR, MAJOR_VIOLATIONS_KEY, MINOR, MINOR_VIOLATIONS_KEY, - INFO, INFO_VIOLATIONS_KEY - ); + INFO, INFO_VIOLATIONS_KEY); private static final Map SEVERITY_TO_NEW_METRIC_KEY = ImmutableMap.of( BLOCKER, NEW_BLOCKER_VIOLATIONS_KEY, CRITICAL, NEW_CRITICAL_VIOLATIONS_KEY, MAJOR, NEW_MAJOR_VIOLATIONS_KEY, MINOR, NEW_MINOR_VIOLATIONS_KEY, - INFO, NEW_INFO_VIOLATIONS_KEY - ); + INFO, NEW_INFO_VIOLATIONS_KEY); private static final Map TYPE_TO_METRIC_KEY = ImmutableMap.builder() .put(RuleType.CODE_SMELL, CoreMetrics.CODE_SMELLS_KEY) @@ -136,11 +133,13 @@ public class IssueCounter extends IssueVisitor { @Override public void onIssue(Component component, DefaultIssue issue) { currentCounters.add(issue); - for (Period period : periodsHolder.getPeriods()) { - // Add one second to not take into account issues created during current analysis - if (issue.creationDate().getTime() >= period.getSnapshotDate() + 1000L) { - currentCounters.addOnPeriod(issue, period.getIndex()); - } + if (!periodsHolder.hasPeriod()) { + return; + } + Period period = periodsHolder.getPeriod(); + // Add one second to not take into account issues created during current analysis + if (issue.creationDate().getTime() >= period.getSnapshotDate() + 1000L) { + currentCounters.addOnPeriod(issue); } } @@ -182,44 +181,34 @@ public class IssueCounter extends IssueVisitor { } private void addMeasuresByPeriod(Component component) { - if (!periodsHolder.getPeriods().isEmpty()) { - Double[] unresolvedVariations = new Double[PeriodsHolder.MAX_NUMBER_OF_PERIODS]; - for (Period period : periodsHolder.getPeriods()) { - unresolvedVariations[period.getIndex() - 1] = (double) currentCounters.counterForPeriod(period.getIndex()).unresolved; - } - measureRepository.add(component, metricRepository.getByKey(NEW_VIOLATIONS_KEY), Measure.newMeasureBuilder() - .setVariations(new MeasureVariations(unresolvedVariations)) - .createNoValue()); + if (!periodsHolder.hasPeriod()) { + return; + } + Double unresolvedVariations = (double) currentCounters.counterForPeriod().unresolved; + measureRepository.add(component, metricRepository.getByKey(NEW_VIOLATIONS_KEY), Measure.newMeasureBuilder() + .setVariation(unresolvedVariations) + .createNoValue()); - for (Map.Entry entry : SEVERITY_TO_NEW_METRIC_KEY.entrySet()) { - String severity = entry.getKey(); - String metricKey = entry.getValue(); - Double[] variations = new Double[PeriodsHolder.MAX_NUMBER_OF_PERIODS]; - for (Period period : periodsHolder.getPeriods()) { - Multiset bag = currentCounters.counterForPeriod(period.getIndex()).severityBag; - variations[period.getIndex() - 1] = (double) bag.count(severity); - } - Metric metric = metricRepository.getByKey(metricKey); - measureRepository.add(component, metric, Measure.newMeasureBuilder() - .setVariations(new MeasureVariations(variations)) - .createNoValue()); - } + for (Map.Entry entry : SEVERITY_TO_NEW_METRIC_KEY.entrySet()) { + String severity = entry.getKey(); + String metricKey = entry.getValue(); + Multiset bag = currentCounters.counterForPeriod().severityBag; + Metric metric = metricRepository.getByKey(metricKey); + measureRepository.add(component, metric, Measure.newMeasureBuilder() + .setVariation((double) bag.count(severity)) + .createNoValue()); + } - // waiting for Java 8 lambda in order to factor this loop with the previous one - // (see call currentCounters.counterForPeriod(period.getIndex()).xxx with xxx as severityBag or typeBag) - for (Map.Entry entry : TYPE_TO_NEW_METRIC_KEY.entrySet()) { - RuleType type = entry.getKey(); - String metricKey = entry.getValue(); - Double[] variations = new Double[PeriodsHolder.MAX_NUMBER_OF_PERIODS]; - for (Period period : periodsHolder.getPeriods()) { - Multiset bag = currentCounters.counterForPeriod(period.getIndex()).typeBag; - variations[period.getIndex() - 1] = (double) bag.count(type); - } - Metric metric = metricRepository.getByKey(metricKey); - measureRepository.add(component, metric, Measure.newMeasureBuilder() - .setVariations(new MeasureVariations(variations)) - .createNoValue()); - } + // waiting for Java 8 lambda in order to factor this loop with the previous one + // (see call currentCounters.counterForPeriod(period.getIndex()).xxx with xxx as severityBag or typeBag) + for (Map.Entry entry : TYPE_TO_NEW_METRIC_KEY.entrySet()) { + RuleType type = entry.getKey(); + String metricKey = entry.getValue(); + Multiset bag = currentCounters.counterForPeriod().typeBag; + Metric metric = metricRepository.getByKey(metricKey); + measureRepository.add(component, metric, Measure.newMeasureBuilder() + .setVariation((double) bag.count(type)) + .createNoValue()); } } @@ -274,40 +263,33 @@ public class IssueCounter extends IssueVisitor { } /** - * List of {@link Counter} for regular value and periods. + * List of {@link Counter} for regular value and period. */ private static class Counters { - private final Counter[] array = new Counter[1 + PeriodsHolder.MAX_NUMBER_OF_PERIODS]; - - Counters() { - array[0] = new Counter(); - for (int i = 1; i <= PeriodsHolder.MAX_NUMBER_OF_PERIODS; i++) { - array[i] = new Counter(); - } - } + private final Counter counter = new Counter(); + private final Counter counterForPeriod = new Counter(); void add(@Nullable Counters other) { if (other != null) { - for (int i = 0; i < array.length; i++) { - array[i].add(other.array[i]); - } + counter.add(other.counter); + counterForPeriod.add(other.counterForPeriod); } } - void addOnPeriod(DefaultIssue issue, int periodIndex) { - array[periodIndex].add(issue); + void addOnPeriod(DefaultIssue issue) { + counterForPeriod.add(issue); } void add(DefaultIssue issue) { - array[0].add(issue); + counter.add(issue); } Counter counter() { - return array[0]; + return counter; } - Counter counterForPeriod(int periodIndex) { - return array[periodIndex]; + Counter counterForPeriod() { + return counterForPeriod; } } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortAggregator.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortAggregator.java index 8d24e021b4c..cf9e0bcc60e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortAggregator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortAggregator.java @@ -32,7 +32,6 @@ import org.sonar.db.issue.IssueChangeDto; import org.sonar.server.computation.task.projectanalysis.component.Component; 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; @@ -94,11 +93,9 @@ public class NewEffortAggregator extends IssueVisitor { @Override public void onIssue(Component component, DefaultIssue issue) { - if (issue.resolution() == null && issue.effortInMinutes() != null && !periodsHolder.getPeriods().isEmpty()) { + if (issue.resolution() == null && issue.effortInMinutes() != null && periodsHolder.hasPeriod()) { List changelog = changesByIssueUuid.get(issue.key()); - for (Period period : periodsHolder.getPeriods()) { - counter.add(issue, period, changelog); - } + counter.add(issue, periodsHolder.getPeriod(), changelog); } } @@ -113,8 +110,7 @@ public class NewEffortAggregator extends IssueVisitor { private void computeMeasure(Component component, Metric metric, EffortSum effortSum) { if (!effortSum.isEmpty) { - MeasureVariations variations = new MeasureVariations(effortSum.sums); - measureRepository.add(component, metric, Measure.newMeasureBuilder().setVariations(variations).createNoValue()); + measureRepository.add(component, metric, Measure.newMeasureBuilder().setVariation(effortSum.newEffort).createNoValue()); } } @@ -139,13 +135,13 @@ public class NewEffortAggregator extends IssueVisitor { long newEffort = calculator.calculate(issue, changelog, period); switch (issue.type()) { case CODE_SMELL: - maintainabilitySum.add(period.getIndex(), newEffort); + maintainabilitySum.add(newEffort); break; case BUG: - reliabilitySum.add(period.getIndex(), newEffort); + reliabilitySum.add(newEffort); break; case VULNERABILITY: - securitySum.add(period.getIndex(), newEffort); + securitySum.add(newEffort); break; default: throw new IllegalStateException(String.format("Unknown type '%s'", issue.type())); @@ -154,21 +150,19 @@ public class NewEffortAggregator extends IssueVisitor { } private static class EffortSum { - private final Double[] sums = new Double[PeriodsHolder.MAX_NUMBER_OF_PERIODS]; + private Double newEffort; private boolean isEmpty = true; - void add(int periodIndex, long newEffort) { - double previous = MoreObjects.firstNonNull(sums[periodIndex - 1], 0d); - sums[periodIndex - 1] = previous + newEffort; + void add(long newEffort) { + double previous = MoreObjects.firstNonNull(this.newEffort, 0d); + this.newEffort = previous + newEffort; isEmpty = false; } void add(EffortSum other) { - for (int i = 0; i < sums.length; i++) { - Double otherValue = other.sums[i]; - if (otherValue != null) { - add(i + 1, otherValue.longValue()); - } + Double otherValue = other.newEffort; + if (otherValue != null) { + add(otherValue.longValue()); } } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java index c33e94ebe84..ce08f62c416 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitor.java @@ -33,7 +33,6 @@ import org.sonar.server.computation.task.projectanalysis.formula.counter.LongVar import org.sonar.server.computation.task.projectanalysis.issue.IntegrateIssuesVisitor; 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; @@ -49,7 +48,6 @@ import static org.sonar.api.measures.CoreMetrics.NEW_TECHNICAL_DEBT_KEY; import static org.sonar.api.utils.KeyValueFormat.newIntegerConverter; import static org.sonar.server.computation.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER; import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder; -import static org.sonar.server.computation.task.projectanalysis.measure.MeasureVariations.newMeasureVariationsBuilder; /** * This visitor depends on {@link IntegrateIssuesVisitor} for the computation of @@ -118,25 +116,20 @@ public class NewMaintainabilityMeasuresVisitor extends PathAwareVisitorAdapter path) { - MeasureVariations.Builder newDebtRatio = newMeasureVariationsBuilder(); - MeasureVariations.Builder newMaintainability = newMeasureVariationsBuilder(); - for (Period period : periodsHolder.getPeriods()) { - double density = computeDensity(path.current(), period); - newDebtRatio.setVariation(period, 100.0 * density); - newMaintainability.setVariation(period, ratingGrid.getRatingForDensity(density).getIndex()); - } - if (!newDebtRatio.isEmpty()) { - measureRepository.add(component, this.newDebtRatioMetric, newMeasureBuilder().setVariations(newDebtRatio.build()).createNoValue()); - } - if (!newMaintainability.isEmpty()) { - measureRepository.add(component, this.newMaintainabilityRatingMetric, newMeasureBuilder().setVariations(newMaintainability.build()).createNoValue()); + if (!periodsHolder.hasPeriod()) { + return; } + double density = computeDensity(path.current()); + double newDebtRatio = 100.0 * density; + double newMaintainability = ratingGrid.getRatingForDensity(density).getIndex(); + measureRepository.add(component, this.newDebtRatioMetric, newMeasureBuilder().setVariation(newDebtRatio).createNoValue()); + measureRepository.add(component, this.newMaintainabilityRatingMetric, newMeasureBuilder().setVariation(newMaintainability).createNoValue()); } - private static double computeDensity(Counter counter, Period period) { - LongVariationValue newDebt = counter.getNewDebt(period); + private static double computeDensity(Counter counter) { + LongVariationValue newDebt = counter.getNewDebt(); if (newDebt.isSet()) { - long developmentCost = counter.getDevCost(period).getValue(); + long developmentCost = counter.getDevCost().getValue(); if (developmentCost != 0L) { return newDebt.getValue() / (double) developmentCost; } @@ -144,23 +137,23 @@ public class NewMaintainabilityMeasuresVisitor extends PathAwareVisitorAdapter measure, Period period) { + private static long getLongValue(Optional measure) { if (!measure.isPresent()) { return 0L; } - return getLongValue(measure.get(), period); + return getLongValue(measure.get()); } - private static long getLongValue(Measure measure, Period period) { - if (measure.hasVariations() && measure.getVariations().hasVariation(period.getIndex())) { - return (long) measure.getVariations().getVariation(period.getIndex()); + private static long getLongValue(Measure measure) { + if (measure.hasVariation()) { + return (long) measure.getVariation(); } return 0L; } private void initNewDebtRatioCounter(Component file, Path path) { // first analysis, no period, no differential value to compute, save processing time and return now - if (periodsHolder.getPeriods().isEmpty()) { + if (!periodsHolder.hasPeriod()) { return; } @@ -180,23 +173,20 @@ public class NewMaintainabilityMeasuresVisitor extends PathAwareVisitorAdapter metricsByKey; public NewReliabilityAndSecurityRatingMeasuresVisitor(MetricRepository metricRepository, MeasureRepository measureRepository, ComponentIssuesRepository componentIssuesRepository, @@ -86,12 +82,9 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitor extends PathAwareVis this.periodsHolder = periodsHolder; // Output metrics - this.newReliabilityRatingMetric = metricRepository.getByKey(NEW_RELIABILITY_RATING_KEY); - this.newSecurityRatingMetric = metricRepository.getByKey(NEW_SECURITY_RATING_KEY); - this.metricsByKey = ImmutableMap.of( - NEW_RELIABILITY_RATING_KEY, newReliabilityRatingMetric, - NEW_SECURITY_RATING_KEY, newSecurityRatingMetric); + NEW_RELIABILITY_RATING_KEY, metricRepository.getByKey(NEW_RELIABILITY_RATING_KEY), + NEW_SECURITY_RATING_KEY, metricRepository.getByKey(NEW_SECURITY_RATING_KEY)); } @Override @@ -115,20 +108,24 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitor extends PathAwareVis } private void computeAndSaveMeasures(Component component, Path path) { + if (!periodsHolder.hasPeriod()) { + return; + } initRatingsToA(path); processIssues(component, path); - path.current().newRatingValueByMetric.entrySet().forEach( - entry -> entry.getValue().toMeasureVariations() - .ifPresent(measureVariations -> measureRepository.add( + path.current().newRatingValueByMetric.entrySet() + .stream() + .filter(entry -> entry.getValue().isSet()) + .forEach( + entry -> measureRepository.add( component, metricsByKey.get(entry.getKey()), - newMeasureBuilder().setVariations(measureVariations).createNoValue()))); + newMeasureBuilder().setVariation(entry.getValue().getValue().getIndex()).createNoValue())); addToParent(path); } - private void initRatingsToA(Path path) { - periodsHolder.getPeriods().forEach(period -> path.current().newRatingValueByMetric.values() - .forEach(entry -> entry.increment(period, A))); + private static void initRatingsToA(Path path) { + path.current().newRatingValueByMetric.values().forEach(entry -> entry.increment(A)); } private void processIssues(Component component, Path path) { @@ -136,7 +133,7 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitor extends PathAwareVis .stream() .filter(issue -> issue.resolution() == null) .filter(issue -> issue.type().equals(BUG) || issue.type().equals(VULNERABILITY)) - .forEach(issue -> periodsHolder.getPeriods().forEach(period -> path.current().processIssue(issue, period))); + .forEach(issue -> path.current().processIssue(issue, periodsHolder.getPeriod())); } private static void addToParent(Path path) { @@ -146,25 +143,25 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitor extends PathAwareVis } static final class Counter { - private Map newRatingValueByMetric = ImmutableMap.of( - NEW_RELIABILITY_RATING_KEY, new RatingVariationValue.Array(), - NEW_SECURITY_RATING_KEY, new RatingVariationValue.Array()); + private Map newRatingValueByMetric = ImmutableMap.of( + NEW_RELIABILITY_RATING_KEY, new RatingVariationValue(), + NEW_SECURITY_RATING_KEY, new RatingVariationValue()); private Counter() { // prevents instantiation } void add(Counter otherCounter) { - newRatingValueByMetric.entrySet().forEach(e -> e.getValue().incrementAll(otherCounter.newRatingValueByMetric.get(e.getKey()))); + newRatingValueByMetric.entrySet().forEach(e -> e.getValue().increment(otherCounter.newRatingValueByMetric.get(e.getKey()))); } void processIssue(Issue issue, Period period) { if (isOnPeriod((DefaultIssue) issue, period)) { Rating rating = RATING_BY_SEVERITY.get(issue.severity()); if (issue.type().equals(BUG)) { - newRatingValueByMetric.get(NEW_RELIABILITY_RATING_KEY).increment(period, rating); + newRatingValueByMetric.get(NEW_RELIABILITY_RATING_KEY).increment(rating); } else if (issue.type().equals(VULNERABILITY)) { - newRatingValueByMetric.get(NEW_SECURITY_RATING_KEY).increment(period, rating); + newRatingValueByMetric.get(NEW_SECURITY_RATING_KEY).increment(rating); } } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCounterTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCounterTest.java index 8a4bc16ad2b..f83a6655272 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCounterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueCounterTest.java @@ -22,7 +22,6 @@ package org.sonar.server.computation.task.projectanalysis.issue; import java.util.Date; import javax.annotation.Nullable; import org.assertj.core.data.Offset; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.sonar.api.measures.CoreMetrics; @@ -32,8 +31,8 @@ import org.sonar.db.rule.RuleTesting; import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReaderRule; import org.sonar.server.computation.task.projectanalysis.component.Component; import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; +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.Metric; import org.sonar.server.computation.task.projectanalysis.metric.MetricImpl; import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule; @@ -140,16 +139,11 @@ public class IssueCounterTest { @Rule public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository); - IssueCounter underTest; - - @Before - public void setUp() { - underTest = new IssueCounter(periodsHolder, metricRepository, measureRepository); - } + private IssueCounter underTest = new IssueCounter(periodsHolder, metricRepository, measureRepository);; @Test public void count_issues_by_status() { - periodsHolder.setPeriods(); + periodsHolder.setPeriod(null); // bottom-up traversal -> from files to project underTest.beforeComponent(FILE1); @@ -186,7 +180,7 @@ public class IssueCounterTest { @Test public void count_issues_by_resolution() { - periodsHolder.setPeriods(); + periodsHolder.setPeriod(null); // bottom-up traversal -> from files to project underTest.beforeComponent(FILE1); @@ -224,7 +218,7 @@ public class IssueCounterTest { @Test public void count_unresolved_issues_by_severity() { - periodsHolder.setPeriods(); + periodsHolder.setPeriod(null); // bottom-up traversal -> from files to project underTest.beforeComponent(FILE1); @@ -256,7 +250,7 @@ public class IssueCounterTest { @Test public void count_unresolved_issues_by_type() { - periodsHolder.setPeriods(); + periodsHolder.setPeriod(null); // bottom-up traversal -> from files to project // file1 : one open code smell, one closed code smell (which will be excluded from metric) @@ -288,8 +282,8 @@ public class IssueCounterTest { @Test public void count_new_issues() { - Period period = newPeriod(3, 1500000000000L); - periodsHolder.setPeriods(period); + Period period = newPeriod(1500000000000L); + periodsHolder.setPeriod(period); underTest.beforeComponent(FILE1); // created before -> existing issues (so ignored) @@ -308,26 +302,26 @@ public class IssueCounterTest { underTest.beforeComponent(PROJECT); underTest.afterComponent(PROJECT); - assertVariation(FILE1, NEW_ISSUES_METRIC, period.getIndex(), 2); - assertVariation(FILE1, NEW_CRITICAL_ISSUES_METRIC, period.getIndex(), 2); - assertVariation(FILE1, NEW_BLOCKER_ISSUES_METRIC, period.getIndex(), 0); - assertVariation(FILE1, NEW_MAJOR_ISSUES_METRIC, period.getIndex(), 0); - assertVariation(FILE1, NEW_CODE_SMELLS_METRIC, period.getIndex(), 1); - assertVariation(FILE1, NEW_BUGS_METRIC, period.getIndex(), 1); - assertVariation(FILE1, NEW_VULNERABILITIES_METRIC, period.getIndex(), 0); - - assertVariation(PROJECT, NEW_ISSUES_METRIC, period.getIndex(), 2); - assertVariation(PROJECT, NEW_CRITICAL_ISSUES_METRIC, period.getIndex(), 2); - assertVariation(PROJECT, NEW_BLOCKER_ISSUES_METRIC, period.getIndex(), 0); - assertVariation(PROJECT, NEW_MAJOR_ISSUES_METRIC, period.getIndex(), 0); - assertVariation(PROJECT, NEW_CODE_SMELLS_METRIC, period.getIndex(), 1); - assertVariation(PROJECT, NEW_BUGS_METRIC, period.getIndex(), 1); - assertVariation(PROJECT, NEW_VULNERABILITIES_METRIC, period.getIndex(), 0); + assertVariation(FILE1, NEW_ISSUES_METRIC, 2); + assertVariation(FILE1, NEW_CRITICAL_ISSUES_METRIC, 2); + assertVariation(FILE1, NEW_BLOCKER_ISSUES_METRIC, 0); + assertVariation(FILE1, NEW_MAJOR_ISSUES_METRIC, 0); + assertVariation(FILE1, NEW_CODE_SMELLS_METRIC, 1); + assertVariation(FILE1, NEW_BUGS_METRIC, 1); + assertVariation(FILE1, NEW_VULNERABILITIES_METRIC, 0); + + assertVariation(PROJECT, NEW_ISSUES_METRIC, 2); + assertVariation(PROJECT, NEW_CRITICAL_ISSUES_METRIC, 2); + assertVariation(PROJECT, NEW_BLOCKER_ISSUES_METRIC, 0); + assertVariation(PROJECT, NEW_MAJOR_ISSUES_METRIC, 0); + assertVariation(PROJECT, NEW_CODE_SMELLS_METRIC, 1); + assertVariation(PROJECT, NEW_BUGS_METRIC, 1); + assertVariation(PROJECT, NEW_VULNERABILITIES_METRIC, 0); } - private void assertVariation(Component component, Metric metric, int periodIndex, int expectedVariation) { - MeasureVariations variations = measureRepository.getRawMeasure(component, metric).get().getVariations(); - assertThat(variations.getVariation(periodIndex)).isEqualTo((double) expectedVariation, Offset.offset(0.01)); + private void assertVariation(Component component, Metric metric, int expectedVariation) { + Measure measure = measureRepository.getRawMeasure(component, metric).get(); + assertThat(measure.getVariation()).isEqualTo((double) expectedVariation, Offset.offset(0.01)); } private static DefaultIssue createIssue(@Nullable String resolution, String status, String severity) { @@ -346,8 +340,8 @@ public class IssueCounterTest { .setCreationDate(new Date(creationDate)); } - private static Period newPeriod(int index, long date) { - return new Period(index, "mode", null, date, "U1"); + private static Period newPeriod(long date) { + return new Period("mode", null, date, "U1"); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortAggregatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortAggregatorTest.java index 86a1b039b7f..19a704d2a43 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortAggregatorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortAggregatorTest.java @@ -57,10 +57,10 @@ public class NewEffortAggregatorTest { private static final Period PERIOD = new Period(1, TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, null, 1_500_000_000L, "U1"); - static final Component FILE = ReportComponent.builder(Component.Type.FILE, 1).setUuid("FILE").build(); - static final Component PROJECT = ReportComponent.builder(Component.Type.PROJECT, 2).addChildren(FILE).build(); + private static final Component FILE = ReportComponent.builder(Component.Type.FILE, 1).setUuid("FILE").build(); + private static final Component PROJECT = ReportComponent.builder(Component.Type.PROJECT, 2).addChildren(FILE).build(); - NewEffortCalculator calculator = mock(NewEffortCalculator.class); + private NewEffortCalculator calculator = mock(NewEffortCalculator.class); @org.junit.Rule public PeriodsHolderRule periodsHolder = new PeriodsHolderRule(); @@ -74,13 +74,13 @@ public class NewEffortAggregatorTest { @org.junit.Rule public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(); - DbClient dbClient = mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS); + private DbClient dbClient = mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS); - NewEffortAggregator underTest = new NewEffortAggregator(calculator, periodsHolder, dbClient, metricRepository, measureRepository); + private NewEffortAggregator underTest = new NewEffortAggregator(calculator, periodsHolder, dbClient, metricRepository, measureRepository); @Test public void sum_new_maintainability_effort_of_issues() { - periodsHolder.setPeriods(PERIOD); + periodsHolder.setPeriod(PERIOD); DefaultIssue unresolved1 = newCodeSmellIssue(10L); DefaultIssue unresolved2 = newCodeSmellIssue(30L); DefaultIssue unresolvedWithoutDebt = newCodeSmellIssueWithoutEffort(); @@ -102,7 +102,7 @@ public class NewEffortAggregatorTest { @Test public void new_maintainability_effort_is_only_computed_using_code_smell_issues() { - periodsHolder.setPeriods(PERIOD); + periodsHolder.setPeriod(PERIOD); DefaultIssue codeSmellIssue = newCodeSmellIssue(10); // Issues of type BUG and VULNERABILITY should be ignored DefaultIssue bugIssue = newBugIssue(15); @@ -124,7 +124,7 @@ public class NewEffortAggregatorTest { @Test public void sum_new_reliability_effort_of_issues() { - periodsHolder.setPeriods(PERIOD); + periodsHolder.setPeriod(PERIOD); DefaultIssue unresolved1 = newBugIssue(10L); DefaultIssue unresolved2 = newBugIssue(30L); DefaultIssue unresolvedWithoutDebt = newBugIssueWithoutEffort(); @@ -146,7 +146,7 @@ public class NewEffortAggregatorTest { @Test public void new_reliability_effort_is_only_computed_using_bug_issues() { - periodsHolder.setPeriods(PERIOD); + periodsHolder.setPeriod(PERIOD); DefaultIssue bugIssue = newBugIssue(15); // Issues of type CODE SMELL and VULNERABILITY should be ignored DefaultIssue codeSmellIssue = newCodeSmellIssue(10); @@ -168,7 +168,7 @@ public class NewEffortAggregatorTest { @Test public void sum_new_securtiy_effort_of_issues() { - periodsHolder.setPeriods(PERIOD); + periodsHolder.setPeriod(PERIOD); DefaultIssue unresolved1 = newVulnerabilityIssue(10L); DefaultIssue unresolved2 = newVulnerabilityIssue(30L); DefaultIssue unresolvedWithoutDebt = newVulnerabilityIssueWithoutEffort(); @@ -190,7 +190,7 @@ public class NewEffortAggregatorTest { @Test public void new_security_effort_is_only_computed_using_vulnerability_issues() { - periodsHolder.setPeriods(PERIOD); + periodsHolder.setPeriod(PERIOD); DefaultIssue vulnerabilityIssue = newVulnerabilityIssue(12); // Issues of type CODE SMELL and BUG should be ignored DefaultIssue codeSmellIssue = newCodeSmellIssue(10); @@ -212,7 +212,7 @@ public class NewEffortAggregatorTest { @Test public void aggregate_new_characteristic_measures_of_children() { - periodsHolder.setPeriods(PERIOD); + periodsHolder.setPeriod(PERIOD); DefaultIssue codeSmellIssue = newCodeSmellIssue(10); when(calculator.calculate(same(codeSmellIssue), anyList(), same(PERIOD))).thenReturn(4L); @@ -246,7 +246,7 @@ public class NewEffortAggregatorTest { @Test public void no_measures_if_no_periods() { - periodsHolder.setPeriods(); + periodsHolder.setPeriod(null); DefaultIssue unresolved = new DefaultIssue().setEffort(Duration.create(10)); verifyZeroInteractions(calculator); @@ -259,8 +259,7 @@ public class NewEffortAggregatorTest { private void assertVariation(Component component, String metricKey, int variation) { Measure newMeasure = measureRepository.getRawMeasure(component, metricRepository.getByKey(metricKey)).get(); - assertThat(newMeasure.getVariations().getVariation(PERIOD.getIndex())).isEqualTo(variation); - assertThat(newMeasure.getVariations().hasVariation(PERIOD.getIndex() + 1)).isFalse(); + assertThat(newMeasure.getVariation()).isEqualTo(variation); } private static DefaultIssue newCodeSmellIssue(long effort) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureAssert.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureAssert.java index 60f2479dd11..d21e9989498 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureAssert.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/measure/MeasureAssert.java @@ -259,169 +259,43 @@ public class MeasureAssert extends AbstractAssert { return this; } - public MeasureAssert hasVariation1(double expected) { + public MeasureAssert hasVariation(double expected) { isNotNull(); - hasVariations(); + hasVariation(); - if (!actual.getVariations().hasVariation1()) { - failWithMessage("Expected Measure to have a Variation 1 but it did not"); + if (!actual.hasVariation()) { + failWithMessage("Expected Measure to have a variation but it did not"); } - if (actual.getVariations().getVariation1() != expected) { - failWithMessage("Expected Variation 1 of Measure to be <%s> but was <%s>", expected, actual.getVariations().getVariation1()); + double variation = actual.getVariation(); + if (variation != expected) { + failWithMessage("Expected variation of Measure to be <%s> but was <%s>", expected, variation); } return this; } - public MeasureAssert hasVariation1(double expected, Offset offset) { + public MeasureAssert hasVariation(double expected, Offset offset) { isNotNull(); - hasVariations(); + hasVariation(); - if (!actual.getVariations().hasVariation1()) { - failWithMessage("Expected Measure to have a Variation 1 but it did not"); + if (!actual.hasVariation()) { + failWithMessage("Expected Measure to have a variation but it did not"); } - if (abs(expected - actual.getVariations().getVariation1()) <= offset.value) { + double variation = actual.getVariation(); + if (abs(expected - variation) > offset.value) { failWithMessage( - "Expected Variation 1 of Measure to be close to <%s> by less than <%s> but was <%s>", - expected, offset.value, actual.getVariations().getVariation1()); + "Expected variation of Measure to be close to <%s> by less than <%s> but was <%s>", + expected, offset.value, variation); } return this; } - public MeasureAssert hasVariation2(double expected) { - isNotNull(); - hasVariations(); - - if (!actual.getVariations().hasVariation2()) { - failWithMessage("Expected Measure to have a Variation 2 but it did not"); - } - - if (actual.getVariations().getVariation2() != expected) { - failWithMessage("Expected Variation 2 of Measure to be <%s> but was <%s>", expected, actual.getVariations().getVariation2()); - } - - return this; - } - - public MeasureAssert hasVariation2(double expected, Offset offset) { - isNotNull(); - hasVariations(); - - if (!actual.getVariations().hasVariation2()) { - failWithMessage("Expected Measure to have a Variation 2 but it did not"); - } - - if (abs(expected - actual.getVariations().getVariation2()) > offset.value) { - failWithMessage( - "Expected Variation 2 of Measure to be close to <%s> by less than <%s> but was <%s>", - expected, offset.value, actual.getVariations().getVariation2()); - } - - return this; - } - - public MeasureAssert hasVariation3(double expected) { - isNotNull(); - hasVariations(); - - if (!actual.getVariations().hasVariation3()) { - failWithMessage("Expected Measure to have a Variation 3 but it did not"); - } - - if (actual.getVariations().getVariation3() != expected) { - failWithMessage("Expected Variation 3 of Measure to be <%s> but was <%s>", expected, actual.getVariations().getVariation3()); - } - - return this; - } - - public MeasureAssert hasVariation3(double expected, Offset offset) { - isNotNull(); - hasVariations(); - - if (!actual.getVariations().hasVariation3()) { - failWithMessage("Expected Measure to have a Variation 3 but it did not"); - } - - if (abs(expected - actual.getVariations().getVariation3()) > offset.value) { - failWithMessage( - "Expected Variation 3 of Measure to be close to <%s> by less than <%s> but was <%s>", - expected, offset.value, actual.getVariations().getVariation3()); - } - - return this; - } - - public MeasureAssert hasVariation4(double expected) { - isNotNull(); - hasVariations(); - - if (!actual.getVariations().hasVariation4()) { - failWithMessage("Expected Measure to have a Variation 4 but it did not"); - } - - if (actual.getVariations().getVariation4() != expected) { - failWithMessage("Expected Variation 4 of Measure to be <%s> but was <%s>", expected, actual.getVariations().getVariation4()); - } - - return this; - } - - public MeasureAssert hasVariation4(double expected, Offset offset) { - isNotNull(); - hasVariations(); - - if (!actual.getVariations().hasVariation4()) { - failWithMessage("Expected Measure to have a Variation 4 but it did not"); - } - - if (abs(expected - actual.getVariations().getVariation4()) > offset.value) { - failWithMessage( - "Expected Variation 4 of Measure to be close to <%s> by less than <%s> but was <%s>", - expected, offset.value, actual.getVariations().getVariation4()); - } - - return this; - } - - public MeasureAssert hasVariation5(double expected) { - isNotNull(); - hasVariations(); - - if (!actual.getVariations().hasVariation5()) { - failWithMessage("Expected Measure to have a Variation 5 but it did not"); - } - - if (actual.getVariations().getVariation5() != expected) { - failWithMessage("Expected Variation 5 of Measure to be <%s> but was <%s>", expected, actual.getVariations().getVariation5()); - } - - return this; - } - - public MeasureAssert hasVariation5(double expected, Offset offset) { - isNotNull(); - hasVariations(); - - if (!actual.getVariations().hasVariation5()) { - failWithMessage("Expected Measure to have a Variation 5 but it did not"); - } - - if (abs(expected - actual.getVariations().getVariation5()) > offset.value) { - failWithMessage( - "Expected Variation 5 of Measure to be close to <%s> by less than <%s> but was <%s>", - expected, offset.value, actual.getVariations().getVariation5()); - } - - return this; - } - - private void hasVariations() { - if (!actual.hasVariations()) { - failWithMessage("Expected Measure to have a Variations but it did not"); + private void hasVariation() { + if (!actual.hasVariation()) { + failWithMessage("Expected Measure to have a variation but it did not"); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderRule.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderRule.java index 8bb0cc8bd3d..a9b427905d8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderRule.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/period/PeriodsHolderRule.java @@ -21,6 +21,7 @@ package org.sonar.server.computation.task.projectanalysis.period; import java.util.Arrays; import java.util.List; +import javax.annotation.Nullable; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; @@ -56,7 +57,7 @@ public class PeriodsHolderRule implements TestRule, PeriodsHolder { return this; } - public PeriodsHolderRule setPeriod(Period period) { + public PeriodsHolderRule setPeriod(@Nullable Period period) { delegate = new PeriodsHolderImpl(); delegate.setPeriod(period); return this; diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java index a0fb67083e3..781639920f3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewMaintainabilityMeasuresVisitorTest.java @@ -36,7 +36,6 @@ import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolde import org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler; 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; @@ -70,8 +69,7 @@ public class NewMaintainabilityMeasuresVisitorTest { private static final String LANGUAGE_1_KEY = "language 1 key"; private static final long LANGUAGE_1_DEV_COST = 30l; - private static final long PERIOD_2_SNAPSHOT_DATE = 12323l; - private static final long PERIOD_5_SNAPSHOT_DATE = 99999999l; + private static final long PERIOD_SNAPSHOT_DATE = 12323l; private static final String SOME_ANALYSIS_UUID = "9993l"; private static final String SOME_PERIOD_MODE = "some mode"; private static final int ROOT_REF = 1; @@ -106,18 +104,18 @@ public class NewMaintainabilityMeasuresVisitorTest { @Test public void project_has_new_measures_for_each_defined_period() { - setTwoPeriods(); + setPeriod(); treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).build()); underTest.visit(treeRootHolder.getRoot()); - assertNewDebtRatioValues(ROOT_REF, 0, 0); - assertNewMaintainability(ROOT_REF, A, A); + assertNewDebtRatioValues(ROOT_REF, 0); + assertNewMaintainability(ROOT_REF, A); } @Test public void project_has_no_measure_if_there_is_no_period() { - periodsHolder.setPeriods(); + periodsHolder.setPeriod(null); treeRootHolder.setRoot(builder(PROJECT, ROOT_REF).build()); underTest.visit(treeRootHolder.getRoot()); @@ -128,10 +126,10 @@ public class NewMaintainabilityMeasuresVisitorTest { @Test public void file_has_no_new_debt_ratio_variation_if_there_is_no_period() { - periodsHolder.setPeriods(); + periodsHolder.setPeriod(null); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); - setupOneFileAloneInAProject(50, 12, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET); - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50, 12)); + setupOneFileAloneInAProject(50, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET); + measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50)); underTest.visit(treeRootHolder.getRoot()); @@ -141,155 +139,155 @@ public class NewMaintainabilityMeasuresVisitorTest { @Test public void file_has_0_new_debt_ratio_if_all_scm_dates_are_before_snapshot_dates() { - setTwoPeriods(); + setPeriod(); treeRootHolder.setRoot( builder(PROJECT, ROOT_REF) .addChildren( builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build()) .build()); - measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50, 12)); + measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50)); measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4)); - scmInfoRepository.setScmInfo(LANGUAGE_1_FILE_REF, createChangesets(PERIOD_2_SNAPSHOT_DATE - 100, 4)); + scmInfoRepository.setScmInfo(LANGUAGE_1_FILE_REF, createChangesets(PERIOD_SNAPSHOT_DATE - 100, 4)); underTest.visit(treeRootHolder.getRoot()); - assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0, 0); - assertNewDebtRatioValues(ROOT_REF, 0, 0); + assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0); + assertNewDebtRatioValues(ROOT_REF, 0); } @Test public void file_has_new_debt_ratio_if_some_scm_dates_are_after_snapshot_dates() { - setTwoPeriods(); + setPeriod(); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); - setupOneFileAloneInAProject(50, 12, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET); - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50, 12)); + setupOneFileAloneInAProject(50, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET); + measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50)); underTest.visit(treeRootHolder.getRoot()); - assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 83.33, 0); - assertNewDebtRatioValues(ROOT_REF, 83.33, 0); + assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 83.33); + assertNewDebtRatioValues(ROOT_REF, 83.33); } @Test public void new_debt_ratio_changes_with_language_cost() { - setTwoPeriods(); + setPeriod(); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST * 10); - setupOneFileAloneInAProject(50, 12, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET); - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50, 12)); + setupOneFileAloneInAProject(50, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET); + measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50)); underTest.visit(treeRootHolder.getRoot()); - assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 8.33, 0); - assertNewDebtRatioValues(ROOT_REF, 8.33, 0); + assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 8.33); + assertNewDebtRatioValues(ROOT_REF, 8.33); } @Test public void new_debt_ratio_changes_with_new_technical_debt() { - setTwoPeriods(); + setPeriod(); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); - setupOneFileAloneInAProject(500, 120, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET); - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(500, 120)); + setupOneFileAloneInAProject(500, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET); + measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(500)); underTest.visit(treeRootHolder.getRoot()); - assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 833.33, 0); - assertNewDebtRatioValues(ROOT_REF, 833.33, 0); + assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 833.33); + assertNewDebtRatioValues(ROOT_REF, 833.33); } @Test public void new_debt_ratio_on_non_file_level_is_based_on_new_technical_debt_of_that_level() { - setTwoPeriods(); + setPeriod(); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); - setupOneFileAloneInAProject(500, 120, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET); - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(1200, 820)); + setupOneFileAloneInAProject(500, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET); + measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(1200)); underTest.visit(treeRootHolder.getRoot()); - assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 833.33, 0); - assertNewDebtRatioValues(ROOT_REF, 833.33, 0); + assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 833.33); + assertNewDebtRatioValues(ROOT_REF, 833.33); } @Test public void new_debt_ratio_when_file_is_unit_test() { - setTwoPeriods(); + setPeriod(); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); - setupOneFileAloneInAProject(500, 120, Flag.UT_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET); - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(1200, 820)); + setupOneFileAloneInAProject(500, Flag.UT_FILE, Flag.WITH_NCLOC, Flag.WITH_CHANGESET); + measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(1200)); underTest.visit(treeRootHolder.getRoot()); - assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 833.33, 0); - assertNewDebtRatioValues(ROOT_REF, 833.33, 0); + assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 833.33); + assertNewDebtRatioValues(ROOT_REF, 833.33); } @Test public void new_debt_ratio_is_0_when_file_has_no_changesets() { - setTwoPeriods(); + setPeriod(); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); - setupOneFileAloneInAProject(50, 12, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.NO_CHANGESET); - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50, 12)); + setupOneFileAloneInAProject(50, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.NO_CHANGESET); + measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50)); underTest.visit(treeRootHolder.getRoot()); - assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0, 0); - assertNewDebtRatioValues(ROOT_REF, 0, 0); + assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0); + assertNewDebtRatioValues(ROOT_REF, 0); } @Test public void new_debt_ratio_is_0_on_non_file_level_when_no_file_has_changesets() { - setTwoPeriods(); + setPeriod(); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); - setupOneFileAloneInAProject(50, 12, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.NO_CHANGESET); - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(200, 162)); + setupOneFileAloneInAProject(50, Flag.SRC_FILE, Flag.WITH_NCLOC, Flag.NO_CHANGESET); + measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(200)); underTest.visit(treeRootHolder.getRoot()); - assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0, 0); - assertNewDebtRatioValues(ROOT_REF, 0, 0); + assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0); + assertNewDebtRatioValues(ROOT_REF, 0); } @Test public void new_debt_ratio_is_0_when_there_is_no_ncloc_in_file() { - setTwoPeriods(); + setPeriod(); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); - setupOneFileAloneInAProject(50, 12, Flag.SRC_FILE, Flag.NO_NCLOC, Flag.WITH_CHANGESET); - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50, 12)); + setupOneFileAloneInAProject(50, Flag.SRC_FILE, Flag.NO_NCLOC, Flag.WITH_CHANGESET); + measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50)); underTest.visit(treeRootHolder.getRoot()); - assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0, 0); - assertNewDebtRatioValues(ROOT_REF, 0, 0); + assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0); + assertNewDebtRatioValues(ROOT_REF, 0); } @Test public void new_debt_ratio_is_0_on_non_file_level_when_one_file_has_zero_new_debt_because_of_no_changeset() { - setTwoPeriods(); + setPeriod(); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); - setupOneFileAloneInAProject(50, 12, Flag.SRC_FILE, Flag.NO_NCLOC, Flag.WITH_CHANGESET); - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(200, 162)); + setupOneFileAloneInAProject(50, Flag.SRC_FILE, Flag.NO_NCLOC, Flag.WITH_CHANGESET); + measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(200)); underTest.visit(treeRootHolder.getRoot()); - assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0, 0); - assertNewDebtRatioValues(ROOT_REF, 0, 0); + assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0); + assertNewDebtRatioValues(ROOT_REF, 0); } @Test public void new_debt_ratio_is_0_when_ncloc_measure_is_missing() { - setTwoPeriods(); + setPeriod(); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); - setupOneFileAloneInAProject(50, 12, Flag.SRC_FILE, Flag.MISSING_MEASURE_NCLOC, Flag.WITH_CHANGESET); - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50, 12)); + setupOneFileAloneInAProject(50, Flag.SRC_FILE, Flag.MISSING_MEASURE_NCLOC, Flag.WITH_CHANGESET); + measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(50)); underTest.visit(treeRootHolder.getRoot()); - assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0, 0); - assertNewDebtRatioValues(ROOT_REF, 0, 0); + assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 0); + assertNewDebtRatioValues(ROOT_REF, 0); } @Test public void leaf_components_always_have_a_measure_when_at_least_one_period_exist_and_ratio_is_computed_from_current_level_new_debt() { - setTwoPeriods(); + setPeriod(); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); treeRootHolder.setRoot( builder(PROJECT, ROOT_REF) @@ -303,69 +301,27 @@ public class NewMaintainabilityMeasuresVisitorTest { .build()) .build()); - Measure newDebtMeasure = createNewDebtMeasure(50, 12); + Measure newDebtMeasure = createNewDebtMeasure(50); measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure); - measureRepository.addRawMeasure(111, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(150, 112)); - measureRepository.addRawMeasure(11, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(200, 112)); - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(250, 212)); + measureRepository.addRawMeasure(111, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(150)); + measureRepository.addRawMeasure(11, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(200)); + measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(250)); // 4 lines file, only first one is not ncloc measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4)); // first 2 lines are before all snapshots, 2 last lines are after PERIOD 2's snapshot date - scmInfoRepository.setScmInfo(LANGUAGE_1_FILE_REF, createChangesets(PERIOD_2_SNAPSHOT_DATE - 100, 2, PERIOD_2_SNAPSHOT_DATE + 100, 2)); + scmInfoRepository.setScmInfo(LANGUAGE_1_FILE_REF, createChangesets(PERIOD_SNAPSHOT_DATE - 100, 2, PERIOD_SNAPSHOT_DATE + 100, 2)); underTest.visit(treeRootHolder.getRoot()); - assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 83.33, 0); - assertNewDebtRatioValues(111, 83.33, 0); - assertNewDebtRatioValues(11, 83.33, 0); - assertNewDebtRatioValues(ROOT_REF, 83.33, 0); - } - - @Test - public void new_debt_ratio_is_computed_for_five_periods() throws Exception { - long period1 = 10000L; - long period2 = 20000L; - long period3 = 30000L; - long period4 = 40000L; - long period5 = 50000L; - - periodsHolder.setPeriods( - new Period(1, SOME_PERIOD_MODE, null, period1, SOME_ANALYSIS_UUID), - new Period(2, SOME_PERIOD_MODE, null, period2, SOME_ANALYSIS_UUID), - new Period(3, SOME_PERIOD_MODE, null, period3, SOME_ANALYSIS_UUID), - new Period(4, SOME_PERIOD_MODE, null, period4, SOME_ANALYSIS_UUID), - new Period(5, SOME_PERIOD_MODE, null, period5, SOME_ANALYSIS_UUID)); - - when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); - - treeRootHolder.setRoot( - builder(PROJECT, ROOT_REF) - .addChildren(builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build()) - .build()); - - Measure newDebtMeasure = newMeasureBuilder().setVariations(new MeasureVariations(500d, 500d, 500d, 120d, 120d)).createNoValue(); - measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure); - // 4 lines file, only first one is not ncloc - measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4)); - // first 2 lines are before all snapshots, 2 last lines are after PERIOD 2's snapshot date - scmInfoRepository.setScmInfo(LANGUAGE_1_FILE_REF, createChangesets(period2 - 100, 2, period2 + 100, 2)); - - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, - newMeasureBuilder().setVariations(new MeasureVariations(1200d, 1200d, 1200d, 820d, 820d)).createNoValue()); - - underTest.visit(treeRootHolder.getRoot()); - - assertThat(measureRepository.getAddedRawMeasure(LANGUAGE_1_FILE_REF, NEW_SQALE_DEBT_RATIO_KEY)) - .hasVariation1(833.333, VARIATION_COMPARISON_OFFSET) - .hasVariation2(833.333, VARIATION_COMPARISON_OFFSET) - .hasVariation3(0d, VARIATION_COMPARISON_OFFSET) - .hasVariation4(0d, VARIATION_COMPARISON_OFFSET) - .hasVariation5(0d, VARIATION_COMPARISON_OFFSET); + assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 83.33); + assertNewDebtRatioValues(111, 83.33); + assertNewDebtRatioValues(11, 83.33); + assertNewDebtRatioValues(ROOT_REF, 83.33); } @Test public void compute_new_maintainability_rating() throws Exception { - setTwoPeriods(); + setPeriod(); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); treeRootHolder.setRoot( builder(PROJECT, ROOT_REF) @@ -379,27 +335,27 @@ public class NewMaintainabilityMeasuresVisitorTest { .build()) .build()); - Measure newDebtMeasure = createNewDebtMeasure(50, 12); + Measure newDebtMeasure = createNewDebtMeasure(50); measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure); - measureRepository.addRawMeasure(111, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(150, 112)); - measureRepository.addRawMeasure(11, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(200, 112)); - measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(250, 212)); + measureRepository.addRawMeasure(111, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(150)); + measureRepository.addRawMeasure(11, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(200)); + measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(250)); // 4 lines file, only first one is not ncloc measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4)); // first 2 lines are before all snapshots, 2 last lines are after PERIOD 2's snapshot date - scmInfoRepository.setScmInfo(LANGUAGE_1_FILE_REF, createChangesets(PERIOD_2_SNAPSHOT_DATE - 100, 2, PERIOD_2_SNAPSHOT_DATE + 100, 2)); + scmInfoRepository.setScmInfo(LANGUAGE_1_FILE_REF, createChangesets(PERIOD_SNAPSHOT_DATE - 100, 2, PERIOD_SNAPSHOT_DATE + 100, 2)); underTest.visit(treeRootHolder.getRoot()); - assertNewMaintainability(LANGUAGE_1_FILE_REF, D, A); - assertNewMaintainability(111, D, A); - assertNewMaintainability(11, D, A); - assertNewMaintainability(ROOT_REF, D, A); + assertNewMaintainability(LANGUAGE_1_FILE_REF, D); + assertNewMaintainability(111, D); + assertNewMaintainability(11, D); + assertNewMaintainability(ROOT_REF, D); } @Test public void compute_new_maintainability_rating_to_A_when_no_debt() throws Exception { - setTwoPeriods(); + setPeriod(); when(ratingSettings.getDevCost(LANGUAGE_1_KEY)).thenReturn(LANGUAGE_1_DEV_COST); treeRootHolder.setRoot( builder(PROJECT, ROOT_REF) @@ -415,13 +371,13 @@ public class NewMaintainabilityMeasuresVisitorTest { underTest.visit(treeRootHolder.getRoot()); - assertNewMaintainability(LANGUAGE_1_FILE_REF, A, A); - assertNewMaintainability(111, A, A); - assertNewMaintainability(11, A, A); - assertNewMaintainability(ROOT_REF, A, A); + assertNewMaintainability(LANGUAGE_1_FILE_REF, A); + assertNewMaintainability(111, A); + assertNewMaintainability(11, A); + assertNewMaintainability(ROOT_REF, A); } - private void setupOneFileAloneInAProject(int newDebtPeriod2, int newDebtPeriod4, Flag isUnitTest, Flag withNclocLines, Flag withChangeSets) { + private void setupOneFileAloneInAProject(int newDebt, Flag isUnitTest, Flag withNclocLines, Flag withChangeSets) { checkArgument(isUnitTest == Flag.UT_FILE || isUnitTest == Flag.SRC_FILE); checkArgument(withNclocLines == Flag.WITH_NCLOC || withNclocLines == Flag.NO_NCLOC || withNclocLines == Flag.MISSING_MEASURE_NCLOC); checkArgument(withChangeSets == Flag.WITH_CHANGESET || withChangeSets == Flag.NO_CHANGESET); @@ -432,7 +388,7 @@ public class NewMaintainabilityMeasuresVisitorTest { builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(isUnitTest == Flag.UT_FILE, LANGUAGE_1_KEY, 1)).build()) .build()); - Measure newDebtMeasure = createNewDebtMeasure(newDebtPeriod2, newDebtPeriod4); + Measure newDebtMeasure = createNewDebtMeasure(newDebt); measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure); if (withNclocLines == Flag.WITH_NCLOC) { // 4 lines file, only first one is not ncloc @@ -443,7 +399,7 @@ public class NewMaintainabilityMeasuresVisitorTest { } if (withChangeSets == Flag.WITH_CHANGESET) { // first 2 lines are before all snapshots, 2 last lines are after PERIOD 2's snapshot date - scmInfoRepository.setScmInfo(LANGUAGE_1_FILE_REF, createChangesets(PERIOD_2_SNAPSHOT_DATE - 100, 2, PERIOD_2_SNAPSHOT_DATE + 100, 2)); + scmInfoRepository.setScmInfo(LANGUAGE_1_FILE_REF, createChangesets(PERIOD_SNAPSHOT_DATE - 100, 2, PERIOD_SNAPSHOT_DATE + 100, 2)); } } @@ -455,8 +411,8 @@ public class NewMaintainabilityMeasuresVisitorTest { return ReportComponent.builder(type, ref).setKey(String.valueOf(ref)); } - private Measure createNewDebtMeasure(double period2Value, double period4Value) { - return newMeasureBuilder().setVariations(new MeasureVariations(null, period2Value, null, period4Value, null)).createNoValue(); + private Measure createNewDebtMeasure(double variation) { + return newMeasureBuilder().setVariation(variation).createNoValue(); } private static Measure createNclocDataMeasure(Integer... nclocLines) { @@ -511,25 +467,20 @@ public class NewMaintainabilityMeasuresVisitorTest { .isAbsent(); } - private void assertNewDebtRatioValues(int componentRef, double expectedPeriod2Value, double expectedPeriod4Value) { - assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SQALE_DEBT_RATIO_KEY)) - .hasVariation2(expectedPeriod2Value, VARIATION_COMPARISON_OFFSET) - .hasVariation4(expectedPeriod4Value, VARIATION_COMPARISON_OFFSET); + private void assertNewDebtRatioValues(int componentRef, double expectedVariation) { + assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_SQALE_DEBT_RATIO_KEY)).hasVariation(expectedVariation, VARIATION_COMPARISON_OFFSET); } - private void assertNewMaintainability(int componentRef, Rating expectedPeriod2Value, Rating expectedPeriod4Value) { - assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_MAINTAINABILITY_RATING_KEY)) - .hasVariation2(expectedPeriod2Value.getIndex()) - .hasVariation4(expectedPeriod4Value.getIndex()); + private void assertNewMaintainability(int componentRef, Rating expectedVariation) { + assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_MAINTAINABILITY_RATING_KEY)).hasVariation(expectedVariation.getIndex()); } private void assertNoNewMaintainability(int componentRef) { assertThat(measureRepository.getAddedRawMeasure(componentRef, NEW_MAINTAINABILITY_RATING_KEY)) - .isAbsent(); } + .isAbsent(); + } - private void setTwoPeriods() { - periodsHolder.setPeriods( - new Period(2, SOME_PERIOD_MODE, null, PERIOD_2_SNAPSHOT_DATE, SOME_ANALYSIS_UUID), - new Period(4, SOME_PERIOD_MODE, null, PERIOD_5_SNAPSHOT_DATE, SOME_ANALYSIS_UUID)); + private void setPeriod() { + periodsHolder.setPeriod(new Period(SOME_PERIOD_MODE, null, PERIOD_SNAPSHOT_DATE, SOME_ANALYSIS_UUID)); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java index 1d962c7d637..1c196a3d8c0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/qualitymodel/NewReliabilityAndSecurityRatingMeasuresVisitorTest.java @@ -106,7 +106,7 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitorTest { public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository); @Rule - public PeriodsHolderRule periodsHolder = new PeriodsHolderRule().setPeriods(new Period(1, "mode", null, LEAK_PERIOD_SNAPSHOT_IN_MILLISEC, "UUID")); + public PeriodsHolderRule periodsHolder = new PeriodsHolderRule().setPeriod(new Period("mode", null, LEAK_PERIOD_SNAPSHOT_IN_MILLISEC, "UUID")); @Rule public ComponentIssuesRepositoryRule componentIssuesRepositoryRule = new ComponentIssuesRepositoryRule(treeRootHolder); @@ -114,7 +114,7 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitorTest { @Rule public FillComponentIssuesVisitorRule fillComponentIssuesVisitorRule = new FillComponentIssuesVisitorRule(componentIssuesRepositoryRule, treeRootHolder); - VisitorsCrawler underTest = new VisitorsCrawler(Arrays.asList(fillComponentIssuesVisitorRule, + private VisitorsCrawler underTest = new VisitorsCrawler(Arrays.asList(fillComponentIssuesVisitorRule, new NewReliabilityAndSecurityRatingMeasuresVisitor(metricRepository, measureRepository, componentIssuesRepositoryRule, periodsHolder))); @Test @@ -130,7 +130,7 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitorTest { @Test public void no_measure_if_there_is_no_period() { - periodsHolder.setPeriods(); + periodsHolder.setPeriod(null); treeRootHolder.setRoot(builder(PROJECT, 1).build()); underTest.visit(treeRootHolder.getRoot()); @@ -323,7 +323,7 @@ public class NewReliabilityAndSecurityRatingMeasuresVisitorTest { private void verifyAddedRawMeasureOnLeakPeriod(int componentRef, String metricKey, Rating rating) { MeasureAssert.assertThat(measureRepository.getAddedRawMeasure(componentRef, metricKey)) - .hasVariation1(rating.getIndex()); + .hasVariation(rating.getIndex()); } private static DefaultIssue newBugIssue(long effort, String severity) { -- 2.39.5