summaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-11-12 16:07:45 +0100
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-11-16 15:12:13 +0100
commitff15786ca7aa029a1ae4a2ed67f5352a1b03853b (patch)
tree8092e240908b8514da9ce847d50c7be27983e60d /sonar-batch
parent9db3683485161ca1a5b786ccbed3144d4daf6610 (diff)
downloadsonarqube-ff15786ca7aa029a1ae4a2ed67f5352a1b03853b.tar.gz
sonarqube-ff15786ca7aa029a1ae4a2ed67f5352a1b03853b.zip
SONAR-5676 Improve validation of highlighting API
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java49
1 files changed, 48 insertions, 1 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java
index bb0ad02c659..9672d2a4b5d 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/highlighting/HighlightingMediumTest.java
@@ -19,9 +19,16 @@
*/
package org.sonar.batch.mediumtest.highlighting;
+import org.hamcrest.TypeSafeMatcher;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.junit.rules.ExpectedException;
import com.google.common.collect.ImmutableMap;
+
import java.io.File;
import java.io.IOException;
+
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.After;
@@ -34,7 +41,6 @@ import org.sonar.api.batch.sensor.highlighting.TypeOfText;
import org.sonar.batch.mediumtest.BatchMediumTester;
import org.sonar.batch.mediumtest.TaskResult;
import org.sonar.xoo.XooPlugin;
-
import static org.assertj.core.api.Assertions.assertThat;
public class HighlightingMediumTest {
@@ -42,6 +48,9 @@ public class HighlightingMediumTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
+ @Rule
+ public ExpectedException exception = ExpectedException.none();
+
public BatchMediumTester tester = BatchMediumTester.builder()
.registerPlugin("xoo", new XooPlugin())
.addDefaultQProfile("xoo", "Sonar Way")
@@ -88,6 +97,44 @@ public class HighlightingMediumTest {
}
@Test
+ public void computeInvalidOffsets() throws IOException {
+
+ File baseDir = temp.newFolder();
+ File srcDir = new File(baseDir, "src");
+ srcDir.mkdir();
+
+ File xooFile = new File(srcDir, "sample.xoo");
+ File xoohighlightingFile = new File(srcDir, "sample.xoo.highlighting");
+ FileUtils.write(xooFile, "Sample xoo\ncontent plop");
+ FileUtils.write(xoohighlightingFile, "0:10:s\n18:18:k");
+
+ exception.expect(IllegalStateException.class);
+ exception.expectMessage("Error processing line 2");
+ exception.expectCause(new TypeSafeMatcher<IllegalArgumentException>() {
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("Invalid cause");
+ }
+
+ @Override
+ protected boolean matchesSafely(IllegalArgumentException e) {
+ return e.getMessage().contains("Unable to highlight file");
+ }
+ });
+
+ TaskResult result = tester.newTask()
+ .properties(ImmutableMap.<String, String>builder()
+ .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
+ .put("sonar.projectKey", "com.foo.project")
+ .put("sonar.projectName", "Foo Project")
+ .put("sonar.projectVersion", "1.0-SNAPSHOT")
+ .put("sonar.projectDescription", "Description of Foo Project")
+ .put("sonar.sources", "src")
+ .build())
+ .start();
+ }
+
+ @Test
public void computeSyntaxHighlightingOnBigFile() throws IOException {
File baseDir = temp.newFolder();