CommandDispatcher { public int run(String... arguments) { return run(Arrays.asList(arguments)); } CommandDispatcher(IO io, String group, List<CommandBuilder> commands);  CommandDispatcher(IO io, List<CommandBuilder> commands);  CommandDispatcher(IO io, CommandBuilder... commands); int run(String... arguments); int run(List<String> arguments); void help(List<String> arguments);  }
@Test(groups = "fast") public void testDispatchNoArgs() { CommandDispatcher dispatcher = createDispatcher(fooCommand); int resultStatus = dispatcher.run(); assertResult(resultStatus, 0, EXPECTED_ALL, ""); }
@Test(groups = "fast") public void testDispatchBogusArg() { CommandDispatcher dispatcher = createDispatcher(new FooCommand(io)); int resultStatus = dispatcher.run("bogus"); assertResult(resultStatus, -1, EXPECTED_ALL + "\n", "Unknown commandName: bogus\n"); }
@Test(groups = "fast") public void testDispatchHelp() { CommandDispatcher dispatcher = createDispatcher(fooCommand); int resultStatus = dispatcher.run("help"); assertResult(resultStatus, 0, EXPECTED_ALL, ""); }
@Test(groups = "fast") public void testDispatchHelpFoo() { CommandDispatcher dispatcher = createDispatcher(fooCommand); int resultStatus = dispatcher.run("help", "foo"); assertResult(resultStatus, 0, EXPECTED_FOO, ""); }
@Test(groups = "fast") public void testDispatchHelpHelp() { CommandDispatcher dispatcher = createDispatcher(fooCommand); int resultStatus = dispatcher.run("help", "help"); assertResult(resultStatus, 0, EXPECTED_HELP, ""); }
@Test(groups = "fast") public void testDispatchFoo() { CommandDispatcher dispatcher = createDispatcher(fooCommand); int resultStatus = dispatcher.run("foo", "--bar", "test"); assertResult(resultStatus, 0, "I am foo\n", "oof ma I\n"); }
@Test(groups = "fast") public void testDispatchFooMissingRequired() { CommandDispatcher dispatcher = createDispatcher(fooCommand); int resultStatus = dispatcher.run("foo"); assertResult(resultStatus, -1, EXPECTED_FOO + "\n", "Missing required option: --bar\n"); }
@Test(groups = "fast") public void testDuplicateArg() { CommandDispatcher dispatcher = createDispatcher(fooCommand); int resultStatus = dispatcher.run("foo", "-b", "bar", "--bar=baz"); assertResult(resultStatus, -1, EXPECTED_FOO + "\n", "Duplicate options: -b=bar, --bar=baz\n"); }