diff options
author | Godin <mandrikov@gmail.com> | 2010-12-06 15:33:53 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-12-06 15:33:53 +0000 |
commit | 385c78d203bb1026e6a4227dfffc230a913d3959 (patch) | |
tree | 5a2d2f27c37723068d41c5cf9e12a52d9d4ab22f /plugins | |
parent | def5c589d4d2b79c8e4a0c6da5d18c34ca22a889 (diff) | |
download | sonarqube-385c78d203bb1026e6a4227dfffc230a913d3959.tar.gz sonarqube-385c78d203bb1026e6a4227dfffc230a913d3959.zip |
Add unit tests for NewViolationsDecorator
Diffstat (limited to 'plugins')
2 files changed, 15 insertions, 4 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 e3294c0de25..14edff0e40f 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 @@ -61,11 +61,11 @@ public class NewViolationsDecorator implements Decorator { } public void decorate(Resource resource, DecoratorContext context) { - clearCache(); prepareCurrentResourceViolations(context); saveNewViolations(context); saveNewViolationsByPriority(context); saveNewViolationsByRule(context); + clearCache(); } private void clearCache() { 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 520b5551a55..ce1400de6ab 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 @@ -44,9 +44,7 @@ import java.util.List; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; public class NewViolationsDecoratorTest { private Rule rule1; @@ -126,6 +124,19 @@ public class NewViolationsDecoratorTest { } @Test + public void shouldClearCacheAfterExecution() { + Violation violation1 = Violation.create(rule1, resource).setPriority(RulePriority.CRITICAL).setCreatedAt(rightNow); + Violation violation2 = Violation.create(rule2, resource).setPriority(RulePriority.CRITICAL).setCreatedAt(rightNow); + when(context.getViolations()).thenReturn(Arrays.asList(violation1)).thenReturn(Arrays.asList(violation2)); + + decorator.decorate(resource, context); + decorator.decorate(resource, context); + + verify(context, times(2)).saveMeasure(argThat(new IsVariationMeasure(CoreMetrics.NEW_CRITICAL_VIOLATIONS, 1.0, 1.0))); + verify(context, never()).saveMeasure(argThat(new IsVariationMeasure(CoreMetrics.NEW_CRITICAL_VIOLATIONS, 2.0, 2.0))); + } + + @Test public void priorityViolations() { when(context.getViolations()).thenReturn(createViolations()); |