summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2013-11-05 17:02:58 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2013-11-05 17:02:58 +0100
commitab0c1f192ba9619561f9b4a829c581a01575aecd (patch)
tree80980b08d7fb4ec9c036cd4587bf4443fa45268e /plugins
parent903a49973b6a2d207f7535bcbc109ba8e04d6e20 (diff)
downloadsonarqube-ab0c1f192ba9619561f9b4a829c581a01575aecd.tar.gz
sonarqube-ab0c1f192ba9619561f9b4a829c581a01575aecd.zip
SONAR-4700 Refactor the way to get differential periods by loading them only at project levels
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java44
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java23
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java17
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java10
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java4
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecoratorTest.java42
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java27
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java12
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java4
9 files changed, 64 insertions, 119 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java
index 79aa634f16b..2b080b9092e 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java
@@ -20,45 +20,25 @@
package org.sonar.plugins.core.issue;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.HashMultiset;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ListMultimap;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multiset;
-import com.google.common.collect.Sets;
+import com.google.common.collect.*;
import org.apache.commons.lang.time.DateUtils;
-import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.DecoratorBarriers;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.DependedUpon;
-import org.sonar.api.batch.DependsUpon;
+import org.sonar.api.batch.*;
import org.sonar.api.component.ResourcePerspectives;
import org.sonar.api.issue.Issuable;
import org.sonar.api.issue.Issue;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.MeasureUtils;
-import org.sonar.api.measures.MeasuresFilters;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.RuleMeasure;
+import org.sonar.api.measures.*;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RulePriority;
-import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.Period;
import org.sonar.batch.components.TimeMachineConfiguration;
import javax.annotation.Nullable;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
/**
* Computes metrics related to number of issues.
@@ -100,7 +80,7 @@ public class CountUnresolvedIssuesDecorator implements Decorator {
CoreMetrics.OPEN_ISSUES,
CoreMetrics.REOPENED_ISSUES,
CoreMetrics.CONFIRMED_ISSUES
- );
+ );
}
public void decorate(Resource resource, DecoratorContext context) {
@@ -232,9 +212,9 @@ public class CountUnresolvedIssuesDecorator implements Decorator {
for (Rule rule : rules) {
RuleMeasure measure = RuleMeasure.createForRule(metric, rule, null);
measure.setSeverity(severity);
- for (PastSnapshot pastSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
- int variationIndex = pastSnapshot.getIndex();
- int count = countIssuesAfterDate(issuesPerRule.get(rule), pastSnapshot.getTargetDate());
+ for (Period period : timeMachineConfiguration.periods()) {
+ int variationIndex = period.getIndex();
+ int count = countIssuesAfterDate(issuesPerRule.get(rule), period.getTargetDate());
double sum = MeasureUtils.sumOnVariation(true, variationIndex, childMeasuresPerRule.get(rule)) + count;
measure.setVariation(variationIndex, sum);
}
@@ -244,11 +224,11 @@ public class CountUnresolvedIssuesDecorator implements Decorator {
}
private void saveNewIssues(DecoratorContext context, Measure measure, Collection<Issue> issues) {
- for (PastSnapshot pastSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
- int variationIndex = pastSnapshot.getIndex();
+ for (Period period : timeMachineConfiguration.periods()) {
+ int variationIndex = period.getIndex();
Collection<Measure> children = context.getChildrenMeasures(measure.getMetric());
// SONAR-3647 Use real snapshot date and not target date in order to stay consistent with other measure variations
- Date datePlusOneSecond = pastSnapshot.getDate() != null ? DateUtils.addSeconds(pastSnapshot.getDate(), 1) : null;
+ Date datePlusOneSecond = period.getDate() != null ? DateUtils.addSeconds(period.getDate(), 1) : null;
int count = countIssuesAfterDate(issues, datePlusOneSecond);
double sum = MeasureUtils.sumOnVariation(true, variationIndex, children) + count;
measure.setVariation(variationIndex, sum);
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java
index 4c13b404164..a5677b6a55c 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/AbstractNewCoverageFileAnalyzer.java
@@ -31,7 +31,7 @@ import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.KeyValueFormat;
-import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.Period;
import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.core.DryRunIncompatible;
@@ -51,8 +51,8 @@ public abstract class AbstractNewCoverageFileAnalyzer implements Decorator {
public AbstractNewCoverageFileAnalyzer(TimeMachineConfiguration timeMachineConfiguration) {
structs = Lists.newArrayList();
- for (PastSnapshot pastSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
- structs.add(new PeriodStruct(pastSnapshot));
+ for (Period period : timeMachineConfiguration.periods()) {
+ structs.add(new PeriodStruct(period.getIndex(), period.getTargetDate()));
}
}
@@ -66,7 +66,7 @@ public abstract class AbstractNewCoverageFileAnalyzer implements Decorator {
public abstract Metric getCoveredConditionsByLineMetric();
- public abstract Metric getNewLinesToCoverMetric();
+ public abstract Metric getNewLinesToCoverMetric();
public abstract Metric getNewUncoveredLinesMetric();
@@ -147,7 +147,7 @@ public abstract class AbstractNewCoverageFileAnalyzer implements Decorator {
Measure newUncoveredConditions = new Measure(getNewUncoveredConditionsMetric());
for (PeriodStruct struct : structs) {
- if(struct.hasNewCode()) {
+ if (struct.hasNewCode()) {
newLines.setVariation(struct.index, (double) struct.getNewLines());
newUncoveredLines.setVariation(struct.index, (double) (struct.getNewLines() - struct.getNewCoveredLines()));
newConditions.setVariation(struct.index, (double) struct.getNewConditions());
@@ -176,11 +176,6 @@ public abstract class AbstractNewCoverageFileAnalyzer implements Decorator {
Integer newConditions;
Integer newCoveredConditions;
- PeriodStruct(PastSnapshot pastSnapshot) {
- this.index = pastSnapshot.getIndex();
- this.date = pastSnapshot.getTargetDate();
- }
-
PeriodStruct(int index, Date date) {
this.index = index;
this.date = date;
@@ -205,12 +200,12 @@ public abstract class AbstractNewCoverageFileAnalyzer implements Decorator {
}
void addLine(boolean covered) {
- if(newLines == null) {
+ if (newLines == null) {
newLines = 0;
}
newLines += 1;
if (covered) {
- if(newCoveredLines == null) {
+ if (newCoveredLines == null) {
newCoveredLines = 0;
}
newCoveredLines += 1;
@@ -218,12 +213,12 @@ public abstract class AbstractNewCoverageFileAnalyzer implements Decorator {
}
void addConditions(int count, int countCovered) {
- if(newConditions == null) {
+ if (newConditions == null) {
newConditions = 0;
}
newConditions += count;
if (count > 0) {
- if(newCoveredConditions == null) {
+ if (newCoveredConditions == null) {
newCoveredConditions = 0;
}
newCoveredConditions += countCovered;
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java
index 39003a8e688..98629d24ab9 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyDecorator.java
@@ -31,7 +31,7 @@ import org.sonar.api.measures.MetricFinder;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
-import org.sonar.batch.components.TimeMachineConfiguration;
+import org.sonar.batch.components.PeriodsDefinition;
import org.sonar.core.DryRunIncompatible;
import java.util.List;
@@ -45,13 +45,11 @@ public class TendencyDecorator implements Decorator {
private TimeMachine timeMachine;
private TimeMachineQuery query;
private TendencyAnalyser analyser;
- private TimeMachineConfiguration configuration;
private List<Metric> metrics;
- public TendencyDecorator(TimeMachine timeMachine, MetricFinder metricFinder, TimeMachineConfiguration configuration) {
+ public TendencyDecorator(TimeMachine timeMachine, MetricFinder metricFinder) {
this.timeMachine = timeMachine;
this.analyser = new TendencyAnalyser();
- this.configuration = configuration;
this.metrics = Lists.newLinkedList();
for (Metric metric : metricFinder.findAll()) {
if (metric.isNumericType()) {
@@ -60,11 +58,10 @@ public class TendencyDecorator implements Decorator {
}
}
- TendencyDecorator(TimeMachine timeMachine, TimeMachineQuery query, TendencyAnalyser analyser, TimeMachineConfiguration configuration) {
+ TendencyDecorator(TimeMachine timeMachine, TimeMachineQuery query, TendencyAnalyser analyser) {
this.timeMachine = timeMachine;
this.query = query;
this.analyser = analyser;
- this.configuration = configuration;
}
@DependsUpon
@@ -73,13 +70,13 @@ public class TendencyDecorator implements Decorator {
}
protected TimeMachineQuery initQuery(Project project) {
- int days = configuration.getTendencyPeriodInDays();
+ int days = PeriodsDefinition.CORE_TENDENCY_DEPTH_DEFAULT_VALUE;
// resource is set after
query = new TimeMachineQuery(null)
- .setFrom(DateUtils.addDays(project.getAnalysisDate(), -days))
- .setToCurrentAnalysis(true)
- .setMetrics(metrics);
+ .setFrom(DateUtils.addDays(project.getAnalysisDate(), -days))
+ .setToCurrentAnalysis(true)
+ .setMetrics(metrics);
return query;
}
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java
index c969d44ee6e..8be8b8a77fd 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java
@@ -29,19 +29,19 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
import org.sonar.batch.components.PastSnapshot;
-import org.sonar.batch.components.TimeMachineConfiguration;
+import org.sonar.batch.components.PeriodsDefinition;
import java.util.List;
@DependedUpon(DecoratorBarriers.END_OF_TIME_MACHINE)
public final class TimeMachineConfigurationPersister implements Decorator {
- private TimeMachineConfiguration configuration;
+ private PeriodsDefinition periodsDefinition;
private Snapshot projectSnapshot;
private DatabaseSession session;
- public TimeMachineConfigurationPersister(TimeMachineConfiguration configuration, Snapshot projectSnapshot, DatabaseSession session) {
- this.configuration = configuration;
+ public TimeMachineConfigurationPersister(PeriodsDefinition periodsDefinition, Snapshot projectSnapshot, DatabaseSession session) {
+ this.periodsDefinition = periodsDefinition;
this.projectSnapshot = projectSnapshot;
this.session = session;
}
@@ -53,7 +53,7 @@ public final class TimeMachineConfigurationPersister implements Decorator {
}
void persistConfiguration() {
- List<PastSnapshot> pastSnapshots = configuration.getProjectPastSnapshots();
+ List<PastSnapshot> pastSnapshots = periodsDefinition.projectPastSnapshots();
for (PastSnapshot pastSnapshot : pastSnapshots) {
Snapshot snapshot = session.reattach(Snapshot.class, projectSnapshot.getId());
updatePeriodParams(snapshot, pastSnapshot);
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
index c081abb44e8..c952b4fb811 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/VariationDecorator.java
@@ -43,8 +43,8 @@ public class VariationDecorator implements Decorator {
private PastMeasuresLoader pastMeasuresLoader;
- public VariationDecorator(PastMeasuresLoader pastMeasuresLoader, MetricFinder metricFinder, TimeMachineConfiguration configuration) {
- this(pastMeasuresLoader, metricFinder, configuration.getProjectPastSnapshots());
+ public VariationDecorator(PastMeasuresLoader pastMeasuresLoader, MetricFinder metricFinder, TimeMachineConfiguration timeMachineConfiguration) {
+ this(pastMeasuresLoader, metricFinder, timeMachineConfiguration.modulePastSnapshots());
}
VariationDecorator(PastMeasuresLoader pastMeasuresLoader, MetricFinder metricFinder, List<PastSnapshot> projectPastSnapshots) {
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecoratorTest.java
index 8641611c457..6b24decb2c7 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecoratorTest.java
@@ -31,11 +31,7 @@ import org.sonar.api.component.ResourcePerspectives;
import org.sonar.api.issue.Issuable;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.MeasuresFilter;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.RuleMeasure;
+import org.sonar.api.measures.*;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
@@ -45,10 +41,9 @@ import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.test.IsRuleMeasure;
-import org.sonar.batch.components.PastSnapshot;
+import org.sonar.batch.components.Period;
import org.sonar.batch.components.TimeMachineConfiguration;
-import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
@@ -60,12 +55,7 @@ import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyDouble;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
public class CountUnresolvedIssuesDecoratorTest {
@@ -104,18 +94,8 @@ public class CountUnresolvedIssuesDecoratorTest {
afterFiveDaysAgo = DateUtils.addDays(fiveDaysAgo, 1);
sameSecond = DateUtils.truncate(rightNow, Calendar.SECOND);
- PastSnapshot pastSnapshot = mock(PastSnapshot.class);
- when(pastSnapshot.getIndex()).thenReturn(1);
- when(pastSnapshot.getDate()).thenReturn(afterFiveDaysAgo);
- when(pastSnapshot.getTargetDate()).thenReturn(fiveDaysAgo);
-
- PastSnapshot pastSnapshot2 = mock(PastSnapshot.class);
- when(pastSnapshot2.getIndex()).thenReturn(2);
- when(pastSnapshot2.getDate()).thenReturn(afterTenDaysAgo);
- when(pastSnapshot2.getTargetDate()).thenReturn(tenDaysAgo);
-
timeMachineConfiguration = mock(TimeMachineConfiguration.class);
- when(timeMachineConfiguration.getProjectPastSnapshots()).thenReturn(Arrays.asList(pastSnapshot, pastSnapshot2));
+ when(timeMachineConfiguration.periods()).thenReturn(newArrayList(new Period(1, fiveDaysAgo, afterFiveDaysAgo), new Period(2, tenDaysAgo, afterTenDaysAgo)));
project = mock(Project.class);
resource = mock(Resource.class);
@@ -139,7 +119,7 @@ public class CountUnresolvedIssuesDecoratorTest {
public void should_count_issues() {
when(resource.getScope()).thenReturn(Scopes.PROJECT);
when(issuable.issues()).thenReturn(createissues());
- when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure> emptyList());
+ when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
decorator.decorate(resource, context);
@@ -164,7 +144,7 @@ public class CountUnresolvedIssuesDecoratorTest {
public void should_not_count_issues_if_measure_already_exists() {
when(resource.getScope()).thenReturn(Scopes.PROJECT);
when(issuable.issues()).thenReturn(createissues());
- when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure> emptyList());
+ when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
when(context.getMeasure(CoreMetrics.VIOLATIONS)).thenReturn(new Measure(CoreMetrics.VIOLATIONS, 3000.0));
when(context.getMeasure(CoreMetrics.MAJOR_VIOLATIONS)).thenReturn(new Measure(CoreMetrics.MAJOR_VIOLATIONS, 500.0));
@@ -178,8 +158,8 @@ public class CountUnresolvedIssuesDecoratorTest {
@Test
public void should_save_zero_on_projects() {
when(resource.getScope()).thenReturn(Scopes.PROJECT);
- when(issuable.issues()).thenReturn(Lists.<Issue> newArrayList());
- when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure> emptyList());
+ when(issuable.issues()).thenReturn(Lists.<Issue>newArrayList());
+ when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
decorator.decorate(resource, context);
@@ -189,8 +169,8 @@ public class CountUnresolvedIssuesDecoratorTest {
@Test
public void should_save_zero_on_directories() {
when(resource.getScope()).thenReturn(Scopes.DIRECTORY);
- when(issuable.issues()).thenReturn(Lists.<Issue> newArrayList());
- when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure> emptyList());
+ when(issuable.issues()).thenReturn(Lists.<Issue>newArrayList());
+ when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
decorator.decorate(resource, context);
@@ -201,7 +181,7 @@ public class CountUnresolvedIssuesDecoratorTest {
public void should_count_issues_by_severity() {
when(resource.getScope()).thenReturn(Scopes.PROJECT);
when(issuable.issues()).thenReturn(createissues());
- when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure> emptyList());
+ when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
decorator.decorate(resource, context);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
index 9b4c09e8794..51764b8c789 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TendencyDecoratorTest.java
@@ -28,7 +28,6 @@ import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.resources.JavaPackage;
import org.sonar.api.resources.Project;
-import org.sonar.batch.components.TimeMachineConfiguration;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -50,7 +49,7 @@ public class TendencyDecoratorTest {
MetricFinder metricFinder = mock(MetricFinder.class);
when(metricFinder.findAll()).thenReturn(Arrays.asList(CoreMetrics.LINES, CoreMetrics.COVERAGE, CoreMetrics.COVERAGE_LINE_HITS_DATA, CoreMetrics.PROFILE));
- TendencyDecorator decorator = new TendencyDecorator(null, metricFinder, newConf());
+ TendencyDecorator decorator = new TendencyDecorator(null, metricFinder);
TimeMachineQuery query = decorator.initQuery(project);
assertThat(query.getMetrics().size(), is(2));
@@ -59,12 +58,6 @@ public class TendencyDecoratorTest {
assertThat(query.isToCurrentAnalysis(), is(true));
}
- private TimeMachineConfiguration newConf() {
- TimeMachineConfiguration configuration = mock(TimeMachineConfiguration.class);
- when(configuration.getTendencyPeriodInDays()).thenReturn(30);
- return configuration;
- }
-
@Test
public void includeCurrentMeasures() throws ParseException {
TendencyAnalyser analyser = mock(TendencyAnalyser.class);
@@ -72,18 +65,18 @@ public class TendencyDecoratorTest {
TimeMachine timeMachine = mock(TimeMachine.class);
when(timeMachine.getMeasuresFields(query)).thenReturn(Arrays.<Object[]>asList(
- new Object[]{date("2009-12-01"), CoreMetrics.LINES, 1200.0},
- new Object[]{date("2009-12-01"), CoreMetrics.COVERAGE, 80.5},
- new Object[]{date("2009-12-02"), CoreMetrics.LINES, 1300.0},
- new Object[]{date("2009-12-02"), CoreMetrics.COVERAGE, 79.6},
- new Object[]{date("2009-12-15"), CoreMetrics.LINES, 1150.0}
+ new Object[]{date("2009-12-01"), CoreMetrics.LINES, 1200.0},
+ new Object[]{date("2009-12-01"), CoreMetrics.COVERAGE, 80.5},
+ new Object[]{date("2009-12-02"), CoreMetrics.LINES, 1300.0},
+ new Object[]{date("2009-12-02"), CoreMetrics.COVERAGE, 79.6},
+ new Object[]{date("2009-12-15"), CoreMetrics.LINES, 1150.0}
));
DecoratorContext context = mock(DecoratorContext.class);
when(context.getMeasure(CoreMetrics.LINES)).thenReturn(new Measure(CoreMetrics.LINES, 1400.0));
when(context.getMeasure(CoreMetrics.COVERAGE)).thenReturn(new Measure(CoreMetrics.LINES, 90.0));
- TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser, newConf());
+ TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
decorator.decorate(new JavaPackage("org.foo"), context);
verify(analyser).analyseLevel(Arrays.asList(1200.0, 1300.0, 1150.0, 1400.0));
@@ -97,12 +90,12 @@ public class TendencyDecoratorTest {
TimeMachine timeMachine = mock(TimeMachine.class);
when(timeMachine.getMeasuresFields(query)).thenReturn(Arrays.<Object[]>asList(
- new Object[]{date("2009-12-01"), CoreMetrics.LINES, 1200.0},
- new Object[]{date("2009-12-02"), CoreMetrics.LINES, 1300.0}
+ new Object[]{date("2009-12-01"), CoreMetrics.LINES, 1200.0},
+ new Object[]{date("2009-12-02"), CoreMetrics.LINES, 1300.0}
));
DecoratorContext context = mock(DecoratorContext.class);
- TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser, newConf());
+ TendencyDecorator decorator = new TendencyDecorator(timeMachine, query, analyser);
decorator.decorate(new JavaPackage("org.foo"), context);
verify(analyser, never()).analyseLevel(anyList());
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
index 888377f435d..80ffb808806 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
@@ -23,7 +23,7 @@ import org.junit.Test;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.utils.DateUtils;
import org.sonar.batch.components.PastSnapshot;
-import org.sonar.batch.components.TimeMachineConfiguration;
+import org.sonar.batch.components.PeriodsDefinition;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import java.util.Arrays;
@@ -37,15 +37,15 @@ public class TimeMachineConfigurationPersisterTest extends AbstractDbUnitTestCas
public void shouldSaveConfigurationInSnapshotsTable() {
setupData("shared");
- TimeMachineConfiguration conf = mock(TimeMachineConfiguration.class);
+ PeriodsDefinition periodsDefinition = mock(PeriodsDefinition.class);
PastSnapshot vs1 = new PastSnapshot("days", DateUtils.parseDate("2009-01-25"), getSession().getSingleResult(Snapshot.class, "id", 100))
- .setModeParameter("30").setIndex(1);
+ .setModeParameter("30").setIndex(1);
PastSnapshot vs3 = new PastSnapshot("version", DateUtils.parseDate("2008-12-13"), getSession().getSingleResult(Snapshot.class, "id", 300))
- .setModeParameter("1.2.3").setIndex(3);
- when(conf.getProjectPastSnapshots()).thenReturn(Arrays.asList(vs1, vs3));
+ .setModeParameter("1.2.3").setIndex(3);
+ when(periodsDefinition.projectPastSnapshots()).thenReturn(Arrays.asList(vs1, vs3));
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
- TimeMachineConfigurationPersister persister = new TimeMachineConfigurationPersister(conf, projectSnapshot, getSession());
+ TimeMachineConfigurationPersister persister = new TimeMachineConfigurationPersister(periodsDefinition, projectSnapshot, getSession());
persister.persistConfiguration();
checkTables("shouldSaveConfigurationInSnapshotsTable", "snapshots");
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
index fb3c0508f50..746f5f00d98 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/VariationDecoratorTest.java
@@ -52,8 +52,8 @@ public class VariationDecoratorTest extends AbstractDbUnitTestCase {
@Test
public void shouldComputeVariations() {
- TimeMachineConfiguration conf = mock(TimeMachineConfiguration.class);
- VariationDecorator decorator = new VariationDecorator(mock(PastMeasuresLoader.class), mock(MetricFinder.class), conf);
+ TimeMachineConfiguration timeMachineConfiguration = mock(TimeMachineConfiguration.class);
+ VariationDecorator decorator = new VariationDecorator(mock(PastMeasuresLoader.class), mock(MetricFinder.class), timeMachineConfiguration);
assertThat(decorator.shouldComputeVariation(new Project("foo"))).isTrue();
assertThat(decorator.shouldComputeVariation(new File("foo/bar.c"))).isFalse();