@Test
public void shouldComputeVariationOfRuleMeasures() {
RuleFinder ruleFinder = mock(RuleFinder.class);
Rule rule1 = Rule.create("repo", "rule1");
rule1.setId(1);
Rule rule2 = Rule.create("repo", "rule2");
rule2.setId(2);
when(ruleFinder.findByKey(rule1.ruleKey())).thenReturn(rule1);
when(ruleFinder.findByKey(rule2.ruleKey())).thenReturn(rule2);
Resource dir = new Directory("org/foo");
PastMeasuresLoader pastMeasuresLoader = mock(PastMeasuresLoader.class);
PastSnapshot pastSnapshot1 = new PastSnapshot("days", new Date()).setIndex(1);
// first past analysis
when(pastMeasuresLoader.getPastMeasures(dir, pastSnapshot1)).thenReturn(Arrays.asList(
new Object[] {VIOLATIONS_ID, null, null, null, 180.0},// total
new Object[] {VIOLATIONS_ID, null, null, rule1.getId(), 100.0},// rule 1
new Object[] {VIOLATIONS_ID, null, null, rule2.getId(), 80.0})); // rule 2
// current analysis
DecoratorContext context = mock(DecoratorContext.class);
Measure violations = newMeasure(VIOLATIONS, 200.0);
Measure violationsRule1 = RuleMeasure.createForRule(VIOLATIONS, rule1, 130.0);