}
public void decorate(Resource resource, DecoratorContext context) {
- clearCache();
prepareCurrentResourceViolations(context);
saveNewViolations(context);
saveNewViolationsByPriority(context);
saveNewViolationsByRule(context);
+ clearCache();
}
private void clearCache() {
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;
assertThat(decorator.sumChildren(3, children), is(6));
}
+ @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());