aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-02-06 15:58:34 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2013-02-06 17:59:16 +0100
commit0ff6aa3320c5d25d60170d0a4b4e9aca99292a64 (patch)
treef660ed67913b0b34b38ad708828a1256ef261e34 /sonar-core
parent8c464366c208f9b89186649e024ccbf9f792e3f3 (diff)
downloadsonarqube-0ff6aa3320c5d25d60170d0a4b4e9aca99292a64.tar.gz
sonarqube-0ff6aa3320c5d25d60170d0a4b4e9aca99292a64.zip
SONAR-2501 move type from test plan to test case
+ add Testable#coverageBlocks()
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/test/DefaultCoverageBlock.java (renamed from sonar-core/src/main/java/org/sonar/core/test/DefaultCover.java)4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java29
-rw-r--r--sonar-core/src/main/java/org/sonar/core/test/DefaultTestPlan.java9
-rw-r--r--sonar-core/src/main/java/org/sonar/core/test/DefaultTestable.java22
-rw-r--r--sonar-core/src/test/java/org/sonar/core/test/DefaultTestCaseTest.java28
-rw-r--r--sonar-core/src/test/java/org/sonar/core/test/DefaultTestPlanTest.java11
-rw-r--r--sonar-core/src/test/java/org/sonar/core/test/DefaultTestableTest.java20
7 files changed, 60 insertions, 63 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/test/DefaultCover.java b/sonar-core/src/main/java/org/sonar/core/test/DefaultCoverageBlock.java
index 8e0f9928f2f..f3c0b0b181e 100644
--- a/sonar-core/src/main/java/org/sonar/core/test/DefaultCover.java
+++ b/sonar-core/src/main/java/org/sonar/core/test/DefaultCoverageBlock.java
@@ -20,14 +20,14 @@
package org.sonar.core.test;
import com.tinkerpop.blueprints.Direction;
-import org.sonar.api.test.Cover;
+import org.sonar.api.test.CoverageBlock;
import org.sonar.api.test.TestCase;
import org.sonar.api.test.Testable;
import org.sonar.core.graph.BeanEdge;
import java.util.List;
-public class DefaultCover extends BeanEdge implements Cover {
+public class DefaultCoverageBlock extends BeanEdge implements CoverageBlock {
public TestCase testCase() {
return getVertex(DefaultTestCase.class, Direction.OUT);
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 7b535ad7c23..bb0fd524fde 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,9 @@ import com.google.common.collect.Iterables;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
-import org.sonar.api.test.Cover;
+import org.sonar.api.test.CoverageBlock;
import org.sonar.api.test.MutableTestCase;
+import org.sonar.api.test.MutableTestPlan;
import org.sonar.api.test.TestPlan;
import org.sonar.api.test.Testable;
import org.sonar.api.test.exception.IllegalDurationException;
@@ -38,6 +39,15 @@ import java.util.List;
public class DefaultTestCase extends BeanVertex implements MutableTestCase {
+ public String type() {
+ return (String) getProperty("type");
+ }
+
+ public MutableTestCase setType(@Nullable String s) {
+ setProperty("type", s);
+ return this;
+ }
+
public Long durationInMs() {
return (Long) getProperty("duration");
}
@@ -51,11 +61,11 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase {
}
public Status status() {
- return Status.of((String)getProperty("status"));
+ return Status.of((String) getProperty("status"));
}
public MutableTestCase setStatus(@Nullable Status s) {
- setProperty("status", s == null ? null : s.toString());
+ setProperty("status", s == null ? null : s.name());
return this;
}
@@ -86,8 +96,9 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase {
return this;
}
- public void setCover(Testable testable, List<Integer> lines) {
+ public MutableTestCase setCoverageBlock(Testable testable, List<Integer> lines) {
beanGraph().getUnderlyingGraph().addEdge(null, element(), ((BeanVertex) testable).element(), "covers").setProperty("lines", lines);
+ return this;
}
public TestPlan testPlan() {
@@ -108,13 +119,13 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase {
return result;
}
- public Iterable covers() {
- return getEdges(DefaultCover.class, Direction.OUT, "covers");
+ public Iterable<CoverageBlock> coverageBlocks() {
+ return (Iterable) getEdges(DefaultCoverageBlock.class, Direction.OUT, "covers");
}
- public Cover coverOfTestable(final Testable testable) {
- return Iterables.find(getEdges(DefaultCover.class, Direction.OUT, "covers"), new Predicate<Cover>() {
- public boolean apply(Cover input) {
+ public CoverageBlock coverageBlock(final Testable testable) {
+ return Iterables.find(getEdges(DefaultCoverageBlock.class, Direction.OUT, "covers"), new Predicate<CoverageBlock>() {
+ public boolean apply(CoverageBlock input) {
return input.testable().component().key().equals(testable.component().key());
}
}, null);
diff --git a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestPlan.java b/sonar-core/src/main/java/org/sonar/core/test/DefaultTestPlan.java
index a9c4b69cc02..01b7c08c59e 100644
--- a/sonar-core/src/main/java/org/sonar/core/test/DefaultTestPlan.java
+++ b/sonar-core/src/main/java/org/sonar/core/test/DefaultTestPlan.java
@@ -39,15 +39,6 @@ public class DefaultTestPlan extends BeanVertex implements MutableTestPlan {
return beanGraph().wrap(component, ComponentVertex.class);
}
- public String type() {
- return (String) getProperty("type");
- }
-
- public MutableTestPlan setType(String s) {
- setProperty("type", s);
- return this;
- }
-
@CheckForNull
public Iterable<MutableTestCase> testCasesByName(String name) {
List<MutableTestCase> result = Lists.newArrayList();
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 a3b4f2598c4..f44589e1421 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
@@ -27,7 +27,7 @@ import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import org.sonar.api.component.Component;
-import org.sonar.api.test.Cover;
+import org.sonar.api.test.CoverageBlock;
import org.sonar.api.test.MutableTestable;
import org.sonar.api.test.TestCase;
import org.sonar.core.component.ComponentVertex;
@@ -46,7 +46,7 @@ public class DefaultTestable extends BeanVertex implements MutableTestable {
public List<TestCase> testCases() {
ImmutableList.Builder<TestCase> cases = ImmutableList.builder();
- for (Edge coversEdge : covers()) {
+ for (Edge coversEdge : coverEdges()) {
Vertex testable = coversEdge.getVertex(Direction.OUT);
cases.add(beanGraph().wrap(testable, DefaultTestCase.class));
}
@@ -63,7 +63,7 @@ public class DefaultTestable extends BeanVertex implements MutableTestable {
public int countTestCasesOfLine(Integer line) {
int number = 0;
- for (Edge edge : covers()) {
+ for (Edge edge : coverEdges()) {
if (Iterables.contains(lines(edge), line)) {
number++;
}
@@ -73,7 +73,7 @@ public class DefaultTestable extends BeanVertex implements MutableTestable {
public List<TestCase> testCasesOfLine(int line) {
ImmutableList.Builder<TestCase> cases = ImmutableList.builder();
- for (Edge edge : covers()) {
+ for (Edge edge : coverEdges()) {
if (lines(edge).contains(line)) {
Vertex vertexTestable = edge.getVertex(Direction.OUT);
DefaultTestCase testCase = beanGraph().wrap(vertexTestable, DefaultTestCase.class);
@@ -85,21 +85,25 @@ public class DefaultTestable extends BeanVertex implements MutableTestable {
public SortedSet<Integer> testedLines() {
ImmutableSortedSet.Builder<Integer> coveredLines = ImmutableSortedSet.naturalOrder();
- for (Edge edge : covers()) {
+ for (Edge edge : coverEdges()) {
coveredLines.addAll(lines(edge));
}
return coveredLines.build();
}
- public Cover coverOfTestCase(final TestCase testCase) {
- return Iterables.find(getEdges(DefaultCover.class, Direction.IN, "covers"), new Predicate<Cover>() {
- public boolean apply(Cover input) {
+ public CoverageBlock coverageBlock(final TestCase testCase) {
+ return Iterables.find(getEdges(DefaultCoverageBlock.class, Direction.IN, "covers"), new Predicate<CoverageBlock>() {
+ public boolean apply(CoverageBlock input) {
return input.testCase().name().equals(testCase.name());
}
}, null);
}
- private Iterable<Edge> covers() {
+ public Iterable<CoverageBlock> coverageBlocks() {
+ return (Iterable)getEdges(DefaultCoverageBlock.class, Direction.IN, "covers");
+ }
+
+ private Iterable<Edge> coverEdges() {
return element().query().labels("covers").direction(Direction.IN).edges();
}
diff --git a/sonar-core/src/test/java/org/sonar/core/test/DefaultTestCaseTest.java b/sonar-core/src/test/java/org/sonar/core/test/DefaultTestCaseTest.java
index 8dc9289bc9d..f6026702ed1 100644
--- a/sonar-core/src/test/java/org/sonar/core/test/DefaultTestCaseTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/test/DefaultTestCaseTest.java
@@ -24,7 +24,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.component.mock.MockSourceFile;
-import org.sonar.api.test.Cover;
+import org.sonar.api.test.CoverageBlock;
import org.sonar.api.test.TestCase;
import org.sonar.api.test.exception.IllegalDurationException;
import org.sonar.core.component.ComponentVertex;
@@ -41,13 +41,13 @@ public class DefaultTestCaseTest {
public ExpectedException thrown = ExpectedException.none();
@Test
- public void no_coverage_data() {
+ public void no_coverage_blocks() {
BeanGraph beanGraph = BeanGraph.createInMemory();
DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class);
assertThat(testCase.doesCover()).isFalse();
assertThat(testCase.countCoveredLines()).isEqualTo(0);
- assertThat(testCase.covers()).isEmpty();
+ assertThat(testCase.coverageBlocks()).isEmpty();
}
@Test
@@ -55,13 +55,13 @@ public class DefaultTestCaseTest {
BeanGraph beanGraph = BeanGraph.createInMemory();
DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class);
DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class);
- testCase.setCover(testable, Arrays.asList(10, 11, 12));
+ testCase.setCoverageBlock(testable, Arrays.asList(10, 11, 12));
assertThat(testCase.doesCover()).isTrue();
assertThat(testCase.countCoveredLines()).isEqualTo(3);
- assertThat(testCase.covers()).hasSize(1);
+ assertThat(testCase.coverageBlocks()).hasSize(1);
- Cover cover = Iterables.<Cover>getFirst(testCase.covers(), null);
+ CoverageBlock cover = Iterables.getFirst(testCase.coverageBlocks(), null);
assertThat(cover.testCase()).isEqualTo(testCase);
assertThat(cover.testable()).isSameAs(testable);
assertThat(cover.lines()).containsExactly(10, 11, 12);
@@ -74,12 +74,12 @@ public class DefaultTestCaseTest {
DefaultTestable testable2 = beanGraph.createVertex(DefaultTestable.class);
DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class);
- testCase.setCover(testable1, Arrays.asList(10, 11, 12));
- testCase.setCover(testable2, Arrays.asList(12, 13, 14));
+ testCase.setCoverageBlock(testable1, Arrays.asList(10, 11, 12));
+ testCase.setCoverageBlock(testable2, Arrays.asList(12, 13, 14));
assertThat(testCase.doesCover()).isTrue();
assertThat(testCase.countCoveredLines()).isEqualTo(6);
- assertThat(testCase.covers()).hasSize(2);
+ assertThat(testCase.coverageBlocks()).hasSize(2);
}
@Test
@@ -94,11 +94,11 @@ public class DefaultTestCaseTest {
DefaultTestable testable2 = beanGraph.createAdjacentVertex(file2, DefaultTestable.class, "testable");
DefaultTestCase testCase = beanGraph.createVertex(DefaultTestCase.class);
- testCase.setCover(testable1, Arrays.asList(10, 11, 12));
+ testCase.setCoverageBlock(testable1, Arrays.asList(10, 11, 12));
- assertThat(testCase.coverOfTestable(testable1).testable()).isEqualTo(testable1);
- assertThat(testCase.coverOfTestable(testable1).testCase()).isEqualTo(testCase);
- assertThat(testCase.coverOfTestable(testable2)).isNull();
+ assertThat(testCase.coverageBlock(testable1).testable()).isEqualTo(testable1);
+ assertThat(testCase.coverageBlock(testable1).testCase()).isEqualTo(testCase);
+ assertThat(testCase.coverageBlock(testable2)).isNull();
}
@Test
@@ -110,6 +110,7 @@ public class DefaultTestCaseTest {
.setDurationInMs(1234L)
.setMessage("Error msg")
.setStackTrace("xxx")
+ .setType(TestCase.TYPE_UNIT)
.setStatus(TestCase.Status.ERROR);
assertThat(testCase.name()).isEqualTo("T1");
@@ -117,6 +118,7 @@ public class DefaultTestCaseTest {
assertThat(testCase.stackTrace()).isEqualTo("xxx");
assertThat(testCase.durationInMs()).isEqualTo(1234L);
assertThat(testCase.status()).isEqualTo(TestCase.Status.ERROR);
+ assertThat(testCase.type()).isEqualTo(TestCase.TYPE_UNIT);
}
@Test
diff --git a/sonar-core/src/test/java/org/sonar/core/test/DefaultTestPlanTest.java b/sonar-core/src/test/java/org/sonar/core/test/DefaultTestPlanTest.java
index 816bdb13d4c..e8369084aec 100644
--- a/sonar-core/src/test/java/org/sonar/core/test/DefaultTestPlanTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/test/DefaultTestPlanTest.java
@@ -82,15 +82,4 @@ public class DefaultTestPlanTest {
assertThat(plan.testCasesByName("T1")).hasSize(2);
}
-
- @Test
- public void should_set_type() {
- BeanGraph beanGraph = BeanGraph.createInMemory();
-
- DefaultTestPlan plan = beanGraph.createVertex(DefaultTestPlan.class);
- assertThat(plan.type()).isNull();
-
- plan.setType(TestPlan.TYPE_UNIT);
- assertThat(plan.type()).isEqualTo(TestPlan.TYPE_UNIT);
- }
}
diff --git a/sonar-core/src/test/java/org/sonar/core/test/DefaultTestableTest.java b/sonar-core/src/test/java/org/sonar/core/test/DefaultTestableTest.java
index cbf107b1617..c02626891ec 100644
--- a/sonar-core/src/test/java/org/sonar/core/test/DefaultTestableTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/test/DefaultTestableTest.java
@@ -46,9 +46,9 @@ public class DefaultTestableTest {
DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class);
DefaultTestCase testCase1 = beanGraph.createVertex(DefaultTestCase.class);
- testCase1.setCover(testable, Arrays.asList(10, 11, 12));
+ testCase1.setCoverageBlock(testable, Arrays.asList(10, 11, 12));
DefaultTestCase testCase2 = beanGraph.createVertex(DefaultTestCase.class);
- testCase2.setCover(testable, Arrays.asList(12, 48, 49));
+ testCase2.setCoverageBlock(testable, Arrays.asList(12, 48, 49));
assertThat(testable.testedLines()).containsOnly(10, 11, 12, 48, 49);
assertThat(testable.countTestCasesOfLine(2)).isEqualTo(0);
@@ -62,9 +62,9 @@ public class DefaultTestableTest {
DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class);
DefaultTestCase testCase1 = beanGraph.createVertex(DefaultTestCase.class);
- testCase1.setCover(testable, Arrays.asList(10, 11, 12));
+ testCase1.setCoverageBlock(testable, Arrays.asList(10, 11, 12));
DefaultTestCase testCase2 = beanGraph.createVertex(DefaultTestCase.class);
- testCase2.setCover(testable, Arrays.asList(12, 48, 49));
+ testCase2.setCoverageBlock(testable, Arrays.asList(12, 48, 49));
assertThat(testable.testCases()).containsOnly(testCase1, testCase2);
assertThat(testable.testCasesOfLine(5)).isEmpty();
@@ -82,9 +82,9 @@ public class DefaultTestableTest {
DefaultTestable testable = beanGraph.createVertex(DefaultTestable.class);
MutableTestCase testCase1 = Iterables.get(plan.testCases(), 0);
- testCase1.setCover(testable, Arrays.asList(10, 11, 12));
+ testCase1.setCoverageBlock(testable, Arrays.asList(10, 11, 12));
MutableTestCase testCase2 = Iterables.get(plan.testCases(), 1);
- testCase2.setCover(testable, Arrays.asList(12, 48, 49));
+ testCase2.setCoverageBlock(testable, Arrays.asList(12, 48, 49));
assertThat(testable.testCaseByName("T1")).isEqualTo(testCase1);
assertThat(testable.testCaseByName("T2")).isEqualTo(testCase2);
@@ -106,10 +106,10 @@ public class DefaultTestableTest {
plan.addTestCase("T1");
MutableTestCase testCase = Iterables.get(plan.testCases(), 0);
- testCase.setCover(testable1, Arrays.asList(10, 11, 12));
+ testCase.setCoverageBlock(testable1, Arrays.asList(10, 11, 12));
- assertThat(testable1.coverOfTestCase(testCase).testCase()).isEqualTo(testCase);
- assertThat(testable1.coverOfTestCase(testCase).testable()).isEqualTo(testable1);
- assertThat(testable2.coverOfTestCase(testCase)).isNull();
+ assertThat(testable1.coverageBlock(testCase).testCase()).isEqualTo(testCase);
+ assertThat(testable1.coverageBlock(testCase).testable()).isEqualTo(testable1);
+ assertThat(testable2.coverageBlock(testCase)).isNull();
}
}