CommandLineApplication { public final void execute(final String[] args) { JCommander jCommander = new JCommander(); jCommander.setProgramName("spiner"); HelpCommand helpCommand = commandFactory.createHelpCommand(jCommander); jCommander.addObject(helpCommand); VersionCommand versionCommand = commandFactory.createVersionCommand(); jCommander.addObject(versionCommand); TransformCommand transformCommand = commandFactory.createTransformCommand(); jCommander.addCommand(CMD_TRANSFORM, transformCommand); jCommander.parse(args); if(versionCommand.isVersionCommand()) { versionCommand.run(); } else if(jCommander.getParsedCommand() != null) { if(CMD_TRANSFORM.equals(jCommander.getParsedCommand())) { transformCommand.run(); } } else { helpCommand.run(); } } @Inject  CommandLineApplication(final CommandFactory commandFactory); final void execute(final String[] args); static void main(final String[] args);  }
@Test public void execute_NoArguments_RunHelpCommand() { application.execute(new String[] {}); Mockito.verify(mockHelpCommand, Mockito.times(1)).run(); }
@Test public void execute_HelpParameter_RunHelpCommand() { application.execute(new String[] {"--help"}); Mockito.verify(mockHelpCommand, Mockito.times(1)).run(); }
@Test public void execute_VersionParameter_RunVersionCommand() { application.execute(new String[] {"--version"}); Mockito.verify(mockVersionCommand, Mockito.times(1)).run(); }
@Test(expected = MissingCommandException.class) public void execute_InvalidCommand_Unknown() { application.execute(new String[] {"thisdoesnotexist"}); }