aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-09-05 14:03:30 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-09-05 14:04:10 +0200
commite1c3a706319c397b436a28b7921b695baf712063 (patch)
tree342c942f72b71c6f2843e71a893252f383342772 /sonar-plugin-api
parenta967da0f1192287036132a5876be693485e94ae6 (diff)
downloadsonarqube-e1c3a706319c397b436a28b7921b695baf712063.tar.gz
sonarqube-e1c3a706319c397b436a28b7921b695baf712063.zip
SONAR-5389 New test API for batch 2.0
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java34
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java22
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rules.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java38
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/TestCase.java69
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/TestCaseBuilder.java61
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCase.java137
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseBuilder.java86
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/package-info.java21
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/package-info.java21
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestPlan.java5
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestable.java5
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/test/TestPlan.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/test/Testable.java5
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java14
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputDirTest.java21
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java13
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFileTest.java13
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java22
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationBuilderTest.java8
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseBuilderTest.java71
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseTest.java63
28 files changed, 672 insertions, 92 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java
index 26fc37a0030..71026d52d33 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputDir.java
@@ -22,8 +22,6 @@ package org.sonar.api.batch.fs.internal;
import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.utils.PathUtils;
-import javax.annotation.CheckForNull;
-
import java.io.File;
import java.io.Serializable;
@@ -33,10 +31,11 @@ import java.io.Serializable;
public class DefaultInputDir implements InputDir, Serializable {
private final String relativePath;
+ private final String moduleKey;
private String absolutePath;
- private String key;
- public DefaultInputDir(String relativePath) {
+ public DefaultInputDir(String moduleKey, String relativePath) {
+ this.moduleKey = moduleKey;
this.relativePath = PathUtils.sanitize(relativePath);
}
@@ -45,12 +44,7 @@ public class DefaultInputDir implements InputDir, Serializable {
return relativePath;
}
- /**
- * Marked as nullable just for the unit tests that do not call {@link #setFile(java.io.File)}
- * previously.
- */
@Override
- @CheckForNull
public String absolutePath() {
return absolutePath;
}
@@ -63,13 +57,12 @@ public class DefaultInputDir implements InputDir, Serializable {
return new File(absolutePath);
}
- /**
- * Component key. It's marked as nullable just for the unit tests that
- * do not previously call {@link #setKey(String)}.
- */
- @CheckForNull
+ public String moduleKey() {
+ return moduleKey;
+ }
+
public String key() {
- return key;
+ return new StringBuilder().append(moduleKey).append(":").append(relativePath).toString();
}
public DefaultInputDir setAbsolutePath(String s) {
@@ -82,11 +75,6 @@ public class DefaultInputDir implements InputDir, Serializable {
return this;
}
- public DefaultInputDir setKey(String s) {
- this.key = s;
- return this;
- }
-
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -97,16 +85,16 @@ public class DefaultInputDir implements InputDir, Serializable {
}
DefaultInputDir that = (DefaultInputDir) o;
- return relativePath.equals(that.relativePath);
+ return moduleKey.equals(that.moduleKey) && relativePath.equals(that.relativePath);
}
@Override
public int hashCode() {
- return relativePath.hashCode();
+ return moduleKey.hashCode() + relativePath.hashCode() * 13;
}
@Override
public String toString() {
- return "[relative=" + relativePath + ", abs=" + absolutePath + "]";
+ return "[moduleKey=" + moduleKey + ", relative=" + relativePath + ", abs=" + absolutePath + "]";
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
index 34611ea5d98..6816e2f1296 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DefaultInputFile.java
@@ -31,15 +31,16 @@ import java.io.Serializable;
public class DefaultInputFile implements InputFile, Serializable {
private final String relativePath;
+ private final String moduleKey;
private String absolutePath;
private String language;
private Type type = Type.MAIN;
private Status status;
private String hash;
private int lines;
- private String key;
- public DefaultInputFile(String relativePath) {
+ public DefaultInputFile(String moduleKey, String relativePath) {
+ this.moduleKey = moduleKey;
this.relativePath = PathUtils.sanitize(relativePath);
}
@@ -95,7 +96,11 @@ public class DefaultInputFile implements InputFile, Serializable {
* Component key.
*/
public String key() {
- return key;
+ return new StringBuilder().append(moduleKey).append(":").append(relativePath).toString();
+ }
+
+ public String moduleKey() {
+ return moduleKey;
}
public DefaultInputFile setAbsolutePath(String s) {
@@ -133,11 +138,6 @@ public class DefaultInputFile implements InputFile, Serializable {
return this;
}
- public DefaultInputFile setKey(String s) {
- this.key = s;
- return this;
- }
-
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -148,16 +148,16 @@ public class DefaultInputFile implements InputFile, Serializable {
}
DefaultInputFile that = (DefaultInputFile) o;
- return relativePath.equals(that.relativePath);
+ return moduleKey.equals(that.moduleKey) && relativePath.equals(that.relativePath);
}
@Override
public int hashCode() {
- return relativePath.hashCode();
+ return moduleKey.hashCode() + relativePath.hashCode() * 13;
}
@Override
public String toString() {
- return "[relative=" + relativePath + ", abs=" + absolutePath + "]";
+ return "[moduleKey=" + moduleKey + ", relative=" + relativePath + ", abs=" + absolutePath + "]";
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java
index 7c82aa501d0..a599b6ff656 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java
@@ -37,8 +37,8 @@ public class DeprecatedDefaultInputFile extends DefaultInputFile implements org.
private String sourceDirAbsolutePath;
private String pathRelativeToSourceDir;
- public DeprecatedDefaultInputFile(String relativePath) {
- super(relativePath);
+ public DeprecatedDefaultInputFile(String moduleKey, String relativePath) {
+ super(moduleKey, relativePath);
}
/**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rules.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rules.java
index 22521ce0115..22d915c20fc 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rules.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rules.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.batch.rule;
+import org.sonar.api.BatchComponent;
import org.sonar.api.rule.RuleKey;
import javax.annotation.CheckForNull;
@@ -28,7 +29,7 @@ import java.util.Collection;
/**
* @since 4.2
*/
-public interface Rules {
+public interface Rules extends BatchComponent {
@CheckForNull
Rule find(RuleKey key);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
index 7465126c3e1..f2102986b38 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
@@ -33,6 +33,8 @@ import org.sonar.api.batch.sensor.issue.IssueBuilder;
import org.sonar.api.batch.sensor.measure.Measure;
import org.sonar.api.batch.sensor.measure.MeasureBuilder;
import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder;
+import org.sonar.api.batch.sensor.test.TestCase;
+import org.sonar.api.batch.sensor.test.TestCaseBuilder;
import org.sonar.api.config.Settings;
import javax.annotation.CheckForNull;
@@ -149,7 +151,43 @@ public interface SensorContext {
/**
* Register all duplications of an {@link InputFile}. Use {@link #duplicationBuilder(InputFile)} to create
* list of duplications.
+ * @since 4.5
*/
void saveDuplications(InputFile inputFile, List<DuplicationGroup> duplications);
+ // ------------ TESTS ------------
+
+ /**
+ * Create a new test case for the given test file.
+ * @param testFile An {@link InputFile} with type {@link InputFile.Type#TEST}
+ * @param testCaseName name of the test case
+ * @since 5.0
+ */
+ TestCaseBuilder testCaseBuilder(InputFile testFile, String testCaseName);
+
+ /**
+ * Add a new test case.
+ * Use {@link #testCaseBuilder(InputFile, String)} to create a new {@link TestCase}
+ * @throws IllegalArgumentException if a test case with same name was already added on the same file.
+ * @since 5.0
+ */
+ void addTestCase(TestCase testCase);
+
+ /**
+ * Get a {@link TestCase} that has been previously added to the context with {@link #addTestCase(TestCase)}.
+ * @since 5.0
+ */
+ @CheckForNull
+ TestCase getTestCase(InputFile testFile, String testCaseName);
+
+ /**
+ * Register coverage of a given test case on another main file. TestCase should have been registered using {@link #testPlanBuilder(InputFile)}
+ * @param testFile test file containing the test case
+ * @param testCaseName name of the test case
+ * @param coveredFile main file that is covered
+ * @param coveredLines list of covered lines
+ * @since 5.0
+ */
+ void saveCoveragePerTest(TestCase testCase, InputFile coveredFile, List<Integer> coveredLines);
+
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/TestCase.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/TestCase.java
new file mode 100644
index 00000000000..a4e95e62e40
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/TestCase.java
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+import javax.annotation.Nullable;
+
+/**
+ * Represents a single test in a test plan.
+ * @since 5.0
+ *
+ */
+public interface TestCase {
+ enum Status {
+ OK, FAILURE, ERROR, SKIPPED;
+
+ public static Status of(@Nullable String s) {
+ return s == null ? null : valueOf(s.toUpperCase());
+ }
+ }
+
+ enum Type {
+ UNIT, INTEGRATION;
+ }
+
+ /**
+ * Duration in milliseconds
+ */
+ Long durationInMs();
+
+ Type type();
+
+ /**
+ * Status of execution of the test.
+ */
+ Status status();
+
+ /**
+ * Name of this test case.
+ */
+ String name();
+
+ /**
+ * Message (usually in case of {@link Status#ERROR} or {@link Status#FAILURE}).
+ */
+ String message();
+
+ /**
+ * Stacktrace (usually in case of {@link Status#ERROR}).
+ */
+ String stackTrace();
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/TestCaseBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/TestCaseBuilder.java
new file mode 100644
index 00000000000..9667ff794aa
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/TestCaseBuilder.java
@@ -0,0 +1,61 @@
+/*
+ * 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;
+
+import org.sonar.api.batch.sensor.test.TestCase.Status;
+import org.sonar.api.batch.sensor.test.TestCase.Type;
+
+/**
+ * Builder to create a new TestCase on a test file.
+ * @since 5.0
+ */
+public interface TestCaseBuilder {
+
+ /**
+ * Duration in milliseconds
+ */
+ TestCaseBuilder durationInMs(long duration);
+
+ /**
+ * Status of execution of the test.
+ */
+ TestCaseBuilder status(Status status);
+
+ /**
+ * Message (usually in case of {@link Status#ERROR} or {@link Status#FAILURE}).
+ */
+ TestCaseBuilder message(String message);
+
+ /**
+ * Type of test.
+ */
+ TestCaseBuilder type(Type type);
+
+ /**
+ * Stacktrace (usually in case of {@link Status#ERROR}).
+ */
+ TestCaseBuilder stackTrace(String stackTrace);
+
+ /**
+ * Call this method only once when your are done with defining the test case.
+ */
+ TestCase build();
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCase.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCase.java
new file mode 100644
index 00000000000..a6616abcb8f
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCase.java
@@ -0,0 +1,137 @@
+/*
+ * 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.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.builder.ToStringStyle;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.sensor.test.TestCase;
+
+import javax.annotation.CheckForNull;
+
+public class DefaultTestCase implements TestCase {
+
+ private final InputFile testFile;
+ private final String name;
+ private final Long duration;
+ private final Status status;
+ private final String message;
+ private final Type type;
+ private final String stackTrace;
+
+ public DefaultTestCase(InputFile testFile, String name, Long duration, Status status, String message, Type type, String stackTrace) {
+ this.testFile = testFile;
+ this.name = name;
+ this.duration = duration;
+ this.status = status;
+ this.message = message;
+ this.type = type;
+ this.stackTrace = stackTrace;
+ }
+
+ public InputFile testFile() {
+ return testFile;
+ }
+
+ @CheckForNull
+ @Override
+ public Long durationInMs() {
+ return duration;
+ }
+
+ @Override
+ public Type type() {
+ return type;
+ }
+
+ @Override
+ public Status status() {
+ return status;
+ }
+
+ @Override
+ public String name() {
+ return name;
+ }
+
+ @CheckForNull
+ @Override
+ public String message() {
+ return message;
+ }
+
+ @CheckForNull
+ @Override
+ public String stackTrace() {
+ return stackTrace;
+ }
+
+ // Just for unit tests
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (obj == this) {
+ return true;
+ }
+ if (obj.getClass() != getClass()) {
+ return false;
+ }
+ DefaultTestCase rhs = (DefaultTestCase) obj;
+ return new EqualsBuilder()
+ .append(testFile, rhs.testFile)
+ .append(name, rhs.name)
+ .append(duration, rhs.duration)
+ .append(status, rhs.status)
+ .append(message, rhs.message)
+ .append(type, rhs.type)
+ .append(stackTrace, rhs.stackTrace)
+ .isEquals();
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashCodeBuilder(13, 43)
+ .append(testFile)
+ .append(name)
+ .append(duration)
+ .append(status)
+ .append(message)
+ .append(type)
+ .append(stackTrace)
+ .toHashCode();
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+ .append("file", testFile)
+ .append("name", name)
+ .append("duration", duration)
+ .append("status", status)
+ .append("message", message)
+ .append("type", type)
+ .append("stackTrace", stackTrace)
+ .toString();
+ }
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseBuilder.java
new file mode 100644
index 00000000000..0b6e34ee07b
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseBuilder.java
@@ -0,0 +1,86 @@
+/*
+ * 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 com.google.common.base.Preconditions;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.sensor.test.TestCase;
+import org.sonar.api.batch.sensor.test.TestCase.Status;
+import org.sonar.api.batch.sensor.test.TestCase.Type;
+import org.sonar.api.batch.sensor.test.TestCaseBuilder;
+
+import javax.annotation.Nullable;
+
+public class DefaultTestCaseBuilder implements TestCaseBuilder {
+
+ private final InputFile testFile;
+ private final String name;
+ private Long duration;
+ private TestCase.Status status = Status.OK;
+ private String message;
+ private TestCase.Type type = Type.UNIT;
+ private String stackTrace;
+
+ public DefaultTestCaseBuilder(InputFile testFile, String name) {
+ Preconditions.checkArgument(testFile.type() == InputFile.Type.TEST, "Should be a test file: " + testFile);
+ Preconditions.checkArgument(StringUtils.isNotBlank(name), "Test name should not be blank");
+ this.testFile = testFile;
+ this.name = name;
+ }
+
+ @Override
+ public TestCaseBuilder durationInMs(long duration) {
+ Preconditions.checkArgument(duration >= 0, "Test duration must be positive (got: " + duration + ")");
+ this.duration = duration;
+ return this;
+ }
+
+ @Override
+ public TestCaseBuilder status(TestCase.Status status) {
+ Preconditions.checkNotNull(status);
+ this.status = status;
+ return this;
+ }
+
+ @Override
+ public TestCaseBuilder message(@Nullable String message) {
+ this.message = message;
+ return this;
+ }
+
+ @Override
+ public TestCaseBuilder type(TestCase.Type type) {
+ this.type = type;
+ return this;
+ }
+
+ @Override
+ public TestCaseBuilder stackTrace(@Nullable String stackTrace) {
+ this.stackTrace = stackTrace;
+ return this;
+ }
+
+ @Override
+ public TestCase build() {
+ return new DefaultTestCase(this.testFile, this.name, this.duration, this.status, this.message, this.type, this.stackTrace);
+ }
+
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/package-info.java
new file mode 100644
index 00000000000..02a89291200
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+@javax.annotation.ParametersAreNonnullByDefault
+package org.sonar.api.batch.sensor.test.internal; \ No newline at end of file
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/package-info.java
new file mode 100644
index 00000000000..c0e60bb0977
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+@javax.annotation.ParametersAreNonnullByDefault
+package org.sonar.api.batch.sensor.test; \ No newline at end of file
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java
index a656a76bbb1..dfecc85f0a4 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java
@@ -19,10 +19,16 @@
*/
package org.sonar.api.test;
+import org.sonar.api.batch.sensor.SensorContext;
+
import javax.annotation.Nullable;
import java.util.List;
+/**
+ * @deprecated since 5.0 use {@link SensorContext#testPlanBuilder(org.sonar.api.batch.fs.InputFile)}
+ */
+@Deprecated
public interface MutableTestCase extends TestCase {
MutableTestCase setStatus(@Nullable Status s);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestPlan.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestPlan.java
index 22bccb8d9fb..7a1f9c8cd24 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestPlan.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestPlan.java
@@ -19,8 +19,13 @@
*/
package org.sonar.api.test;
+import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.component.MutablePerspective;
+/**
+ * @deprecated since 5.0 use {@link SensorContext#testPlanBuilder(org.sonar.api.batch.fs.InputFile)}
+ */
+@Deprecated
public interface MutableTestPlan extends TestPlan<MutableTestCase>, MutablePerspective {
MutableTestCase addTestCase(String name);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestable.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestable.java
index be9c30892b1..2d91cb885e9 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestable.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestable.java
@@ -19,8 +19,13 @@
*/
package org.sonar.api.test;
+import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.component.MutablePerspective;
+/**
+ * @deprecated since 5.0 use {@link SensorContext#testPlanBuilder(org.sonar.api.batch.fs.InputFile)}
+ */
+@Deprecated
public interface MutableTestable extends Testable, MutablePerspective {
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java
index abe7025a02a..70dccba3976 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java
@@ -21,6 +21,10 @@ package org.sonar.api.test;
import javax.annotation.Nullable;
+/**
+ * @deprecated since 5.0 see {@link org.sonar.api.batch.sensor.test.TestCase}
+ */
+@Deprecated
public interface TestCase {
enum Status {
OK, FAILURE, ERROR, SKIPPED;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/TestPlan.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/TestPlan.java
index dbb864426f5..affb39bfe5e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/test/TestPlan.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/TestPlan.java
@@ -21,6 +21,10 @@ package org.sonar.api.test;
import org.sonar.api.component.Perspective;
+/**
+ * @deprecated since 5.0
+ */
+@Deprecated
public interface TestPlan<T extends TestCase> extends Perspective {
Iterable<T> testCases();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/test/Testable.java b/sonar-plugin-api/src/main/java/org/sonar/api/test/Testable.java
index 7091b6bee86..1857c49642b 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/test/Testable.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/test/Testable.java
@@ -19,12 +19,17 @@
*/
package org.sonar.api.test;
+import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.component.Perspective;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
+/**
+ * @deprecated since 5.0 use {@link SensorContext#testPlanBuilder(org.sonar.api.batch.fs.InputFile)}
+ */
+@Deprecated
public interface Testable extends Perspective {
List<TestCase> testCases();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java
index 95888fecfe9..3539bea9566 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java
@@ -45,7 +45,7 @@ public class DefaultFilePredicatesTest {
@Before
public void before() throws IOException {
- javaFile = new DefaultInputFile("src/main/java/struts/Action.java")
+ javaFile = new DefaultInputFile("foo", "src/main/java/struts/Action.java")
.setFile(temp.newFile("Action.java"))
.setLanguage("java")
.setStatus(InputFile.Status.ADDED);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java
index 678fdc5687b..aacc7abfb9b 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFileSystemTest.java
@@ -80,12 +80,12 @@ public class DefaultFileSystemTest {
assertThat(fs.inputFiles(fs.predicates().all())).isEmpty();
- fs.add(new DefaultInputFile("src/Foo.php").setLanguage("php").setFile(temp.newFile()));
- fs.add(new DefaultInputFile("src/Bar.java").setLanguage("java").setFile(temp.newFile()));
- fs.add(new DefaultInputFile("src/Baz.java").setLanguage("java").setFile(temp.newFile()));
+ fs.add(new DefaultInputFile("foo", "src/Foo.php").setLanguage("php").setFile(temp.newFile()));
+ fs.add(new DefaultInputFile("foo", "src/Bar.java").setLanguage("java").setFile(temp.newFile()));
+ fs.add(new DefaultInputFile("foo", "src/Baz.java").setLanguage("java").setFile(temp.newFile()));
// no language
- fs.add(new DefaultInputFile("src/readme.txt").setFile(temp.newFile()));
+ fs.add(new DefaultInputFile("foo", "src/readme.txt").setFile(temp.newFile()));
assertThat(fs.inputFile(fs.predicates().hasRelativePath("src/Bar.java"))).isNotNull();
assertThat(fs.inputFile(fs.predicates().hasRelativePath("does/not/exist"))).isNull();
@@ -119,8 +119,8 @@ public class DefaultFileSystemTest {
thrown.expectMessage("expected one element");
DefaultFileSystem fs = new DefaultFileSystem();
- fs.add(new DefaultInputFile("src/Bar.java").setLanguage("java").setFile(temp.newFile()));
- fs.add(new DefaultInputFile("src/Baz.java").setLanguage("java").setFile(temp.newFile()));
+ fs.add(new DefaultInputFile("foo", "src/Bar.java").setLanguage("java").setFile(temp.newFile()));
+ fs.add(new DefaultInputFile("foo", "src/Baz.java").setLanguage("java").setFile(temp.newFile()));
fs.inputFile(fs.predicates().all());
}
@@ -128,7 +128,7 @@ public class DefaultFileSystemTest {
@Test
public void input_file_supports_non_indexed_predicates() throws Exception {
DefaultFileSystem fs = new DefaultFileSystem();
- fs.add(new DefaultInputFile("src/Bar.java").setLanguage("java").setFile(temp.newFile()));
+ fs.add(new DefaultInputFile("foo", "src/Bar.java").setLanguage("java").setFile(temp.newFile()));
// it would fail if more than one java file
assertThat(fs.inputFile(fs.predicates().hasLanguage("java"))).isNotNull();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputDirTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputDirTest.java
index ca11cd02bcc..49157e92a44 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputDirTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputDirTest.java
@@ -35,11 +35,10 @@ public class DefaultInputDirTest {
@Test
public void test() throws Exception {
File dir = temp.newFolder("src");
- DefaultInputDir inputDir = new DefaultInputDir("src")
- .setFile(dir)
- .setKey("ABCDE");
+ DefaultInputDir inputDir = new DefaultInputDir("ABCDE", "src")
+ .setFile(dir);
- assertThat(inputDir.key()).isEqualTo("ABCDE");
+ assertThat(inputDir.key()).isEqualTo("ABCDE:src");
assertThat(inputDir.file().getAbsolutePath()).isEqualTo(dir.getAbsolutePath());
assertThat(inputDir.relativePath()).isEqualTo("src");
assertThat(new File(inputDir.relativePath())).isRelative();
@@ -50,22 +49,20 @@ public class DefaultInputDirTest {
@Test
public void testEqualsAndHashCode() throws Exception {
File dir1 = temp.newFolder("src");
- DefaultInputDir inputDir1 = new DefaultInputDir("src")
- .setFile(dir1)
- .setKey("ABCDE");
+ DefaultInputDir inputDir1 = new DefaultInputDir("ABCDE", "src")
+ .setFile(dir1);
File dir2 = temp.newFolder("src2");
- DefaultInputDir inputDir2 = new DefaultInputDir("src")
- .setFile(dir2)
- .setKey("ABCDE");
+ DefaultInputDir inputDir2 = new DefaultInputDir("ABCDE", "src")
+ .setFile(dir2);
assertThat(inputDir1.equals(inputDir1)).isTrue();
assertThat(inputDir1.equals(inputDir2)).isTrue();
assertThat(inputDir1.equals("foo")).isFalse();
- assertThat(inputDir1.hashCode()).isEqualTo(114148);
+ assertThat(inputDir1.hashCode()).isEqualTo(63545559);
- assertThat(inputDir1.toString()).contains("[relative=src, abs=");
+ assertThat(inputDir1.toString()).contains("[moduleKey=ABCDE, relative=src, abs=");
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java
index b96821ffd69..e96f29e82e0 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputFileTest.java
@@ -35,9 +35,8 @@ public class DefaultInputFileTest {
@Test
public void test() throws Exception {
- DefaultInputFile inputFile = new DefaultInputFile("src/Foo.php")
+ DefaultInputFile inputFile = new DefaultInputFile("ABCDE", "src/Foo.php")
.setFile(temp.newFile("Foo.php"))
- .setKey("ABCDE")
.setHash("1234")
.setLines(42)
.setLanguage("php")
@@ -57,9 +56,9 @@ public class DefaultInputFileTest {
@Test
public void test_equals_and_hashcode() throws Exception {
- DefaultInputFile f1 = new DefaultInputFile("src/Foo.php");
- DefaultInputFile f1a = new DefaultInputFile("src/Foo.php");
- DefaultInputFile f2 = new DefaultInputFile("src/Bar.php");
+ DefaultInputFile f1 = new DefaultInputFile("ABCDE", "src/Foo.php");
+ DefaultInputFile f1a = new DefaultInputFile("ABCDE", "src/Foo.php");
+ DefaultInputFile f2 = new DefaultInputFile("ABCDE", "src/Bar.php");
assertThat(f1).isEqualTo(f1);
assertThat(f1).isEqualTo(f1a);
@@ -73,7 +72,7 @@ public class DefaultInputFileTest {
@Test
public void test_toString() throws Exception {
- DefaultInputFile file = new DefaultInputFile("src/Foo.php").setAbsolutePath("/path/to/src/Foo.php");
- assertThat(file.toString()).isEqualTo("[relative=src/Foo.php, abs=/path/to/src/Foo.php]");
+ DefaultInputFile file = new DefaultInputFile("ABCDE", "src/Foo.php").setAbsolutePath("/path/to/src/Foo.php");
+ assertThat(file.toString()).isEqualTo("[moduleKey=ABCDE, relative=src/Foo.php, abs=/path/to/src/Foo.php]");
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFileTest.java
index 321efa8b681..b1f07a138b1 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFileTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFileTest.java
@@ -36,11 +36,10 @@ public class DeprecatedDefaultInputFileTest {
@Test
public void test() throws Exception {
- DeprecatedDefaultInputFile inputFile = (DeprecatedDefaultInputFile) new DeprecatedDefaultInputFile("src/Foo.php")
+ DeprecatedDefaultInputFile inputFile = (DeprecatedDefaultInputFile) new DeprecatedDefaultInputFile("ABCDE", "src/Foo.php")
.setPathRelativeToSourceDir("Foo.php")
.setDeprecatedKey("deprecated")
.setFile(temp.newFile("Foo.php"))
- .setKey("ABCDE")
.setHash("1234")
.setLines(42)
.setLanguage("php")
@@ -62,9 +61,9 @@ public class DeprecatedDefaultInputFileTest {
@Test
public void test_equals_and_hashcode() throws Exception {
- DefaultInputFile f1 = new DefaultInputFile("src/Foo.php");
- DefaultInputFile f1a = new DefaultInputFile("src/Foo.php");
- DefaultInputFile f2 = new DefaultInputFile("src/Bar.php");
+ DefaultInputFile f1 = new DefaultInputFile("ABCDE", "src/Foo.php");
+ DefaultInputFile f1a = new DefaultInputFile("ABCDE", "src/Foo.php");
+ DefaultInputFile f2 = new DefaultInputFile("ABCDE", "src/Bar.php");
assertThat(f1).isEqualTo(f1);
assertThat(f1).isEqualTo(f1a);
@@ -78,7 +77,7 @@ public class DeprecatedDefaultInputFileTest {
@Test
public void test_toString() throws Exception {
- DefaultInputFile file = new DefaultInputFile("src/Foo.php").setAbsolutePath("/path/to/src/Foo.php");
- assertThat(file.toString()).isEqualTo("[relative=src/Foo.php, abs=/path/to/src/Foo.php]");
+ DefaultInputFile file = new DefaultInputFile("ABCDE", "src/Foo.php").setAbsolutePath("/path/to/src/Foo.php");
+ assertThat(file.toString()).isEqualTo("[moduleKey=ABCDE, relative=src/Foo.php, abs=/path/to/src/Foo.php]");
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java
index 01d6dabd0fb..87f6aa3b245 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/PathPatternTest.java
@@ -38,16 +38,16 @@ public class PathPatternTest {
assertThat(pattern.toString()).isEqualTo("**/*Foo.java");
File file = new File(temp.newFolder(), "src/main/java/org/MyFoo.java");
- InputFile inputFile = new DefaultInputFile("src/main/java/org/MyFoo.java").setFile(file);
+ InputFile inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.java").setFile(file);
assertThat(pattern.match(inputFile)).isTrue();
// case sensitive by default
file = new File(temp.newFolder(), "src/main/java/org/MyFoo.JAVA");
- inputFile = new DefaultInputFile("src/main/java/org/MyFoo.JAVA").setFile(file);
+ inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.JAVA").setFile(file);
assertThat(pattern.match(inputFile)).isFalse();
file = new File(temp.newFolder(), "src/main/java/org/Other.java");
- inputFile = new DefaultInputFile("src/main/java/org/Other.java").setFile(file);
+ inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/Other.java").setFile(file);
assertThat(pattern.match(inputFile)).isFalse();
}
@@ -56,11 +56,11 @@ public class PathPatternTest {
PathPattern pattern = PathPattern.create("**/*Foo.java");
File file = new File(temp.newFolder(), "src/main/java/org/MyFoo.JAVA");
- InputFile inputFile = new DefaultInputFile("src/main/java/org/MyFoo.JAVA").setFile(file);
+ InputFile inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.JAVA").setFile(file);
assertThat(pattern.match(inputFile, false)).isTrue();
file = new File(temp.newFolder(), "src/main/java/org/Other.java");
- inputFile = new DefaultInputFile("src/main/java/org/Other.java").setFile(file);
+ inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/Other.java").setFile(file);
assertThat(pattern.match(inputFile, false)).isFalse();
}
@@ -70,16 +70,16 @@ public class PathPatternTest {
assertThat(pattern.toString()).isEqualTo("file:**/src/main/**Foo.java");
File file = new File(temp.newFolder(), "src/main/java/org/MyFoo.java");
- InputFile inputFile = new DefaultInputFile("src/main/java/org/MyFoo.java").setFile(file);
+ InputFile inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.java").setFile(file);
assertThat(pattern.match(inputFile)).isTrue();
// case sensitive by default
file = new File(temp.newFolder(), "src/main/java/org/MyFoo.JAVA");
- inputFile = new DefaultInputFile("src/main/java/org/MyFoo.JAVA").setFile(file);
+ inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.JAVA").setFile(file);
assertThat(pattern.match(inputFile)).isFalse();
file = new File(temp.newFolder(), "src/main/java/org/Other.java");
- inputFile = new DefaultInputFile("src/main/java/org/Other.java").setFile(file);
+ inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/Other.java").setFile(file);
assertThat(pattern.match(inputFile)).isFalse();
}
@@ -89,17 +89,17 @@ public class PathPatternTest {
assertThat(pattern.toString()).isEqualTo("file:**/src/main/**Foo.java");
File file = new File(temp.newFolder(), "src/main/java/org/MyFoo.JAVA");
- InputFile inputFile = new DefaultInputFile("src/main/java/org/MyFoo.JAVA").setFile(file);
+ InputFile inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/MyFoo.JAVA").setFile(file);
assertThat(pattern.match(inputFile, false)).isTrue();
file = new File(temp.newFolder(), "src/main/java/org/Other.JAVA");
- inputFile = new DefaultInputFile("src/main/java/org/Other.JAVA").setFile(file);
+ inputFile = new DefaultInputFile("ABCDE", "src/main/java/org/Other.JAVA").setFile(file);
assertThat(pattern.match(inputFile, false)).isFalse();
}
@Test
public void create_array_of_patterns() throws Exception {
- PathPattern[] patterns = PathPattern.create(new String[]{
+ PathPattern[] patterns = PathPattern.create(new String[] {
"**/src/main/**Foo.java",
"file:**/src/main/**Bar.java"
});
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationBuilderTest.java
index 17a813dbf35..d586e6855eb 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationBuilderTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/duplication/internal/DefaultDuplicationBuilderTest.java
@@ -32,13 +32,13 @@ public class DefaultDuplicationBuilderTest {
@Test
public void test() {
- DefaultDuplicationBuilder builder = new DefaultDuplicationBuilder(new DefaultInputFile("foo.php").setKey("foo:foo.php"));
+ DefaultDuplicationBuilder builder = new DefaultDuplicationBuilder(new DefaultInputFile("foo", "foo.php"));
List<DuplicationGroup> duplicationGroup = builder.originBlock(1, 11)
- .isDuplicatedBy(new DefaultInputFile("foo.php"), 40, 50)
- .isDuplicatedBy(new DefaultInputFile("foo2.php"), 1, 10)
+ .isDuplicatedBy(new DefaultInputFile("foo", "foo.php"), 40, 50)
+ .isDuplicatedBy(new DefaultInputFile("foo", "foo2.php"), 1, 10)
.originBlock(20, 30)
- .isDuplicatedBy(new DefaultInputFile("foo3.php"), 30, 40)
+ .isDuplicatedBy(new DefaultInputFile("foo", "foo3.php"), 30, 40)
.build();
assertThat(duplicationGroup).hasSize(2);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java
index 7e98d6e3591..6c0d12da82c 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java
@@ -36,14 +36,14 @@ public class DefaultIssueTest {
@Test
public void build_file_issue() {
Issue issue = new DefaultIssueBuilder()
- .onFile(new DefaultInputFile("src/Foo.php"))
+ .onFile(new DefaultInputFile("foo", "src/Foo.php"))
.ruleKey(RuleKey.of("repo", "rule"))
.atLine(1)
.effortToFix(10.0)
.message("Wrong way!")
.build();
- assertThat(issue.inputPath()).isEqualTo(new DefaultInputFile("src/Foo.php"));
+ assertThat(issue.inputPath()).isEqualTo(new DefaultInputFile("foo", "src/Foo.php"));
assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
assertThat(issue.line()).isEqualTo(1);
assertThat(issue.effortToFix()).isEqualTo(10.0);
@@ -72,7 +72,7 @@ public class DefaultIssueTest {
thrown.expectMessage("onProject already called");
new DefaultIssueBuilder()
.onProject()
- .onFile(new DefaultInputFile("src/Foo.php"))
+ .onFile(new DefaultInputFile("foo", "src/Foo.php"))
.ruleKey(RuleKey.of("repo", "rule"))
.atLine(1)
.effortToFix(10.0)
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java
index b894ffec092..8d3faf23810 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/measure/internal/DefaultMeasureTest.java
@@ -37,11 +37,11 @@ public class DefaultMeasureTest {
public void build_file_measure() {
Measure<Integer> issue = new DefaultMeasureBuilder<Integer>()
.forMetric(CoreMetrics.LINES)
- .onFile(new DefaultInputFile("src/Foo.php"))
+ .onFile(new DefaultInputFile("foo", "src/Foo.php"))
.withValue(3)
.build();
- assertThat(issue.inputFile()).isEqualTo(new DefaultInputFile("src/Foo.php"));
+ assertThat(issue.inputFile()).isEqualTo(new DefaultInputFile("foo", "src/Foo.php"));
assertThat(issue.metric()).isEqualTo(CoreMetrics.LINES);
assertThat(issue.value()).isEqualTo(3);
}
@@ -65,7 +65,7 @@ public class DefaultMeasureTest {
thrown.expectMessage("onProject already called");
new DefaultMeasureBuilder<Integer>()
.onProject()
- .onFile(new DefaultInputFile("src/Foo.php"))
+ .onFile(new DefaultInputFile("foo", "src/Foo.php"))
.withValue(3)
.build();
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseBuilderTest.java
new file mode 100644
index 00000000000..27a9777b6ee
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseBuilderTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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 org.sonar.api.batch.sensor.test.TestCase.Status;
+import org.sonar.api.batch.sensor.test.TestCase.Type;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultTestCaseBuilderTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private InputFile parent = new DefaultInputFile("foo", "src/Foo.php").setType(InputFile.Type.TEST);
+
+ @Test
+ public void testBuilder() throws Exception {
+ DefaultTestCaseBuilder builder = new DefaultTestCaseBuilder(parent, "myTest");
+ assertThat(builder.durationInMs(1)
+ .message("message")
+ .stackTrace("stack")
+ .status(Status.ERROR)
+ .type(Type.UNIT)
+ .build()).isEqualTo(new DefaultTestCase(parent, "myTest", 1L, Status.ERROR, "message", Type.UNIT, "stack"));
+ }
+
+ @Test
+ public void testBuilderWithDefaultValues() throws Exception {
+ DefaultTestCaseBuilder builder = new DefaultTestCaseBuilder(parent, "myTest");
+ assertThat(builder.build()).isEqualTo(
+ new DefaultTestCase(parent, "myTest", null, Status.OK, null, Type.UNIT, null));
+ }
+
+ @Test
+ public void testInvalidDuration() throws Exception {
+ DefaultTestCaseBuilder builder = new DefaultTestCaseBuilder(parent, "myTest");
+
+ thrown.expect(IllegalArgumentException.class);
+
+ builder.durationInMs(-3)
+ .message("message")
+ .stackTrace("stack")
+ .status(Status.ERROR)
+ .type(Type.UNIT)
+ .build();
+ }
+
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseTest.java
new file mode 100644
index 00000000000..ec5668ac3ca
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCaseTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.Test;
+import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.sensor.test.TestCase.Status;
+import org.sonar.api.batch.sensor.test.TestCase.Type;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class DefaultTestCaseTest {
+
+ private InputFile parent = new DefaultInputFile("foo", "src/Foo.php");
+
+ @Test
+ public void testDefaultTestCaseTest() {
+ DefaultTestCase testCase1 = new DefaultTestCase(parent, "myTest", 1L, Status.ERROR, "message", Type.UNIT, "stack");
+
+ assertThat(testCase1.name()).isEqualTo("myTest");
+ assertThat(testCase1.durationInMs()).isEqualTo(1L);
+ assertThat(testCase1.status()).isEqualTo(Status.ERROR);
+ assertThat(testCase1.message()).isEqualTo("message");
+ assertThat(testCase1.type()).isEqualTo(Type.UNIT);
+ assertThat(testCase1.stackTrace()).isEqualTo("stack");
+ }
+
+ @Test
+ public void testEqualsHashCodeToString() {
+ DefaultTestCase testCase1 = new DefaultTestCase(parent, "myTest", 1L, Status.ERROR, "message", Type.UNIT, "stack");
+ DefaultTestCase testCase1a = new DefaultTestCase(parent, "myTest", 1L, Status.ERROR, "message", Type.UNIT, "stack");
+ DefaultTestCase testCase2 = new DefaultTestCase(new DefaultInputFile("foo2", "src/Foo.php"), "myTest2", 2L, Status.FAILURE, "message2", Type.INTEGRATION, null);
+
+ assertThat(testCase1).isEqualTo(testCase1);
+ assertThat(testCase1).isEqualTo(testCase1a);
+ assertThat(testCase1).isNotEqualTo(testCase2);
+ assertThat(testCase1).isNotEqualTo(null);
+ assertThat(testCase1).isNotEqualTo("foo");
+
+ assertThat(testCase1.toString()).isEqualTo(
+ "DefaultTestCase[file=[moduleKey=foo, relative=src/Foo.php, abs=null],name=myTest,duration=1,status=ERROR,message=message,type=UNIT,stackTrace=stack]");
+ assertThat(testCase1.hashCode()).isEqualTo(testCase1a.hashCode());
+ }
+
+}