From 3258f16877c32accda2a1a7aec1a2114068b3bab Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sun, 7 Apr 2013 14:45:26 +0200 Subject: [PATCH] Add test --- .../org/sonar/runner/batch/IsolatedLauncher.java | 6 +++++- .../sonar/runner/batch/IsolatedLauncherTest.java | 14 ++++++++++++++ .../src/test/java_sample/sonar-project.properties | 5 +++++ .../src/test/java_sample/src/Sample.java | 0 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 sonar-runner-batch/src/test/java_sample/sonar-project.properties create mode 100644 sonar-runner-batch/src/test/java_sample/src/Sample.java diff --git a/sonar-runner-batch/src/main/java/org/sonar/runner/batch/IsolatedLauncher.java b/sonar-runner-batch/src/main/java/org/sonar/runner/batch/IsolatedLauncher.java index c541b1e..eee9da7 100644 --- a/sonar-runner-batch/src/main/java/org/sonar/runner/batch/IsolatedLauncher.java +++ b/sonar-runner-batch/src/main/java/org/sonar/runner/batch/IsolatedLauncher.java @@ -41,6 +41,10 @@ import java.util.Properties; public class IsolatedLauncher { public void execute(Properties properties, List extensions) { + createBatch(properties, extensions).execute(); + } + + Batch createBatch(Properties properties, List extensions) { ProjectReactor projectReactor = null; String task = properties.getProperty("sonar.task", "scan"); if ("scan".equals(task)) { @@ -57,7 +61,7 @@ public class IsolatedLauncher { if (projectReactor != null) { builder.setProjectReactor(projectReactor); } - builder.build().execute(); + return builder.build(); } private void initLogging(Properties props) { diff --git a/sonar-runner-batch/src/test/java/org/sonar/runner/batch/IsolatedLauncherTest.java b/sonar-runner-batch/src/test/java/org/sonar/runner/batch/IsolatedLauncherTest.java index 31c6174..44a2e2d 100644 --- a/sonar-runner-batch/src/test/java/org/sonar/runner/batch/IsolatedLauncherTest.java +++ b/sonar-runner-batch/src/test/java/org/sonar/runner/batch/IsolatedLauncherTest.java @@ -20,7 +20,9 @@ package org.sonar.runner.batch; import org.junit.Test; +import org.sonar.batch.bootstrapper.Batch; +import java.util.Collections; import java.util.Properties; import static org.fest.assertions.Assertions.assertThat; @@ -30,6 +32,18 @@ public class IsolatedLauncherTest { Properties props = new Properties(); IsolatedLauncher launcher = new IsolatedLauncher(); + @Test + public void should_create_batch() { + props.setProperty("sonar.projectBaseDir", "src/test/java_sample"); + props.setProperty("sonar.projectKey", "sample"); + props.setProperty("sonar.projectName", "Sample"); + props.setProperty("sonar.projectVersion", "1.0"); + props.setProperty("sonar.sources", "src"); + Batch batch = launcher.createBatch(props, Collections.emptyList()); + + assertThat(batch).isNotNull(); + } + @Test public void testGetSqlLevel() throws Exception { assertThat(IsolatedLauncher.getSqlLevel(props)).isEqualTo("WARN"); diff --git a/sonar-runner-batch/src/test/java_sample/sonar-project.properties b/sonar-runner-batch/src/test/java_sample/sonar-project.properties new file mode 100644 index 0000000..0c35484 --- /dev/null +++ b/sonar-runner-batch/src/test/java_sample/sonar-project.properties @@ -0,0 +1,5 @@ +sonar.projectKey=sample +sonar.projectName=Sample +sonar.projectVersion=1.0-SNAPSHOT +sonar.projectDescription=Sample description +sonar.sources=src diff --git a/sonar-runner-batch/src/test/java_sample/src/Sample.java b/sonar-runner-batch/src/test/java_sample/src/Sample.java new file mode 100644 index 0000000..e69de29 -- 2.39.5