aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-10-05 13:56:08 +0200
committerDavid Gageot <david@gageot.net>2012-10-05 13:56:25 +0200
commit824b3b9facd472d989596a214edbbc660df2dc1d (patch)
tree13d9df366e1bfa3eb1d8226ff2f8b7a8d839cca7 /plugins
parent9ecd1e8d2219a2eab8aa08ff978b2348ec8e40d5 (diff)
downloadsonarqube-824b3b9facd472d989596a214edbbc660df2dc1d.tar.gz
sonarqube-824b3b9facd472d989596a214edbbc660df2dc1d.zip
Add more tests
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java28
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java28
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallCoverageDecoratorTest.java28
3 files changed, 84 insertions, 0 deletions
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java
index 0a9a0a9ddb4..16efef23eb3 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CoverageDecoratorTest.java
@@ -105,6 +105,19 @@ public class CoverageDecoratorTest {
verify(context, never()).saveMeasure(eq(CoreMetrics.COVERAGE), anyDouble());
}
+ @Test
+ public void should_count_covered_elements_for_new_code() {
+ Measure newLines = measureWithVariation(1, 100.0);
+ Measure newUncoveredConditions = measureWithVariation(1, 10.0);
+ Measure newUncoveredLines = measureWithVariation(1, 5.0);
+ Measure newConditions = measureWithVariation(1, 1.0);
+ DecoratorContext context = mockNewContext(newLines, newUncoveredConditions, newUncoveredLines, newConditions);
+
+ long count = decorator.countCoveredElementsForNewCode(context, 1);
+
+ assertThat(count).isEqualTo(86).isEqualTo(100 + 1 - 10 - 5);
+ }
+
private static DecoratorContext mockContext(int lines, int uncoveredLines, int conditions, int uncoveredConditions) {
DecoratorContext context = mock(DecoratorContext.class);
when(context.getMeasure(CoreMetrics.LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.LINES_TO_COVER, (double) lines));
@@ -113,4 +126,19 @@ public class CoverageDecoratorTest {
when(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.UNCOVERED_CONDITIONS, (double) uncoveredConditions));
return context;
}
+
+ private static DecoratorContext mockNewContext(Measure newLines, Measure newUncoveredConditions, Measure newUncoveredLines, Measure newConditions) {
+ DecoratorContext context = mock(DecoratorContext.class);
+ when(context.getMeasure(CoreMetrics.NEW_LINES_TO_COVER)).thenReturn(newLines);
+ when(context.getMeasure(CoreMetrics.NEW_UNCOVERED_LINES)).thenReturn(newUncoveredLines);
+ when(context.getMeasure(CoreMetrics.NEW_UNCOVERED_CONDITIONS)).thenReturn(newUncoveredConditions);
+ when(context.getMeasure(CoreMetrics.NEW_CONDITIONS_TO_COVER)).thenReturn(newConditions);
+ return context;
+ }
+
+ private static Measure measureWithVariation(int period, double variation) {
+ Measure measure = mock(Measure.class);
+ when(measure.getVariation(period)).thenReturn(variation);
+ return measure;
+ }
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java
index 1fc2089a376..b8e3afb2162 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ItCoverageDecoratorTest.java
@@ -105,6 +105,19 @@ public class ItCoverageDecoratorTest {
verify(context, never()).saveMeasure(eq(CoreMetrics.IT_COVERAGE), anyDouble());
}
+ @Test
+ public void should_count_covered_elements_for_new_code() {
+ Measure newLines = measureWithVariation(1, 100.0);
+ Measure newUncoveredConditions = measureWithVariation(1, 10.0);
+ Measure newUncoveredLines = measureWithVariation(1, 5.0);
+ Measure newConditions = measureWithVariation(1, 1.0);
+ DecoratorContext context = mockNewContext(newLines, newUncoveredConditions, newUncoveredLines, newConditions);
+
+ long count = decorator.countCoveredElementsForNewCode(context, 1);
+
+ assertThat(count).isEqualTo(86).isEqualTo(100 + 1 - 10 - 5);
+ }
+
private static DecoratorContext mockContext(int lines, int uncoveredLines, int conditions, int uncoveredConditions) {
DecoratorContext context = mock(DecoratorContext.class);
when(context.getMeasure(CoreMetrics.IT_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.IT_LINES_TO_COVER, (double) lines));
@@ -113,4 +126,19 @@ public class ItCoverageDecoratorTest {
when(context.getMeasure(CoreMetrics.IT_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.IT_UNCOVERED_CONDITIONS, (double) uncoveredConditions));
return context;
}
+
+ private static DecoratorContext mockNewContext(Measure newLines, Measure newUncoveredConditions, Measure newUncoveredLines, Measure newConditions) {
+ DecoratorContext context = mock(DecoratorContext.class);
+ when(context.getMeasure(CoreMetrics.NEW_IT_LINES_TO_COVER)).thenReturn(newLines);
+ when(context.getMeasure(CoreMetrics.NEW_IT_UNCOVERED_LINES)).thenReturn(newUncoveredLines);
+ when(context.getMeasure(CoreMetrics.NEW_IT_UNCOVERED_CONDITIONS)).thenReturn(newUncoveredConditions);
+ when(context.getMeasure(CoreMetrics.NEW_IT_CONDITIONS_TO_COVER)).thenReturn(newConditions);
+ return context;
+ }
+
+ private static Measure measureWithVariation(int period, double variation) {
+ Measure measure = mock(Measure.class);
+ when(measure.getVariation(period)).thenReturn(variation);
+ return measure;
+ }
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallCoverageDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallCoverageDecoratorTest.java
index 7ec96574cee..546f9b8e312 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallCoverageDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/OverallCoverageDecoratorTest.java
@@ -105,6 +105,19 @@ public class OverallCoverageDecoratorTest {
verify(context, never()).saveMeasure(eq(CoreMetrics.OVERALL_COVERAGE), anyDouble());
}
+ @Test
+ public void should_count_covered_elements_for_new_code() {
+ Measure newLines = measureWithVariation(1, 100.0);
+ Measure newUncoveredConditions = measureWithVariation(1, 10.0);
+ Measure newUncoveredLines = measureWithVariation(1, 5.0);
+ Measure newConditions = measureWithVariation(1, 1.0);
+ DecoratorContext context = mockNewContext(newLines, newUncoveredConditions, newUncoveredLines, newConditions);
+
+ long count = decorator.countCoveredElementsForNewCode(context, 1);
+
+ assertThat(count).isEqualTo(86).isEqualTo(100 + 1 - 10 - 5);
+ }
+
private static DecoratorContext mockContext(int lines, int uncoveredLines, int conditions, int uncoveredConditions) {
DecoratorContext context = mock(DecoratorContext.class);
when(context.getMeasure(CoreMetrics.OVERALL_LINES_TO_COVER)).thenReturn(new Measure(CoreMetrics.OVERALL_LINES_TO_COVER, (double) lines));
@@ -113,4 +126,19 @@ public class OverallCoverageDecoratorTest {
when(context.getMeasure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS)).thenReturn(new Measure(CoreMetrics.OVERALL_UNCOVERED_CONDITIONS, (double) uncoveredConditions));
return context;
}
+
+ private static DecoratorContext mockNewContext(Measure newLines, Measure newUncoveredConditions, Measure newUncoveredLines, Measure newConditions) {
+ DecoratorContext context = mock(DecoratorContext.class);
+ when(context.getMeasure(CoreMetrics.NEW_OVERALL_LINES_TO_COVER)).thenReturn(newLines);
+ when(context.getMeasure(CoreMetrics.NEW_OVERALL_UNCOVERED_LINES)).thenReturn(newUncoveredLines);
+ when(context.getMeasure(CoreMetrics.NEW_OVERALL_UNCOVERED_CONDITIONS)).thenReturn(newUncoveredConditions);
+ when(context.getMeasure(CoreMetrics.NEW_OVERALL_CONDITIONS_TO_COVER)).thenReturn(newConditions);
+ return context;
+ }
+
+ private static Measure measureWithVariation(int period, double variation) {
+ Measure measure = mock(Measure.class);
+ when(measure.getVariation(period)).thenReturn(variation);
+ return measure;
+ }
}