diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-01-29 15:56:43 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-01-29 15:56:43 +0100 |
commit | ddf176b98ea07bf1fe530c25141caa8be22916d1 (patch) | |
tree | 33ee69cfcda3745c5fea1c9d5034c2effa2aff42 /sonar-core | |
parent | 16dee1a8ef024b31bf04e699e4ff166dec4a352b (diff) | |
download | sonarqube-ddf176b98ea07bf1fe530c25141caa8be22916d1.tar.gz sonarqube-ddf176b98ea07bf1fe530c25141caa8be22916d1.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 | 29 | ||||
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java | 25 |
2 files changed, 44 insertions, 10 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 23e2789d4ff..07590798d3a 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 @@ -24,8 +24,6 @@ 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; @@ -40,8 +38,6 @@ import java.util.List; public class DefaultTestCase extends BeanVertex implements MutableTestCase { - private static final Logger LOG = LoggerFactory.getLogger(DefaultTestCase.class); - public String type() { return (String) getProperty("type"); } @@ -105,8 +101,6 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase { } public void covers(Testable testable, List<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); } @@ -132,4 +126,27 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase { public Collection<CoveredTestable> coveredTestable() { return null; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + DefaultTestCase that = (DefaultTestCase) o; + + if (key() != null ? !key().equals(that.key()) : that.key() != null) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + return key() != null ? key().hashCode() : 0; + } } 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 d2e72ae271c..debd0d4aa54 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 @@ -19,6 +19,7 @@ */ package org.sonar.core.test; +import com.google.common.collect.Iterables; import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Vertex; @@ -29,9 +30,13 @@ import org.sonar.core.component.ComponentVertex; import org.sonar.core.graph.BeanVertex; 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 { @@ -41,12 +46,24 @@ public class DefaultTestable extends BeanVertex implements MutableTestable { return beanGraph().wrap(component, ComponentVertex.class); } - public List<TestCase> coveringTestCases() { - return null; + public Collection<TestCase> coveringTestCases() { + List<TestCase> testCases = newArrayList(); + for (Edge edge : element().getEdges(Direction.IN, "covers")){ + Vertex testable = edge.getVertex(Direction.OUT); + testCases.add(beanGraph().wrap(testable, DefaultTestCase.class)); + } + return testCases; } - public List<TestCase> testCasesCoveringLine(int line) { - return null; + 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)); + } + } + return testCases; } public SortedSet<Integer> coveredLines() { |