01: package abbot.util;
02:
03: import java.io.*;
04: import junit.framework.*;
05: import junit.extensions.abbot.*;
06:
07: public class ProcessOutputHandlerTest extends TestCase {
08:
09: public void testExec() throws Exception {
10: String[] cmd = { "echo", "hello" };
11: String out = ProcessOutputHandler.exec(cmd);
12: assertEquals("Wrong output", "hello\n", out);
13:
14: try {
15: out = ProcessOutputHandler
16: .exec(new String[] { "no such command" });
17: fail("Non-existent command should throw an IOException");
18: } catch (IOException e) {
19: }
20:
21: try {
22: out = ProcessOutputHandler.exec(new String[] { "java",
23: "-no-such-option" });
24: fail("Expect exception with error output on non-zero exit");
25: } catch (IOException e) {
26: assertTrue("Error output should have been thrown", e
27: .getMessage().indexOf("exited") != -1);
28: }
29: }
30:
31: public ProcessOutputHandlerTest(String name) {
32: super (name);
33: }
34:
35: public static void main(String[] args) {
36: TestHelper.runTests(args, ProcessOutputHandlerTest.class);
37: }
38: }
|