@Test
  public void shouldSaveZeroOnProjects() {
    when(resource.getScope()).thenReturn(Scopes.PROJECT);
    when(context.getViolations()).thenReturn(Collections.<Violation>emptyList());
    when(context.getChildrenMeasures((MeasuresFilter) anyObject()))
        .thenReturn(Collections.<Measure>emptyList());

    decorator.decorate(resource, context);

    verify(context).saveMeasure(CoreMetrics.VIOLATIONS, 0.0);
  }
  @Test
  public void sameRuleShouldHaveDifferentSeverities() {
    List<Violation> violations = Lists.newArrayList();
    violations.add(Violation.create(ruleA1, resource).setSeverity(RulePriority.CRITICAL));
    violations.add(Violation.create(ruleA1, resource).setSeverity(RulePriority.CRITICAL));
    violations.add(Violation.create(ruleA1, resource).setSeverity(RulePriority.MINOR));
    when(context.getViolations()).thenReturn(violations);

    decorator.decorate(resource, context);

    verify(context)
        .saveMeasure(argThat(new IsRuleMeasure(CoreMetrics.CRITICAL_VIOLATIONS, ruleA1, 2.0)));
    verify(context)
        .saveMeasure(argThat(new IsRuleMeasure(CoreMetrics.MINOR_VIOLATIONS, ruleA1, 1.0)));
  }
  @Test
  public void shouldCountViolationsBySeverity() {
    when(resource.getScope()).thenReturn(Scopes.PROJECT);
    when(context.getViolations()).thenReturn(createViolations());
    when(context.getChildrenMeasures((MeasuresFilter) anyObject()))
        .thenReturn(Collections.<Measure>emptyList());

    decorator.decorate(resource, context);

    verify(context).saveMeasure(CoreMetrics.BLOCKER_VIOLATIONS, 0.0);
    verify(context).saveMeasure(CoreMetrics.CRITICAL_VIOLATIONS, 2.0);
    verify(context).saveMeasure(CoreMetrics.MAJOR_VIOLATIONS, 1.0);
    verify(context).saveMeasure(CoreMetrics.MINOR_VIOLATIONS, 1.0);
    verify(context).saveMeasure(CoreMetrics.INFO_VIOLATIONS, 0.0);
  }
  /** See http://jira.codehaus.org/browse/SONAR-1729 */
  @Test
  public void shouldNotCountViolationsIfMeasureAlreadyExists() {
    when(resource.getScope()).thenReturn(Scopes.PROJECT);
    when(context.getViolations()).thenReturn(createViolations());
    when(context.getChildrenMeasures((MeasuresFilter) anyObject()))
        .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));

    decorator.decorate(resource, context);

    verify(context, never()).saveMeasure(eq(CoreMetrics.VIOLATIONS), anyDouble()); // not changed
    verify(context, never())
        .saveMeasure(eq(CoreMetrics.MAJOR_VIOLATIONS), anyDouble()); // not changed
    verify(context, times(1))
        .saveMeasure(eq(CoreMetrics.CRITICAL_VIOLATIONS), anyDouble()); // did not exist
  }