diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-04-04 22:45:26 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-04-04 22:45:26 +0200 |
commit | c71267451a392f036b8f88656f10a17c5cd456ad (patch) | |
tree | 6052fcef841d9257413b86c55d5b6e92bf67356a /sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java | |
parent | 5d6050431f60bcde823fad161b979c4b8701f959 (diff) | |
download | sonar-scanner-cli-c71267451a392f036b8f88656f10a17c5cd456ad.tar.gz sonar-scanner-cli-c71267451a392f036b8f88656f10a17c5cd456ad.zip |
SONARPLUGINS-2574 set env variables + improve unit tests
Diffstat (limited to 'sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java')
-rw-r--r-- | sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java b/sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java index d3d2ca2..437d6bd 100644 --- a/sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java +++ b/sonar-runner-api/src/test/java/org/sonar/runner/api/EmbeddedRunnerTest.java @@ -20,9 +20,17 @@ package org.sonar.runner.api; import org.junit.Test; +import org.mockito.ArgumentMatcher; +import org.sonar.runner.impl.BatchLauncher; import org.sonar.runner.impl.Constants; +import java.util.List; +import java.util.Properties; + import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Matchers.argThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; public class EmbeddedRunnerTest { @Test @@ -31,6 +39,13 @@ public class EmbeddedRunnerTest { } @Test + public void test_app() { + EmbeddedRunner runner = EmbeddedRunner.create().setApp("Eclipse", "3.1"); + assertThat(runner.app()).isEqualTo("Eclipse"); + assertThat(runner.appVersion()).isEqualTo("3.1"); + } + + @Test public void should_set_unmasked_packages() { EmbeddedRunner runner = EmbeddedRunner.create(); assertThat(runner.property(Constants.UNMASKED_PACKAGES, null)).isNull(); @@ -49,6 +64,43 @@ public class EmbeddedRunnerTest { assertThat(runner.extensions()).containsExactly(fakeExtension); } + @Test + public void should_set_properties() { + EmbeddedRunner runner = EmbeddedRunner.create(); + runner.setProperty("sonar.projectKey", "foo"); + runner.addProperties(new Properties() {{ + setProperty("sonar.login", "admin"); + setProperty("sonar.password", "gniark"); + }}); + + assertThat(runner.property("sonar.projectKey", null)).isEqualTo("foo"); + assertThat(runner.property("sonar.login", null)).isEqualTo("admin"); + assertThat(runner.property("sonar.password", null)).isEqualTo("gniark"); + assertThat(runner.property("not.set", "this_is_default")).isEqualTo("this_is_default"); + } + + @Test + public void should_launch_batch() { + BatchLauncher batchLauncher = mock(BatchLauncher.class); + EmbeddedRunner runner = new EmbeddedRunner(batchLauncher); + final FakeExtension fakeExtension = new FakeExtension(); + runner.addExtensions(fakeExtension); + runner.setProperty("sonar.projectKey", "foo"); + runner.execute(); + + verify(batchLauncher).execute(argThat(new ArgumentMatcher<Properties>() { + @Override + public boolean matches(Object o) { + return "foo".equals(((Properties) o).getProperty("sonar.projectKey")); + } + }), argThat(new ArgumentMatcher<List<Object>>() { + @Override + public boolean matches(Object o) { + return ((List) o).contains(fakeExtension); + } + })); + } + static class FakeExtension { } } |