summaryrefslogtreecommitdiffstats
path: root/plugins/sonar-surefire-plugin
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-04-08 09:13:10 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-04-08 09:13:10 +0200
commit7d231a67761c8c5637435d21a7e24364bb00fbe1 (patch)
tree707248a373f86ab868165cd1432eb5bd0f857e86 /plugins/sonar-surefire-plugin
parentaa5de1d8e7f8f6d68f9be98ad9536e4f6db88b6f (diff)
downloadsonarqube-7d231a67761c8c5637435d21a7e24364bb00fbe1.tar.gz
sonarqube-7d231a67761c8c5637435d21a7e24364bb00fbe1.zip
SONAR-2322 Filter unit tests files listed in surefire reports
Diffstat (limited to 'plugins/sonar-surefire-plugin')
-rw-r--r--plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/api/AbstractSurefireParser.java21
-rw-r--r--plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/api/AbstractSurefireParserTest.java23
2 files changed, 5 insertions, 39 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 b13e667ebe0..c8d6a5fd372 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
@@ -73,7 +73,7 @@ public abstract class AbstractSurefireParser {
private void parseFiles(SensorContext context, File[] reports) {
UnitTestIndex index = new UnitTestIndex();
parseFiles(reports, index);
- sanitize(index, context);
+ sanitize(index);
save(index, context);
}
@@ -90,23 +90,12 @@ public abstract class AbstractSurefireParser {
}
}
- private void sanitize(UnitTestIndex index, SensorContext context) {
+ private void sanitize(UnitTestIndex index) {
for (String classname : index.getClassnames()) {
- Resource resource = getUnitTestResource(classname);
- if (resource != null && context.isIndexed(resource, false)) {
- // ok
-
- } else if (StringUtils.contains(classname, "$")) {
- // Java inner class
+ if (StringUtils.contains(classname, "$")) {
+ // Surefire reports classes whereas sonar supports files
String parentClassName = StringUtils.substringBeforeLast(classname, "$");
- Resource parentResource = getUnitTestResource(parentClassName);
- if (parentResource != null && context.isIndexed(parentResource, false)) {
- index.merge(classname, parentClassName);
- } else {
- index.remove(classname);
- }
- } else {
- index.remove(classname);
+ index.merge(classname, parentClassName);
}
}
}
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 84fef260f4f..697c94a5750 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
@@ -83,29 +83,6 @@ public class AbstractSurefireParserTest {
verify(context, never()).saveMeasure(eq(CoreMetrics.TESTS), anyDouble());
}
- /**
- * This use-case occurs in projects mixing Groovy and Java tests. All test files are listed in surefire reports,
- * but only Java files are indexed into sonar.
- */
- @Test
- public void shouldIgnoreNonIndexedFiles() throws URISyntaxException {
- AbstractSurefireParser parser = newParser();
-
- SensorContext context = mock(SensorContext.class);
- when(context.isIndexed(argThat(new BaseMatcher<Resource>(){
- public boolean matches(Object o) {
- return ((Resource)o).getName().startsWith("java");
- }
- public void describeTo(Description description) {
- }
- }), eq(false))).thenReturn(true);
-
- parser.collect(new Project("foo"), context, getDir("groovyAndJavaTests"));
-
- verify(context).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "java.Foo")), eq(CoreMetrics.TESTS), eq(6.0));
- verify(context, never()).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.FILE, "groovy.Foo")), any(Metric.class), anyDouble());
- }
-
@Test
public void shouldMergeInnerClasses() throws URISyntaxException {
AbstractSurefireParser parser = newParser();