CommandExecutor { public static int exec(String command, OutputStream out, OutputStream err) throws IOException, InterruptedException { CommandLine cmdLine = CommandLine.parse(command); Executor executor = new DefaultExecutor(); executor.setStreamHandler(new PumpStreamHandler(out, err, null)); return executor.execute(cmdLine); }  static int exec(String command, OutputStream out, OutputStream err); static int exec(String command);  }
@Test public void testExec_1() throws Exception { String command = "ls"; int result = CommandExecutor.exec(command); assertEquals(0, result); }
@Test public void testExec_3() throws Exception { String command = "sl"; int result = 0; try { result = CommandExecutor.exec(command); } catch (Exception e) { e.printStackTrace(); result = 1; } assertNotSame(0, result); }
@Test public void testExec_2() throws Exception { String command = "ls"; OutputStream out = new ByteArrayOutputStream(); OutputStream err = new ByteArrayOutputStream(); int result = CommandExecutor.exec(command, out, err); assertEquals(0, result); assertFalse(out.toString().isEmpty()); assertTrue(err.toString().isEmpty()); }