2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2008-2012 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * Sonar is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * Sonar is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.plugins.core.timemachine;
22 import org.hamcrest.BaseMatcher;
23 import org.hamcrest.Description;
24 import org.junit.Test;
25 import org.mockito.Matchers;
26 import org.sonar.api.batch.DecoratorContext;
27 import org.sonar.api.measures.CoreMetrics;
28 import org.sonar.api.measures.Measure;
30 import java.util.Arrays;
31 import java.util.Collections;
33 import static org.mockito.Mockito.*;
35 public class NewCoverageAggregatorTest {
38 public void shouldNotSaveDataWhenNoMeasures() {
39 NewCoverageAggregator aggregator = new NewCoverageAggregator();
40 DecoratorContext context = mock(DecoratorContext.class);
41 when(context.getChildrenMeasures(CoreMetrics.NEW_LINES_TO_COVER)).thenReturn(Collections.<Measure>emptyList());
43 aggregator.aggregate(context, CoreMetrics.NEW_LINES_TO_COVER, 3);
45 verify(context, never()).saveMeasure(Matchers.<Measure>anyObject());
49 public void shouldNotsetZeroWhenNoValueOnPeriod() {
50 NewCoverageAggregator aggregator = new NewCoverageAggregator();
51 DecoratorContext context = mock(DecoratorContext.class);
52 when(context.getChildrenMeasures(CoreMetrics.NEW_LINES_TO_COVER)).thenReturn(Arrays.asList(newMeasure(null, 3.0, 2.0), newMeasure(null, 13.0, null)));
54 aggregator.aggregate(context, CoreMetrics.NEW_LINES_TO_COVER, 3);
56 verify(context).saveMeasure(argThat(new BaseMatcher<Measure>() {
57 public boolean matches(Object o) {
58 Measure m = (Measure)o;
59 return m.getVariation1()==null;
62 public void describeTo(Description description) {
70 public void shouldSumValues() {
71 NewCoverageAggregator aggregator = new NewCoverageAggregator();
72 DecoratorContext context = mock(DecoratorContext.class);
73 when(context.getChildrenMeasures(CoreMetrics.NEW_LINES_TO_COVER)).thenReturn(Arrays.asList(newMeasure(null, 3.0, 2.0), newMeasure(null, 13.0, null)));
75 aggregator.aggregate(context, CoreMetrics.NEW_LINES_TO_COVER, 3);
77 verify(context).saveMeasure(argThat(new BaseMatcher<Measure>() {
78 public boolean matches(Object o) {
79 Measure m = (Measure)o;
80 return m.getVariation2()==16.0 && m.getVariation3()==2.0;
83 public void describeTo(Description description) {
90 private Measure newMeasure(Double variation1, Double variation2, Double variation3) {
91 return new Measure(CoreMetrics.NEW_LINES_TO_COVER)
92 .setVariation1(variation1)
93 .setVariation2(variation2)
94 .setVariation3(variation3);