protected ByteArrayOutputStream main(final String... args) throws Exception { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final ByteArrayOutputStream err = new ByteArrayOutputStream(); final CliMain main = new CliMain(new PrintStream(out), new PrintStream(err), args); main.run(); return out; }
@SuppressWarnings("UseOfSystemOutOrSystemErr") public static void main(final String... args) { try { final int exitCode = new CliMain(System.out, System.err, args).run(); System.exit(exitCode); } catch (Throwable e) { // don't print error message for arg parser exception, because parser will do that if (!(e instanceof ArgumentParserException)) { System.err.println(e.toString()); } System.exit(1); } }
@Test public void test() throws Exception { final String[] commands = { "jobs", "--no-log-setup", "-d", "bogusdomain" }; final ByteArrayOutputStream stdout = new ByteArrayOutputStream(); final ByteArrayOutputStream stderr = new ByteArrayOutputStream(); new CliMain(new PrintStream(stdout), new PrintStream(stderr), commands).run(); final String string = stderr.toString(); assertTrue(string.trim().equals( "Failed to resolve helios master in bogusdomain (srv: helios)")); } }
final CliMain main = new CliMain(new PrintStream(out), new PrintStream(new ByteArrayOutputStream()), commands); main.run(); assertTrue("Should have stopped the stream due to success: got\n" + Joiner.on("").join(outputLines), success.get());
final CliMain main = new CliMain(new PrintStream(out), new PrintStream(new ByteArrayOutputStream()), commands); main.run(); assertTrue("Should have stopped the stream due to success: got\n" + Joiner.on("").join(outputLines), success.get());
@SuppressWarnings("UseOfSystemOutOrSystemErr") public static void main(final String... args) { try { int exitCode = new CliMain(System.out, System.err, args).run(); System.exit(exitCode); } catch (Throwable e) { // don't print error message for arg parser exception, because parser will do that if (!(e instanceof ArgumentParserException)) { System.err.println(e.toString()); } System.exit(1); } }