diff --git a/gclc.system/src/main/java/net/bigeon/gclc/system/ExecSystemCommand.java b/gclc.system/src/main/java/net/bigeon/gclc/system/ExecSystemCommand.java index 88dc150..335ac8d 100644 --- a/gclc.system/src/main/java/net/bigeon/gclc/system/ExecSystemCommand.java +++ b/gclc.system/src/main/java/net/bigeon/gclc/system/ExecSystemCommand.java @@ -89,8 +89,7 @@ public class ExecSystemCommand extends Command { try { proc = Runtime.getRuntime().exec(args); } catch (final IOException e2) { - LOGGER.log(Level.SEVERE, "Unable to run process", e2); //$NON-NLS-1$ - return; + throw new CommandRunException("Unable to run process", e2); } final InputStream is = proc.getInputStream(); @@ -114,7 +113,9 @@ public class ExecSystemCommand extends Command { try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os))) { while (th.isAlive()) { String user = in.prompt(); - writer.write(user + EOL); + if (!user.isEmpty()) { + writer.write(user + EOL); + } } } catch (final IOException e1) { throw new CommandRunException(CommandRunExceptionType.INTERACTION, diff --git a/gclc.system/src/test/java/net/bigeon/gclc/system/ExecSystemCommandTest.java b/gclc.system/src/test/java/net/bigeon/gclc/system/ExecSystemCommandTest.java new file mode 100644 index 0000000..4789afb --- /dev/null +++ b/gclc.system/src/test/java/net/bigeon/gclc/system/ExecSystemCommandTest.java @@ -0,0 +1,41 @@ +package net.bigeon.gclc.system; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import net.bigeon.gclc.exception.CommandRunException; +import net.bigeon.gclc.manager.ConsoleInput; +import net.bigeon.gclc.manager.ConsoleOutput; +import net.bigeon.gclc.utils.EmptyInput; +import net.bigeon.gclc.utils.SinkOutput; + +public class ExecSystemCommandTest { + + @Test + public void testExecSystemCommand() { + ExecSystemCommand cmd = new ExecSystemCommand("test"); + assertEquals("Name should be preserved", "test", cmd.getCommandName()); + assertNotNull("tip should be defined", cmd.tip()); + assertNotNull("usage should be defined", cmd.usagePattern()); + assertNotNull("usage should be defined", cmd.usageDetail()); + } + + @Test + public void testExecute() throws CommandRunException { + ConsoleOutput out = SinkOutput.INSTANCE; + ConsoleInput in = EmptyInput.INSTANCE; + + ExecSystemCommand cmd = new ExecSystemCommand(); + if (System.getProperty("os.name").contains("indows")) { + cmd.execute(out, in, "cmd", "/C", "dir"); + try { + cmd.execute(out, in, "inexistent"); + fail("Able to execute inexistent command in system"); + } catch (CommandRunException e) { + // ok + } + } + } + +}