### Question:
Main { int run(@Nonnull String[] args, @Nonnull final ProcessStream system) { OptionHandlerRegistry.getRegistry().registerHandler(CliCommand.class, CliCommandOptionHandler.class); OptionHandlerRegistry.getRegistry().registerHandler(ProcessRuntime.class, new OptionHandlerRegistry.OptionHandlerFactory() { public OptionHandler<?> getHandler(CmdLineParser parser, OptionDef o, Setter setter) { return new ProcessRuntimeOptionHandler(parser, o, setter, system); } }); CmdLineParser parser = new CmdLineParser(this); try { parser.parseArgument(args); return handler.run(system); } catch (CmdLineException ex) { system.err().println(ex.getMessage()); HelpCommand.printUsage(handler, system.err(), ex); } catch (CommandFailedException ex) { system.err().println(ex.getMessage()); } catch (RuntimeException ex) { ex.printStackTrace(system.err()); } return -1; }  static void main(@Nonnull String[] args);  }### Answer:
@Test public void notEnoughArguments() { run(); assertThat(err.toString(), containsString("Argument \"COMMAND\" is required")); assertThat(out.toString(), equalTo("")); assertThat(exitValue, not(equalTo(0))); }
@Test public void noSuchCommand() { run("there_is_no_such_command"); assertThat(err.toString(), containsString("Command \"there_is_no_such_command\" not found")); assertThat(out.toString(), equalTo("")); assertThat(exitValue, not(equalTo(0))); }
@Test public void help() { run("help"); assertThat(err.toString(), equalTo("")); assertThat(out.toString(), containsString("Usage: ")); assertThat(out.toString(), containsString("Available commands:")); assertThat(out.toString(), containsString("blocking-tree")); assertThat(this, succeeded()); }
@Test public void detailedHelp() { run("help", "deadlocks"); assertThat(err.toString(), equalTo("")); assertThat(out.toString(), containsString("dumpling.sh deadlocks")); assertThat(out.toString(), containsString("Detect cycles of blocked threads")); assertThat(this, succeeded()); }
@Test public void factoryWithoutKind() { run("deadlocks", "--in"); assertThat(out.toString(), equalTo("")); assertThat(exitValue, not(equalTo(0))); assertThat(err.toString(), containsString("takes an operand KIND")); }
@Test public void factoryWithoutLocator() { run("deadlocks", "--in", "threaddump:"); assertThat(out.toString(), equalTo("")); assertThat(exitValue, not(equalTo(0))); assertThat(err.toString(), containsString("No locator provided for scheme: threaddump")); }
@Test public void runtimeKindHelp() throws Exception { run("deadlocks", "--in", "dead:beef"); assertThat(out.toString(), equalTo("")); assertThat(exitValue, not(equalTo(0))); assertThat(err.toString(), containsString("Unknown runtime source kind: dead")); assertThat(err.toString(), containsString("Available runtime source KINDs:")); }