| | |
| | | */ |
| | | public class ConsoleApplicationTestCase extends CliTestCase { |
| | | |
| | | final LocalizableMessage msg = LocalizableMessage.raw("Language is the source of misunderstandings."); |
| | | final LocalizableMessage msg2 = LocalizableMessage |
| | | .raw("If somebody wants a sheep, that is a proof that one exists."); |
| | | |
| | | /** |
| | | * For test purposes only. |
| | | */ |
| | |
| | | private static ByteArrayOutputStream err; |
| | | private boolean verbose = false; |
| | | private boolean interactive = false; |
| | | private boolean quiet = false; |
| | | |
| | | private MockConsoleApplication(PrintStream out, PrintStream err) { |
| | | super(out, err); |
| | |
| | | return interactive; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isQuiet() { |
| | | return quiet; |
| | | } |
| | | |
| | | public void setVerbose(boolean v) { |
| | | verbose = v; |
| | | } |
| | |
| | | public void setInteractive(boolean inter) { |
| | | interactive = inter; |
| | | } |
| | | |
| | | public void setQuiet(boolean q) { |
| | | quiet = q; |
| | | } |
| | | } |
| | | |
| | | @Test() |
| | | public void testWriteLineInOutputStream() throws UnsupportedEncodingException { |
| | | final LocalizableMessage msg = LocalizableMessage |
| | | .raw("If somebody wants a sheep, that is a proof that one exists."); |
| | | final MockConsoleApplication ca = MockConsoleApplication.getDefault(); |
| | | ca.print(msg); |
| | | assertThat(ca.getOut()).contains(msg.toString()); |
| | |
| | | |
| | | @Test() |
| | | public void testWriteLineInErrorStream() throws UnsupportedEncodingException { |
| | | final LocalizableMessage msg = LocalizableMessage.raw("Language is the source of misunderstandings."); |
| | | final MockConsoleApplication ca = MockConsoleApplication.getDefault(); |
| | | ca.errPrintln(msg); |
| | | assertThat(ca.getOut()).isEmpty(); |
| | |
| | | |
| | | @Test() |
| | | public void testWriteOutputStreamVerbose() throws UnsupportedEncodingException { |
| | | final LocalizableMessage msg = LocalizableMessage |
| | | .raw("If somebody wants a sheep, that is a proof that one exists."); |
| | | final MockConsoleApplication ca = MockConsoleApplication.getDefault(); |
| | | ca.printVerboseMessage(msg); |
| | | assertThat(ca.isVerbose()).isFalse(); |
| | |
| | | |
| | | @Test() |
| | | public void testWriteErrorStreamVerbose() throws UnsupportedEncodingException { |
| | | final LocalizableMessage msg = LocalizableMessage.raw("Language is the source of misunderstandings."); |
| | | final MockConsoleApplication ca = MockConsoleApplication.getDefault(); |
| | | ca.errPrintVerboseMessage(msg); |
| | | assertThat(ca.isVerbose()).isFalse(); |
| | |
| | | */ |
| | | @Test() |
| | | public void testNonInteractiveApplicationShouldNotStdoutErrors() throws UnsupportedEncodingException { |
| | | final LocalizableMessage msg = LocalizableMessage.raw("Language is the source of misunderstandings."); |
| | | final LocalizableMessage msg2 = LocalizableMessage |
| | | .raw("If somebody wants a sheep, that is a proof that one exists."); |
| | | final MockConsoleApplication ca = MockConsoleApplication.getDefault(); |
| | | |
| | | assertFalse(ca.isInteractive()); |
| | |
| | | */ |
| | | @Test() |
| | | public void testInteractiveApplicationShouldStdoutErrors() throws UnsupportedEncodingException { |
| | | final LocalizableMessage msg = LocalizableMessage.raw("Language is the source of misunderstandings."); |
| | | final LocalizableMessage msg2 = LocalizableMessage |
| | | .raw("If somebody wants a sheep, that is a proof that one exists."); |
| | | |
| | | final MockConsoleApplication ca = MockConsoleApplication.getDefault(); |
| | | |
| | | assertFalse(ca.isInteractive()); |
| | |
| | | assertThat(ca.getOut()).contains(msg2.toString()); |
| | | assertThat(ca.getErr()).isEmpty(); |
| | | } |
| | | |
| | | /** |
| | | * In quiet mode, only the stderr should contain lines. |
| | | * @throws UnsupportedEncodingException |
| | | */ |
| | | @Test() |
| | | public void testQuietMode() throws UnsupportedEncodingException { |
| | | final MockConsoleApplication ca = MockConsoleApplication.getDefault(); |
| | | ca.setQuiet(true); |
| | | assertTrue(ca.isQuiet()); |
| | | ca.println(msg); |
| | | ca.errPrintln(msg2); |
| | | assertThat(ca.getOut()).isEmpty(); |
| | | assertThat(ca.getErr()).contains(msg2.toString()); |
| | | assertThat(ca.getErr()).doesNotContain(msg.toString()); |
| | | } |
| | | } |