Main { int run(String[] args) { initJCommander(); try { parseParams(jc, args); if (help) { printUsage(null); return EXIT_CODE_OK; } if (debug) { initializeDebugLogging(); } if (jc.getParsedCommand() == null) { return handleNoCommand(); } if (!commands.containsKey(jc.getParsedCommand())) { LOGGER.error("Unknown command: " + jc.getParsedCommand()); return EXIT_CODE_ERR; } Command parsedCommand = commands.get(jc.getParsedCommand()); if (CommandHelp.CLINAME.equals(parsedCommand.getName())) { printUsage(null); } else { if (parsedCommand.validateParameters()) { parsedCommand.execute(); } else { printUsage(jc.getParsedCommand()); return EXIT_CODE_ERR; } } return EXIT_CODE_OK; } catch (Exception ex) { PrintWriter writer = new PrintWriter(output); output.print("Failed to run command '" + jc.getParsedCommand() + "'."); if (ex.getMessage() != null) { output.print(" " + ex.getMessage() + ".\n"); } else { ex.printStackTrace(writer); } writer.close(); LOGGER.debug("Exception while processing", ex); return EXIT_CODE_ERR; } }  static void main(String[] args); void setOutput(PrintStream output);  }
@Test public void testUp() { main.run(new String[]{"up"}); verify(commandUp).execute(); }
@Test public void testDestroy() { main.run(new String[]{"destroy"}); verify(commandDestroy).execute(); }
@Test public void testInfo() throws IOException { main.run(new String[]{"info"}); verify(commandInfo).execute(); }
@Test public void testState() throws IOException { main.run(new String[]{"state"}); verify(commandState).execute(); }
@Test public void testInstall() throws IOException { main.run(new String[]{"install", "--marathonFile", "bla.json"}); verify(commandInstall).execute(); }
@Test public void testLogs() throws IOException { main.run(new String[]{"logs", "--task", "something"}); verify(commandLogs).execute(); }
@Test public void testLogsNoParameter() throws IOException { main.run(new String[]{"logs", "--task"}); String result = outputStream.toString("UTF-8"); assertTrue(result.contains("Usage: logs [options]")); }
@Test public void testUnsupportedCommand() throws IOException { main.run(new String[]{"unsupported"}); String result = outputStream.toString("UTF-8"); assertUsageText(result); }
@Test public void testMinusMinusHelp() throws IOException { main.run(new String[]{"--help"}); String result = outputStream.toString("UTF-8"); assertUsageText(result); }
@Test public void testInstallNoParameters() throws IOException { main.run(new String[]{"install"}); String output = outputStream.toString("UTF-8"); assertTrue(output.contains("Usage: install [options]")); }
@Test public void testHelp() throws IOException { main.run(new String[]{"help"}); String result = outputStream.toString("UTF-8"); assertUsageText(result); }
@Test public void testNonExistingCommand() throws IOException { main.run(new String[]{"foo"}); String result = outputStream.toString("UTF-8"); assertUsageText(result); assertFalse(result.contains("Failed to run command 'null'. null")); }