From cb2e27fc08f3b12aaea5c2614e1d14e37dbf6cf3 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 21 Jun 2013 14:27:29 +0200 Subject: [PATCH] Add unit test to SONARPLUGINS-2982 --- .../sonar/runner/api/ForkedRunnerTest.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/sonar-runner-api/src/test/java/org/sonar/runner/api/ForkedRunnerTest.java b/sonar-runner-api/src/test/java/org/sonar/runner/api/ForkedRunnerTest.java index 4d9d6aa..9a20405 100644 --- a/sonar-runner-api/src/test/java/org/sonar/runner/api/ForkedRunnerTest.java +++ b/sonar-runner-api/src/test/java/org/sonar/runner/api/ForkedRunnerTest.java @@ -32,12 +32,12 @@ import java.io.PrintStream; import java.util.Properties; import static org.fest.assertions.Assertions.assertThat; +import static org.fest.assertions.Fail.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.*; public class ForkedRunnerTest { @@ -139,4 +139,26 @@ public class ForkedRunnerTest { }), any(PrintStreamConsumer.class), any(PrintStreamConsumer.class), anyLong()); } + + @Test + public void test_failure_of_java_command() throws IOException { + JarExtractor jarExtractor = mock(JarExtractor.class); + final File jar = temp.newFile(); + when(jarExtractor.extractToTemp("sonar-runner-impl")).thenReturn(jar); + StreamConsumer out = mock(StreamConsumer.class); + StreamConsumer err = mock(StreamConsumer.class); + CommandExecutor commandExecutor = mock(CommandExecutor.class); + when(commandExecutor.execute(any(Command.class), eq(out), eq(err), anyLong())).thenReturn(3); + + ForkedRunner runner = new ForkedRunner(jarExtractor, commandExecutor); + runner.setStdOut(out); + runner.setStdErr(err); + + try { + runner.execute(); + fail(); + } catch (IllegalStateException e) { + assertThat(e.getMessage()).matches("Error status \\[command: .*java.*\\]"); + } + } } -- 2.39.5