]> source.dussan.org Git - sonar-scanner-cli.git/commitdiff
Add unit test to SONARPLUGINS-2982
authorSimon Brandhof <simon.brandhof@gmail.com>
Fri, 21 Jun 2013 12:27:29 +0000 (14:27 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Fri, 21 Jun 2013 12:27:29 +0000 (14:27 +0200)
sonar-runner-api/src/test/java/org/sonar/runner/api/ForkedRunnerTest.java

index 4d9d6aa4f6ec4e159c95354775f8190462838691..9a2040511ea8d87ef95df13c69fc0baf8deaa069 100644 (file)
@@ -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.*\\]");
+    }
+  }
 }