diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-07-10 18:50:56 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-07-11 17:03:16 +0200 |
commit | 4a6b9541a01065121b6472360c178708c5697f38 (patch) | |
tree | fcd4c6342e1f5af44c4024da399b6eea8c53396d /sonar-plugin-api/src/test/java/org | |
parent | dc893d90da17245af18884502531554a727ea034 (diff) | |
download | sonarqube-4a6b9541a01065121b6472360c178708c5697f38.tar.gz sonarqube-4a6b9541a01065121b6472360c178708c5697f38.zip |
Command env variables are initialized with System.getenv()
Diffstat (limited to 'sonar-plugin-api/src/test/java/org')
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandTest.java | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandTest.java index b069ac4f931..cd47f03703a 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/command/CommandTest.java @@ -19,23 +19,30 @@ */ package org.sonar.api.utils.command; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import java.io.File; +import java.util.Arrays; + +import static org.fest.assertions.Assertions.assertThat; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; public class CommandTest { - @Test(expected = IllegalArgumentException.class) + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test public void shouldFailWhenBlankExecutable() throws Exception { + thrown.expect(IllegalArgumentException.class); Command.create(" "); } - @Test(expected = IllegalArgumentException.class) + @Test public void shouldFailWhenNullExecutable() throws Exception { + thrown.expect(IllegalArgumentException.class); Command.create(null); } @@ -43,19 +50,40 @@ public class CommandTest { public void shouldCreateCommand() throws Exception { Command command = Command.create("java"); command.addArgument("-Xmx512m"); - command.addArgument("-Dfoo=bar"); - assertThat(command.getExecutable(), is("java")); - assertThat(command.getArguments().size(), is(2)); - assertThat(command.toCommandLine(), is("java -Xmx512m -Dfoo=bar")); + command.addArguments(Arrays.asList("-a", "-b")); + command.addArguments(new String[]{"-x", "-y"}); + assertThat(command.getExecutable()).isEqualTo("java"); + assertThat(command.getArguments()).hasSize(5); + assertThat(command.toCommandLine()).isEqualTo("java -Xmx512m -a -b -x -y"); + } + + @Test + public void toString_is_the_command_line() { + Command command = Command.create("java"); + command.addArgument("-Xmx512m"); + assertThat(command.toString()).isEqualTo(command.toCommandLine()); } @Test public void shouldSetWorkingDirectory() throws Exception { Command command = Command.create("java"); - assertThat(command.getDirectory(), nullValue()); + assertThat(command.getDirectory()).isNull(); File working = new File("working"); command = Command.create("java").setDirectory(working); - assertThat(command.getDirectory(), is(working)); + assertThat(command.getDirectory()).isEqualTo(working); + } + + @Test + public void initialize_with_current_env() throws Exception { + Command command = Command.create("java"); + assertThat(command.getEnvironmentVariables()).isNotEmpty(); + } + + @Test + public void override_env_variables() throws Exception { + Command command = Command.create("java"); + command.setEnvironmentVariable("JAVA_HOME", "/path/to/java"); + assertThat(command.getEnvironmentVariables().get("JAVA_HOME")).isEqualTo("/path/to/java"); } } |