aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-10-15 16:57:01 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-10-15 16:57:20 +0200
commit47a1dfc97e94d4032ffec55cd6cf79d644ffe92f (patch)
tree8c064a06e54509a66c10e6dcf02eb241d5e3e7d2
parented3b7766ae24600403886b2a1e197fe5f68e704a (diff)
downloadsonarqube-47a1dfc97e94d4032ffec55cd6cf79d644ffe92f.tar.gz
sonarqube-47a1dfc97e94d4032ffec55cd6cf79d644ffe92f.zip
Fix some quality flaws
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverage.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverageTest.java83
2 files changed, 86 insertions, 3 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverage.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverage.java
index f2f8834d87f..2199ef002e8 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverage.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverage.java
@@ -65,7 +65,7 @@ public class DefaultTestCaseCoverage extends DefaultStorable implements TestCase
}
@Override
- public TestCaseCoverage cover(InputFile mainFile) {
+ public DefaultTestCaseCoverage cover(InputFile mainFile) {
Preconditions.checkNotNull(mainFile, "InputFile cannot be null");
Preconditions.checkArgument(mainFile.type() == InputFile.Type.MAIN, "Should be a main file: " + mainFile);
this.mainFile = mainFile;
@@ -90,9 +90,9 @@ public class DefaultTestCaseCoverage extends DefaultStorable implements TestCase
}
@Override
- public TestCaseCoverage onLines(List<Integer> lines) {
+ public DefaultTestCaseCoverage onLines(List<Integer> lines) {
Preconditions.checkNotNull(lines, "Lines list cannot be null");
- Preconditions.checkArgument(lines.size() > 0, "No need to register test coverage if no line is covered");
+ Preconditions.checkArgument(!lines.isEmpty(), "No need to register test coverage if no line is covered");
this.lines = lines;
return this;
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverageTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverageTest.java
new file mode 100644
index 00000000000..2daa6e5d34e
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseCoverageTest.java
@@ -0,0 +1,83 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.api.batch.sensor.test.internal;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
+
+import java.util.Arrays;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultTestCaseCoverageTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private InputFile mainFile = new DefaultInputFile("foo", "src/Foo.php").setType(InputFile.Type.MAIN);
+ private InputFile testFile = new DefaultInputFile("foo", "test/FooTest.php").setType(InputFile.Type.TEST);
+
+ @Test
+ public void testCreation() throws Exception {
+ DefaultTestCaseCoverage testCaseCoverage = new DefaultTestCaseCoverage(null)
+ .testFile(testFile)
+ .testName("myTest")
+ .cover(mainFile)
+ .onLines(Arrays.asList(1, 2, 3));
+
+ assertThat(testCaseCoverage.testName()).isEqualTo("myTest");
+ assertThat(testCaseCoverage.testFile()).isEqualTo(testFile);
+ assertThat(testCaseCoverage.coveredFile()).isEqualTo(mainFile);
+ assertThat(testCaseCoverage.coveredLines()).containsExactly(1, 2, 3);
+ }
+
+ @Test
+ public void testEqualsHashCodeToString() {
+ DefaultTestCaseCoverage testCaseCoverage1 = new DefaultTestCaseCoverage(null)
+ .testFile(testFile)
+ .testName("myTest")
+ .cover(mainFile)
+ .onLines(Arrays.asList(1, 2, 3));
+ DefaultTestCaseCoverage testCaseCoverage1a = new DefaultTestCaseCoverage(null)
+ .testFile(testFile)
+ .testName("myTest")
+ .cover(mainFile)
+ .onLines(Arrays.asList(1, 2, 3));
+ DefaultTestCaseCoverage testCaseCoverage2 = new DefaultTestCaseCoverage(null)
+ .testFile(testFile)
+ .testName("myTest2")
+ .cover(mainFile)
+ .onLines(Arrays.asList(1, 3, 3));
+
+ assertThat(testCaseCoverage1).isEqualTo(testCaseCoverage1);
+ assertThat(testCaseCoverage1).isEqualTo(testCaseCoverage1a);
+ assertThat(testCaseCoverage1).isNotEqualTo(testCaseCoverage2);
+ assertThat(testCaseCoverage1).isNotEqualTo(null);
+ assertThat(testCaseCoverage1).isNotEqualTo("foo");
+
+ assertThat(testCaseCoverage1.toString())
+ .isEqualTo(
+ "DefaultTestCaseCoverage[testFile=[moduleKey=foo, relative=test/FooTest.php, abs=null],mainFile=[moduleKey=foo, relative=src/Foo.php, abs=null],name=myTest,lines=[1, 2, 3]]");
+ assertThat(testCaseCoverage1.hashCode()).isEqualTo(testCaseCoverage1a.hashCode());
+ }
+}