diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-11-13 15:36:49 +0100 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-11-16 17:26:06 +0100 |
commit | 1309845e856c33c5ca18c7295764993564a2a9c2 (patch) | |
tree | 8b25a6710e31343b23b432340f6cfda236fb2717 /sonar-batch/src/test | |
parent | a7fbd0596d337b2aa2a2540355866efbbc3a17ad (diff) | |
download | sonarqube-1309845e856c33c5ca18c7295764993564a2a9c2.tar.gz sonarqube-1309845e856c33c5ca18c7295764993564a2a9c2.zip |
SONAR-6976 Branch should not allow \n character
Diffstat (limited to 'sonar-batch/src/test')
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java | 76 |
1 files changed, 50 insertions, 26 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java index 119aa973416..ed7a35a4836 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java @@ -20,14 +20,12 @@ package org.sonar.batch.mediumtest.fs; import com.google.common.collect.ImmutableMap; -import java.io.File; -import java.io.IOException; -import java.util.Date; -import java.util.List; import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.batch.mediumtest.BatchMediumTester; import org.sonar.batch.mediumtest.TaskResult; @@ -35,12 +33,20 @@ import org.sonar.batch.protocol.output.BatchReport.Issue; import org.sonar.xoo.XooPlugin; import org.sonar.xoo.rule.XooRulesDefinition; +import java.io.File; +import java.io.IOException; +import java.util.Date; +import java.util.List; + import static org.assertj.core.api.Assertions.assertThat; public class ProjectBuilderMediumTest { - @org.junit.Rule + @Rule public TemporaryFolder temp = new TemporaryFolder(); + + @Rule + public ExpectedException exception = ExpectedException.none(); public BatchMediumTester tester = BatchMediumTester.builder() .registerPlugin("xoo", new XooPlugin()) @@ -62,17 +68,8 @@ public class ProjectBuilderMediumTest { @Test public void testProjectBuilder() throws IOException { - - File baseDir = temp.getRoot(); - File module1Dir = new File(baseDir, "module1"); - module1Dir.mkdir(); - - File srcDir = new File(module1Dir, "src"); - srcDir.mkdir(); - - File xooFile = new File(srcDir, "sample.xoo"); - FileUtils.write(xooFile, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10"); - + File baseDir = prepareProject(); + TaskResult result = tester.newTask() .properties(ImmutableMap.<String, String>builder() .put("sonar.task", "scan") @@ -99,19 +96,32 @@ public class ProjectBuilderMediumTest { assertThat(foundIssueAtLine1).isTrue(); } + + @Test + // SONAR-6976 + public void testProjectBuilderWithNewLine() throws IOException { + File baseDir = prepareProject(); + + exception.expect(IllegalStateException.class); + exception.expectMessage("is not a valid branch name"); + 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.branch", "branch\n") + .put("sonar.projectVersion", "1.0-SNAPSHOT") + .put("sonar.projectDescription", "Description of Foo Project") + .put("sonar.sources", ".") + .put("sonar.xoo.enableProjectBuilder", "true") + .build()) + .start(); + } @Test public void testProjectBuilderWithBranch() throws IOException { - - File baseDir = temp.getRoot(); - File module1Dir = new File(baseDir, "module1"); - module1Dir.mkdir(); - - File srcDir = new File(module1Dir, "src"); - srcDir.mkdir(); - - File xooFile = new File(srcDir, "sample.xoo"); - FileUtils.write(xooFile, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10"); + File baseDir = prepareProject(); TaskResult result = tester.newTask() .properties(ImmutableMap.<String, String>builder() @@ -140,5 +150,19 @@ public class ProjectBuilderMediumTest { } assertThat(foundIssueAtLine1).isTrue(); } + + private File prepareProject() throws IOException { + File baseDir = temp.getRoot(); + File module1Dir = new File(baseDir, "module1"); + module1Dir.mkdir(); + + File srcDir = new File(module1Dir, "src"); + srcDir.mkdir(); + + File xooFile = new File(srcDir, "sample.xoo"); + FileUtils.write(xooFile, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10"); + + return baseDir; + } } |