Added comment and test

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
2018-10-26 10:09:33 -04:00
parent af0c8e91f8
commit 674333a42c
2 changed files with 59 additions and 4 deletions

View File

@@ -0,0 +1,44 @@
package net.bigeon.gclc.command.base;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.io.IOException;
import org.junit.Test;
import net.bigeon.gclc.exception.CommandRunException;
import net.bigeon.gclc.utils.PipedConsoleOutput;
public class EchoCommandTest {
@Test
public void testExecute() throws IOException, CommandRunException {
final EchoCommand echo = new EchoCommand("echo");
assertNotNull("Help tip should be specified", echo.tip());
assertNotNull("Usage should be specified", echo.usageDetail());
try (PipedConsoleOutput out = new PipedConsoleOutput()) {
echo.execute(out, null);
assertEquals("Echo should print a line", "", out.readNextLine());
echo.execute(out, null, "Message");
assertEquals("Echo should print argument", "Message", out.readNextLine());
echo.execute(out, null, "Message {0}", "with parameter");
assertEquals("Echo should format string and print", "Message with parameter",
out.readNextLine());
}
final PipedConsoleOutput out = new PipedConsoleOutput();
out.close();
try {
echo.execute(out, null);
fail("Should not be able to print in closed outputs");
} catch (final CommandRunException e) {
// expected
}
}
}