@Test public void shouldNotSaveDataWhenNoMeasures() { NewCoverageAggregator aggregator = new NewCoverageAggregator(); DecoratorContext context = mock(DecoratorContext.class); when(context.getChildrenMeasures(CoreMetrics.NEW_LINES_TO_COVER)) .thenReturn(Collections.<Measure>emptyList()); aggregator.aggregate(context, CoreMetrics.NEW_LINES_TO_COVER, 3); verify(context, never()).saveMeasure(Matchers.<Measure>anyObject()); }
@Test public void shouldSumValues() { NewCoverageAggregator aggregator = new NewCoverageAggregator(); DecoratorContext context = mock(DecoratorContext.class); when(context.getChildrenMeasures(CoreMetrics.NEW_LINES_TO_COVER)) .thenReturn(Arrays.asList(newMeasure(null, 3.0, 2.0), newMeasure(null, 13.0, null))); aggregator.aggregate(context, CoreMetrics.NEW_LINES_TO_COVER, 3); verify(context) .saveMeasure( argThat( new ArgumentMatcher<Measure>() { @Override public boolean matches(Object o) { Measure m = (Measure) o; return m.getVariation2() == 16.0 && m.getVariation3() == 2.0; } })); }