aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-01-29 10:32:54 +0100
committerJulien Lancelot <julien.lancelot@gmail.com>2013-01-29 10:33:14 +0100
commit86199f0cbaeb53ce5419d9617b8ff5e46cc225c4 (patch)
tree2b2da2e793d0b1b4780473b9b2a55c7dd74cb363
parent9f3de2ad8b0aaff9ec309a50a1b5d0f3c578d7a8 (diff)
downloadsonarqube-86199f0cbaeb53ce5419d9617b8ff5e46cc225c4.tar.gz
sonarqube-86199f0cbaeb53ce5419d9617b8ff5e46cc225c4.zip
SONAR-4092 Display number of lines covered by a test
-rw-r--r--plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/web/tests_viewer.html.erb9
-rw-r--r--sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java23
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java4
4 files changed, 33 insertions, 7 deletions
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/web/tests_viewer.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/web/tests_viewer.html.erb
index b043a58fa10..d33f97d3993 100644
--- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/web/tests_viewer.html.erb
+++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/web/tests_viewer.html.erb
@@ -59,13 +59,8 @@
test_case[:name] = test.name()
test_case[:status] = test.status()
test_case[:time] = test.durationInMs()
- test_case[:covered_lines] = 0
- if test.coveredBlocks()
- has_covered_lines = true
- test.coveredBlocks().each do |covered_block|
- test_case[:covered_lines] += covered_block.lines().size
- end
- end
+ has_covered_lines = test.hasCoveredBlocks()
+ test_case[:covered_lines] = test.countCoveredBlocks() if test.hasCoveredBlocks()
if test.status() != 'ok'
test_case[:message] = ''
test_case[:message] = test.message() if test.message()
diff --git a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java b/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java
index 1c4a8c1ebcf..53febd013dc 100644
--- a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java
+++ b/sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java
@@ -20,8 +20,12 @@
package org.sonar.core.test;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
import com.tinkerpop.blueprints.Direction;
+import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonar.api.test.CoveredTestable;
import org.sonar.api.test.MutableTestCase;
import org.sonar.api.test.TestPlan;
@@ -32,10 +36,13 @@ import org.sonar.core.graph.GraphUtil;
import javax.annotation.Nullable;
import java.util.Collection;
+import java.util.List;
import java.util.Set;
public class DefaultTestCase extends BeanVertex implements MutableTestCase {
+ private static final Logger LOG = LoggerFactory.getLogger(DefaultTestCase.class);
+
public String type() {
return (String) getProperty("type");
}
@@ -99,7 +106,10 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase {
}
public void covers(Testable testable, Set<Integer> lines) {
+ LOG.info("Covers : " + testable.component().key(), " on "+ lines);
+ Vertex componentVertex = GraphUtil.single(beanGraph().getUnderlyingGraph().getVertices("key", testable.component().key()));
+ beanGraph().getUnderlyingGraph().addEdge(null, element(), componentVertex, "covers").setProperty("lines", lines);
}
public TestPlan testPlan() {
@@ -107,6 +117,19 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase {
return beanGraph().wrap(plan, DefaultTestPlan.class);
}
+ public boolean hasCoveredBlocks(){
+ return Iterables.size(element().getEdges(Direction.OUT, "covers")) > 0;
+ }
+
+ public int countCoveredBlocks() {
+ int coveredBlocks = 0;
+ for (Edge edge : element().getEdges(Direction.OUT, "covers")){
+ List<String> lines = (List<String>) edge.getProperty("lines");
+ coveredBlocks = coveredBlocks + lines.size();
+ }
+ return coveredBlocks;
+ }
+
public Collection<CoveredTestable> coveredBlocks() {
return null;
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java
index e978bf8b472..a7deec1ab08 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java
@@ -21,6 +21,8 @@ package org.sonar.api.test;
import javax.annotation.Nullable;
+import java.util.Set;
+
public interface MutableTestCase extends TestCase {
MutableTestCase setStatus(String s);
@@ -31,4 +33,6 @@ public interface MutableTestCase extends TestCase {
MutableTestCase setMessage(String s);
MutableTestCase setStackTrace(String s);
+
+ void covers(Testable testable, Set<Integer> lines);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java
index cf4ffba9c3e..b7e72e0cca1 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java
@@ -52,5 +52,9 @@ public interface TestCase {
TestPlan testPlan();
+ boolean hasCoveredBlocks();
+
+ int countCoveredBlocks();
+
Collection<CoveredTestable> coveredBlocks();
}