summaryrefslogtreecommitdiffstats
path: root/plugins/sonar-surefire-plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/sonar-surefire-plugin')
-rw-r--r--plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/api/AbstractSurefireParser.java7
-rw-r--r--plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/SurefireSensorTest.java15
-rw-r--r--plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java29
3 files changed, 31 insertions, 20 deletions
diff --git a/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/api/AbstractSurefireParser.java b/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/api/AbstractSurefireParser.java
index d0cc6262093..85e7a2682f8 100644
--- a/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/api/AbstractSurefireParser.java
+++ b/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/api/AbstractSurefireParser.java
@@ -47,7 +47,12 @@ public abstract class AbstractSurefireParser {
public void collect(Project project, SensorContext context, File reportsDir) {
File[] xmlFiles = getReports(reportsDir);
- if (xmlFiles.length != 0) {
+ if (xmlFiles.length == 0) {
+ // See http://jira.codehaus.org/browse/SONAR-2371
+ if (project.getModules().isEmpty()) {
+ context.saveMeasure(CoreMetrics.TESTS, 0.0);
+ }
+ } else {
parseFiles(context, xmlFiles);
}
}
diff --git a/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/SurefireSensorTest.java b/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/SurefireSensorTest.java
index 690603fc091..d288fc12454 100644
--- a/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/SurefireSensorTest.java
+++ b/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/SurefireSensorTest.java
@@ -19,6 +19,12 @@
*/
package org.sonar.plugins.surefire;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.*;
+
import org.apache.commons.lang.ObjectUtils;
import org.custommonkey.xmlunit.DetailedDiff;
import org.custommonkey.xmlunit.Diff;
@@ -40,15 +46,6 @@ import java.io.FileReader;
import java.io.StringReader;
import java.net.URISyntaxException;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.anyDouble;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
-
public class SurefireSensorTest {
@Test
diff --git a/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java b/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java
index 15085fee0c4..e4d195ebe42 100644
--- a/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java
+++ b/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java
@@ -26,11 +26,11 @@ import org.sonar.api.batch.SensorContext;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
import org.sonar.api.resources.*;
-import org.sonar.api.resources.File;
import org.sonar.api.test.IsMeasure;
import org.sonar.api.test.IsResource;
import java.net.URISyntaxException;
+import java.util.Arrays;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyDouble;
@@ -52,34 +52,43 @@ public class AbstractSurefireParserTest {
verify(context, times(6)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE)), argThat(new IsMeasure(CoreMetrics.TEST_DATA)));
}
+ /**
+ * See http://jira.codehaus.org/browse/SONAR-2371
+ */
@Test
- public void shouldNotFailIfNoReports() throws URISyntaxException {
+ public void shouldInsertZeroWhenNoReports() throws URISyntaxException {
AbstractSurefireParser parser = newParser();
SensorContext context = mockContext();
+ Project project = mock(Project.class);
- parser.collect(new Project("foo"), context, getDir("noReports"));
+ parser.collect(project, context, getDir("noReports"));
- verifyZeroInteractions(context);
+ verify(context).saveMeasure(CoreMetrics.TESTS, 0.0);
}
+ /**
+ * See http://jira.codehaus.org/browse/SONAR-2371
+ */
@Test
- public void shouldNotInsertZeroOnFiles() throws URISyntaxException {
+ public void shouldNotInsertZeroWhenNoReports() throws URISyntaxException {
AbstractSurefireParser parser = newParser();
SensorContext context = mockContext();
+ Project project = mock(Project.class);
+ when(project.getModules()).thenReturn(Arrays.asList(new Project("foo")));
- parser.collect(new Project("foo"), context, getDir("noTests"));
+ parser.collect(project, context, getDir("noReports"));
- verify(context, never()).saveMeasure(any(Resource.class),(Metric)anyObject(), anyDouble());
+ verify(context, never()).saveMeasure(CoreMetrics.TESTS, 0.0);
}
@Test
- public void shouldNotInsertMeasuresOnPomProjects() throws URISyntaxException {
+ public void shouldNotInsertZeroOnFiles() throws URISyntaxException {
AbstractSurefireParser parser = newParser();
SensorContext context = mockContext();
- parser.collect(new Project("foo").setPackaging("pom"), context, getDir("noReports"));
+ parser.collect(new Project("foo"), context, getDir("noTests"));
- verify(context, never()).saveMeasure(eq(CoreMetrics.TESTS), anyDouble());
+ verify(context, never()).saveMeasure(any(Resource.class),(Metric)anyObject(), anyDouble());
}
@Test