diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-12-21 22:45:37 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-12-21 22:45:37 +0000 |
commit | 6d5308e5a52bddee3570a7836f94a497f2389f09 (patch) | |
tree | 9dea926c5757ed8c088ee09a1d2cb03444f3234b | |
parent | 2398469a24eb259e8b8de911a373bb49615d761c (diff) | |
download | sonarqube-6d5308e5a52bddee3570a7836f94a497f2389f09.tar.gz sonarqube-6d5308e5a52bddee3570a7836f94a497f2389f09.zip |
SONAR-1941 fix tracking of violations since previous analysis
2 files changed, 13 insertions, 10 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java index 5f981991dd2..c491feafdab 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/NewViolationsDecorator.java @@ -168,7 +168,7 @@ public class NewViolationsDecorator implements Decorator { } private boolean isAfter(Violation violation, Date date) { - return !violation.getCreatedAt().before(date); + return violation.getCreatedAt()!= null && violation.getCreatedAt().after(date); } private Metric getMetricForSeverity(RulePriority severity) { diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java index 34e6963a642..0ac22acda20 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/NewViolationsDecoratorTest.java @@ -19,6 +19,7 @@ */ package org.sonar.plugins.core.timemachine; +import com.google.common.collect.Lists; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.time.DateUtils; import org.hamcrest.BaseMatcher; @@ -108,8 +109,8 @@ public class NewViolationsDecoratorTest { List<Violation> violations = createViolations(); assertThat(decorator.countViolations(null, fiveDaysAgo), is(0)); - assertThat(decorator.countViolations(violations, fiveDaysAgo), is(3)); - assertThat(decorator.countViolations(violations, tenDaysAgo), is(6)); + assertThat(decorator.countViolations(violations, fiveDaysAgo), is(1)); // 1 rightNow + assertThat(decorator.countViolations(violations, tenDaysAgo), is(3)); // 1 rightNow + 2 fiveDaysAgo } @Test @@ -142,10 +143,11 @@ public class NewViolationsDecoratorTest { decorator.decorate(resource, context); + // remember : period1 is 5daysAgo, period2 is 10daysAgo verify(context).saveMeasure(argThat(new IsVariationMeasure(CoreMetrics.NEW_BLOCKER_VIOLATIONS, 0.0, 0.0))); - verify(context).saveMeasure(argThat(new IsVariationMeasure(CoreMetrics.NEW_CRITICAL_VIOLATIONS, 1.0, 2.0))); - verify(context).saveMeasure(argThat(new IsVariationMeasure(CoreMetrics.NEW_MAJOR_VIOLATIONS, 1.0, 2.0))); - verify(context).saveMeasure(argThat(new IsVariationMeasure(CoreMetrics.NEW_MINOR_VIOLATIONS, 1.0, 2.0))); + verify(context).saveMeasure(argThat(new IsVariationMeasure(CoreMetrics.NEW_CRITICAL_VIOLATIONS, 1.0, 1.0))); + verify(context).saveMeasure(argThat(new IsVariationMeasure(CoreMetrics.NEW_MAJOR_VIOLATIONS, 0.0, 1.0))); + verify(context).saveMeasure(argThat(new IsVariationMeasure(CoreMetrics.NEW_MINOR_VIOLATIONS, 0.0, 1.0))); verify(context).saveMeasure(argThat(new IsVariationMeasure(CoreMetrics.NEW_INFO_VIOLATIONS, 0.0, 0.0))); } @@ -155,13 +157,14 @@ public class NewViolationsDecoratorTest { decorator.decorate(resource, context); - verify(context).saveMeasure(argThat(new IsVariationRuleMeasure(CoreMetrics.NEW_VIOLATIONS, rule1, RulePriority.CRITICAL, 1.0, 2.0))); - verify(context).saveMeasure(argThat(new IsVariationRuleMeasure(CoreMetrics.NEW_VIOLATIONS, rule2, RulePriority.MAJOR, 1.0, 2.0))); - verify(context).saveMeasure(argThat(new IsVariationRuleMeasure(CoreMetrics.NEW_VIOLATIONS, rule3, RulePriority.MINOR, 1.0, 2.0))); + // remember : period1 is 5daysAgo, period2 is 10daysAgo + verify(context).saveMeasure(argThat(new IsVariationRuleMeasure(CoreMetrics.NEW_VIOLATIONS, rule1, RulePriority.CRITICAL, 1.0, 1.0))); + verify(context).saveMeasure(argThat(new IsVariationRuleMeasure(CoreMetrics.NEW_VIOLATIONS, rule2, RulePriority.MAJOR, 0.0, 1.0))); + verify(context).saveMeasure(argThat(new IsVariationRuleMeasure(CoreMetrics.NEW_VIOLATIONS, rule3, RulePriority.MINOR, 0.0, 1.0))); } private List<Violation> createViolations() { - List<Violation> violations = new ArrayList<Violation>(); + List<Violation> violations = Lists.newLinkedList(); violations.add(Violation.create(rule1, resource).setSeverity(RulePriority.CRITICAL).setCreatedAt(rightNow)); violations.add(Violation.create(rule1, resource).setSeverity(RulePriority.CRITICAL).setCreatedAt(tenDaysAgo)); violations.add(Violation.create(rule2, resource).setSeverity(RulePriority.MAJOR).setCreatedAt(fiveDaysAgo)); |