diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-10-13 15:08:30 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-10-14 14:26:46 +0200 |
commit | 7df58c2fc0dbab0d82c5587104a9ad1d2fa369ac (patch) | |
tree | 84ac39059ebee0173e4c06de501cfc2eba5b89d3 /plugins | |
parent | 6882924ef2d57618e9391c20b1a7a54546a7d9dd (diff) | |
download | sonarqube-7df58c2fc0dbab0d82c5587104a9ad1d2fa369ac.tar.gz sonarqube-7df58c2fc0dbab0d82c5587104a9ad1d2fa369ac.zip |
SONAR-5389 Refactor test coverage API
Diffstat (limited to 'plugins')
4 files changed, 34 insertions, 31 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CoveragePerTestSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CoveragePerTestSensor.java index 1e4c8b49d02..70fe9b78ff7 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CoveragePerTestSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/CoveragePerTestSensor.java @@ -30,7 +30,6 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; -import org.sonar.api.batch.sensor.test.TestCase; import org.sonar.xoo.Xoo; import java.io.File; @@ -81,13 +80,12 @@ public class CoveragePerTestSensor implements Sensor { while (lines.hasNext()) { coveredLines.add(Integer.parseInt(lines.next())); } - TestCase testCase = context.newTestCase() - .inTestFile(testFile) - .name(testCaseName); - if (testCase == null) { - throw new IllegalStateException("No test case with name " + testCaseName + " on file " + testFile); - } - context.saveCoveragePerTest(testCase, mainFile, coveredLines); + context.newTestCaseCoverage() + .testFile(testFile) + .testName(testCaseName) + .cover(mainFile) + .onLines(coveredLines) + .save(); } catch (Exception e) { throw new IllegalStateException("Error processing line " + lineNumber + " of file " + coverPerTest.getAbsolutePath(), e); } diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/TestCaseSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/TestCaseSensor.java index e9b9ff79dcf..12f231c17e8 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/TestCaseSensor.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/TestCaseSensor.java @@ -30,7 +30,7 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.sensor.Sensor; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorDescriptor; -import org.sonar.api.batch.sensor.test.TestCase; +import org.sonar.api.batch.sensor.test.TestCaseExecution; import org.sonar.xoo.Xoo; import java.io.File; @@ -77,11 +77,11 @@ public class TestCaseSensor implements Sensor { String message = split.next(); String stack = split.next(); long duration = Long.parseLong(split.next()); - context.newTestCase() + context.newTestCaseExecution() .inTestFile(testFile) .name(name) - .ofType(TestCase.Type.valueOf(type)) - .status(TestCase.Status.valueOf(status)) + .ofType(TestCaseExecution.Type.valueOf(type)) + .status(TestCaseExecution.Status.valueOf(status)) .message(StringUtils.trimToNull(message)) .stackTrace(StringUtils.trimToNull(stack)) .durationInMs(duration) diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java index 9c9ed6f2f46..e22b81eb5f8 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/CoveragePerTestSensorTest.java @@ -32,8 +32,8 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorStorage; import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; -import org.sonar.api.batch.sensor.test.TestCase; -import org.sonar.api.batch.sensor.test.internal.DefaultTestCase; +import org.sonar.api.batch.sensor.test.TestCaseCoverage; +import org.sonar.api.batch.sensor.test.internal.DefaultTestCaseCoverage; import java.io.File; import java.io.IOException; @@ -86,19 +86,24 @@ public class CoveragePerTestSensorTest { final SensorStorage sensorStorage = mock(SensorStorage.class); - when(context.newTestCase()).thenAnswer(new Answer<TestCase>() { + when(context.newTestCaseCoverage()).thenAnswer(new Answer<TestCaseCoverage>() { @Override - public TestCase answer(InvocationOnMock invocation) throws Throwable { - return new DefaultTestCase(sensorStorage); + public TestCaseCoverage answer(InvocationOnMock invocation) throws Throwable { + return new DefaultTestCaseCoverage(sensorStorage); } }); - TestCase test1 = new DefaultTestCase(null).inTestFile(testFile).name("test1"); - TestCase test2 = new DefaultTestCase(null).inTestFile(testFile).name("test2"); - sensor.execute(context); - verify(context).saveCoveragePerTest(test1, inputFile, Arrays.asList(1, 2, 3, 4)); - verify(context).saveCoveragePerTest(test2, inputFile, Arrays.asList(5, 6, 7)); + verify(sensorStorage).store(new DefaultTestCaseCoverage() + .testFile(testFile) + .testName("test1") + .cover(inputFile) + .onLines(Arrays.asList(1, 2, 3, 4))); + verify(sensorStorage).store(new DefaultTestCaseCoverage() + .testFile(testFile) + .testName("test2") + .cover(inputFile) + .onLines(Arrays.asList(5, 6, 7))); } } diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java index 4efb5c4d5ea..49b669707e0 100644 --- a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/TestCaseSensorTest.java @@ -32,8 +32,8 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.SensorContext; import org.sonar.api.batch.sensor.SensorStorage; import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; -import org.sonar.api.batch.sensor.test.TestCase; -import org.sonar.api.batch.sensor.test.internal.DefaultTestCase; +import org.sonar.api.batch.sensor.test.TestCaseExecution; +import org.sonar.api.batch.sensor.test.internal.DefaultTestCaseExecution; import java.io.File; import java.io.IOException; @@ -83,24 +83,24 @@ public class TestCaseSensorTest { final SensorStorage sensorStorage = mock(SensorStorage.class); - when(context.newTestCase()).thenAnswer(new Answer<TestCase>() { + when(context.newTestCaseExecution()).thenAnswer(new Answer<TestCaseExecution>() { @Override - public TestCase answer(InvocationOnMock invocation) throws Throwable { - return new DefaultTestCase(sensorStorage); + public TestCaseExecution answer(InvocationOnMock invocation) throws Throwable { + return new DefaultTestCaseExecution(sensorStorage); } }); sensor.execute(context); - verify(sensorStorage).store(new DefaultTestCase(null) + verify(sensorStorage).store(new DefaultTestCaseExecution(null) .inTestFile(testFile) .name("test1") .durationInMs(10)); - verify(sensorStorage).store(new DefaultTestCase(null) + verify(sensorStorage).store(new DefaultTestCaseExecution(null) .inTestFile(testFile) .name("test2") - .ofType(TestCase.Type.INTEGRATION) - .status(TestCase.Status.ERROR) + .ofType(TestCaseExecution.Type.INTEGRATION) + .status(TestCaseExecution.Status.ERROR) .message("message") .stackTrace("stack") .durationInMs(15)); |