if (isPositive(tests, true) && isPositive(errors, false) && isPositive(failures, false)) {
Double errorsAndFailuresRatio = (errors + failures) * 100.0 / tests;
context.saveMeasure(CoreMetrics.TEST_SUCCESS_DENSITY, 100.0 - errorsAndFailuresRatio);
- } else if (tests == null && ResourceUtils.isProject(resource)) {
- // See http://jira.codehaus.org/browse/SONAR-2371
- context.saveMeasure(CoreMetrics.TESTS, 0.0);
}
}
}
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.JavaPackage;
import org.sonar.api.resources.Project;
import java.util.Arrays;
when(context.getChildrenMeasures(metric)).thenReturn(Arrays.asList(new Measure(metric, value), new Measure(metric, value)));
}
- /**
- * See http://jira.codehaus.org/browse/SONAR-2371
- */
@Test
public void doNotDecorateIfTestsMeasureAlreadyExists() {
Project project = mock(Project.class);
verifyNoMoreInteractions(context);
}
- /**
- * See http://jira.codehaus.org/browse/SONAR-2371
- */
- @Test
- public void shouldSaveZeroOnProject() {
- Project project = new Project("").setAnalysisType(Project.AnalysisType.DYNAMIC);
-
- decorator.decorate(project, context);
-
- verify(context).saveMeasure(CoreMetrics.TESTS, 0.0);
- }
-
- /**
- * See http://jira.codehaus.org/browse/SONAR-2371
- */
- @Test
- public void shouldNotSaveZeroOnPackage() {
- JavaPackage pkg = new JavaPackage();
-
- decorator.decorate(pkg, context);
-
- assertThat(decorator.shouldDecorateResource(pkg, context), is(true));
- verify(context, never()).saveMeasure(CoreMetrics.TESTS, 0.0);
- }
-
}
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);
}
}
*/
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;
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
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;
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