diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-10-05 18:02:31 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-10-05 18:44:44 +0200 |
commit | 59e1f8eca37d7a37e0837e437ab3e6eb38a7dfea (patch) | |
tree | 67d86a8824cd5904a5cf8179b52bf5803930590c /sonar-batch/src | |
parent | 9bd6da57d295bec4f8d22d32c28cefd0032bceaa (diff) | |
download | sonarqube-59e1f8eca37d7a37e0837e437ab3e6eb38a7dfea.tar.gz sonarqube-59e1f8eca37d7a37e0837e437ab3e6eb38a7dfea.zip |
SONAR-6847 Fix NPE when creating issues on root directory
Diffstat (limited to 'sonar-batch/src')
2 files changed, 62 insertions, 0 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/deprecated/DeprecatedApiMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/deprecated/DeprecatedApiMediumTest.java index 7e8cdbcaf95..11c49c564c8 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/deprecated/DeprecatedApiMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/deprecated/DeprecatedApiMediumTest.java @@ -95,4 +95,40 @@ public class DeprecatedApiMediumTest { } + @Test + public void createIssueOnRootDir() throws IOException { + + File baseDir = temp.getRoot(); + + File xooFileInRootDir = new File(baseDir, "sample.xoo"); + FileUtils.write(xooFileInRootDir, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10"); + + File xooFileInAnotherDir = new File(baseDir, "package/sample.xoo"); + FileUtils.write(xooFileInAnotherDir, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10"); + + TaskResult result = tester.newTask() + .properties(ImmutableMap.<String, String>builder() + .put("sonar.task", "scan") + .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", ".") + .build()) + .start(); + + assertThat(result.issuesFor(result.inputFile("sample.xoo"))).extracting("msg", "line").containsOnly( + tuple("Issue created using deprecated API", 0), + tuple("Issue created using deprecated API", 1)); + assertThat(result.issuesFor(result.inputFile("package/sample.xoo"))).extracting("msg", "line").containsOnly( + tuple("Issue created using deprecated API", 0), + tuple("Issue created using deprecated API", 1)); + assertThat(result.issuesFor(result.inputDir(""))).extracting("msg", "line").containsOnly( + tuple("Issue created using deprecated API", 0)); + assertThat(result.issuesFor(result.inputDir("package"))).extracting("msg", "line").containsOnly( + tuple("Issue created using deprecated API", 0)); + + } + } diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java index 4fad08a8c99..4280af482f4 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java @@ -84,4 +84,30 @@ public class IssuesOnDirMediumTest { assertThat(result.issuesFor(result.inputDir("src"))).hasSize(2); } + @Test + public void issueOnRootFolder() throws IOException { + + File baseDir = temp.getRoot(); + + File xooFile1 = new File(baseDir, "sample1.xoo"); + FileUtils.write(xooFile1, "Sample1 xoo\ncontent"); + + File xooFile2 = new File(baseDir, "sample2.xoo"); + FileUtils.write(xooFile2, "Sample2 xoo\ncontent"); + + TaskResult result = tester.newTask() + .properties(ImmutableMap.<String, String>builder() + .put("sonar.task", "scan") + .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", ".") + .build()) + .start(); + + assertThat(result.issuesFor(result.inputDir(""))).hasSize(2); + } + } |