aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-04-08 10:12:04 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2015-04-08 10:18:12 +0200
commit5cfd5f674d24b304db1ded615ee371905593fd40 (patch)
tree7ce153fd26820d467ed1775ce5409ca15f71df99 /sonar-batch
parent7c50d3b8c30dfb6898ed66daee5b04954f9ab5fc (diff)
downloadsonarqube-5cfd5f674d24b304db1ded615ee371905593fd40.tar.gz
sonarqube-5cfd5f674d24b304db1ded615ee371905593fd40.zip
Fix regression during local issue tracking on empty files
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/EmptyFileTest.java90
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/sonar-project.properties5
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/xources/hello/Empty.xoo0
-rw-r--r--sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/xources/hello/HelloJava.xoo8
4 files changed, 103 insertions, 0 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/EmptyFileTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/EmptyFileTest.java
new file mode 100644
index 00000000000..62ea53ce6ae
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/EmptyFileTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.batch.mediumtest.preview;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.batch.mediumtest.BatchMediumTester;
+import org.sonar.batch.mediumtest.TaskResult;
+import org.sonar.batch.protocol.input.ActiveRule;
+import org.sonar.xoo.XooPlugin;
+
+import java.io.File;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class EmptyFileTest {
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ @Rule
+ public LogTester logTester = new LogTester();
+
+ private static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
+
+ private static Long date(String date) {
+ try {
+ return sdf.parse(date).getTime();
+ } catch (ParseException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public BatchMediumTester tester = BatchMediumTester.builder()
+ .bootstrapProperties(ImmutableMap.of(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW))
+ .registerPlugin("xoo", new XooPlugin())
+ .addDefaultQProfile("xoo", "Sonar Way")
+ .activateRule(new ActiveRule("xoo", "OneIssuePerLine", null, "One issue per line", "MAJOR", "my/internal/key", "xoo"))
+ .setPreviousAnalysisDate(new Date())
+ .build();
+
+ @Before
+ public void prepare() {
+ tester.start();
+ }
+
+ @After
+ public void stop() {
+ tester.stop();
+ }
+
+ @Test
+ public void testIssueTrackingWithIssueOnEmptyFile() throws Exception {
+ File projectDir = new File(EmptyFileTest.class.getResource("/mediumtest/xoo/sample-with-empty-file").toURI());
+
+ TaskResult result = tester
+ .newScanTask(new File(projectDir, "sonar-project.properties"))
+ .property("sonar.xoo.internalKey", "my/internal/key")
+ .start();
+
+ assertThat(result.issues()).hasSize(10);
+ }
+
+}
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/sonar-project.properties b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/sonar-project.properties
new file mode 100644
index 00000000000..58f27e81f61
--- /dev/null
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/sonar-project.properties
@@ -0,0 +1,5 @@
+sonar.projectKey=sample-with-empty-file
+sonar.projectName=Sample With Empty
+sonar.projectVersion=0.1-SNAPSHOT
+sonar.sources=xources
+sonar.language=xoo
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/xources/hello/Empty.xoo b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/xources/hello/Empty.xoo
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/xources/hello/Empty.xoo
diff --git a/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/xources/hello/HelloJava.xoo b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/xources/hello/HelloJava.xoo
new file mode 100644
index 00000000000..1d9c60d56b7
--- /dev/null
+++ b/sonar-batch/src/test/resources/mediumtest/xoo/sample-with-empty-file/xources/hello/HelloJava.xoo
@@ -0,0 +1,8 @@
+package hello;
+
+public class HelloJava {
+
+ public static void main(String[] args) {
+ System.out.println("Hello");
+ }
+} \ No newline at end of file