diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-01-30 09:37:15 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-01-30 09:38:03 +0100 |
commit | d783de7be0a66c3f0969610d276b3f63dd1a6747 (patch) | |
tree | 8343bb1ce7d5416e808b76009d69d0adb5ef0b6e /sonar-core | |
parent | 8d9eb9edf1ea931aabd94a4e6fe1cbe5343e93a3 (diff) | |
download | sonarqube-d783de7be0a66c3f0969610d276b3f63dd1a6747.tar.gz sonarqube-d783de7be0a66c3f0969610d276b3f63dd1a6747.zip |
SONAR-4093 Display number of tests covering a line
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java | 3 | ||||
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java | 32 |
2 files changed, 20 insertions, 15 deletions
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 07590798d3a..5b6bb74405d 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 @@ -101,8 +101,7 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase { } public void covers(Testable testable, List<Integer> lines) { - Vertex componentVertex = GraphUtil.single(beanGraph().getUnderlyingGraph().getVertices("key", testable.component().key())); - beanGraph().getUnderlyingGraph().addEdge(null, element(), componentVertex, "covers").setProperty("lines", lines); + beanGraph().getUnderlyingGraph().addEdge(null, element(), ((BeanVertex) testable).element(), "covers").setProperty("lines", lines); } public TestPlan testPlan() { diff --git a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java b/sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java index debd0d4aa54..661e7b3ce97 100644 --- a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java +++ b/sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java @@ -32,11 +32,9 @@ import org.sonar.core.graph.GraphUtil; import java.util.Collection; import java.util.List; -import java.util.Set; import java.util.SortedSet; import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Sets.newHashSet; import static com.google.common.collect.Sets.newTreeSet; public class DefaultTestable extends BeanVertex implements MutableTestable { @@ -48,7 +46,7 @@ public class DefaultTestable extends BeanVertex implements MutableTestable { public Collection<TestCase> coveringTestCases() { List<TestCase> testCases = newArrayList(); - for (Edge edge : element().getEdges(Direction.IN, "covers")){ + for (Edge edge : getCovers()){ Vertex testable = edge.getVertex(Direction.OUT); testCases.add(beanGraph().wrap(testable, DefaultTestCase.class)); } @@ -56,23 +54,31 @@ public class DefaultTestable extends BeanVertex implements MutableTestable { } public Collection<TestCase> testCasesCoveringLine(int line) { - Set<TestCase> testCases = newHashSet(); - for (Edge edge : element().getEdges(Direction.IN, "covers")){ - if (Iterables.contains( (List<Integer>) edge.getProperty("lines"), line)){ - Vertex testable = edge.getVertex(Direction.OUT); - testCases.add(beanGraph().wrap(testable, DefaultTestCase.class)); + List<TestCase> testCases = newArrayList(); + for (Edge edge : getCovers()){ + if (Iterables.contains(getCoveredLines(edge), Long.valueOf(line))){ + Vertex vertexTestable = edge.getVertex(Direction.OUT); + DefaultTestCase testCase = beanGraph().wrap(vertexTestable, DefaultTestCase.class); + testCases.add(testCase); } } return testCases; } - public SortedSet<Integer> coveredLines() { - SortedSet<Integer> coveredLines = newTreeSet(); - for (Edge edge : element().getEdges(Direction.IN, "covers")){ - List<Integer> lines = (List<Integer>) edge.getProperty("lines"); - coveredLines.addAll(lines); + public SortedSet<Long> coveredLines() { + SortedSet<Long> coveredLines = newTreeSet(); + for (Edge edge : getCovers()){ + coveredLines.addAll(getCoveredLines(edge)); } return coveredLines; } + private Iterable<Edge> getCovers(){ + return element().getEdges(Direction.IN, "covers"); + } + + private List<Long> getCoveredLines(Edge edge){ + return (List<Long>) edge.getProperty("lines"); + } + }
\ No newline at end of file |