Cli implements Callable<Integer> { public static int parse(final String... args) { final CommandLine cli = new CommandLine(new Cli()); return cli.execute(args); }  static int parse(final String... args); @Override Integer call();  }
@Test void noArguments() { final int exit = Cli.parse(); assertThat(exit).isEqualTo(CommandLine.ExitCode.USAGE); }
@Test void nonExistentCommand() { final int exit = Cli.parse(UUID.randomUUID() .toString()); assertThat(exit).isEqualTo(CommandLine.ExitCode.USAGE); }
@Test void nonExistentOption() { final int exit = Cli.parse("-" + UUID.randomUUID()); assertThat(exit).isEqualTo(CommandLine.ExitCode.USAGE); }
@Test void basicHelp() { final int exit = Cli.parse("help"); assertThat(exit).isEqualTo(CommandLine.ExitCode.OK); }
@Test void helpWithSubcommand() { final int exit = Cli.parse("help", "strategy-validator"); assertThat(exit).isEqualTo(CommandLine.ExitCode.OK); }
@Test void correctSubcommandNoArguments() { final int exit = Cli.parse("strategy-validator"); assertThat(exit).isEqualTo(CommandLine.ExitCode.USAGE); }
@Test void correctSubcommandWrongArgument() { final int exit = Cli.parse("strategy-validator ", "--location=a.txt"); assertThat(exit).isEqualTo(CommandLine.ExitCode.USAGE); }
@Test void correctSubcommandCorrectArgumentWrongValue() { System.setIn(new ByteArrayInputStream("\n".getBytes())); final int exit = Cli.parse("strategy-validator", "--location=file: assertThat(exit).isEqualTo(CommandLine.ExitCode.SOFTWARE); }
@Test void correctSubcommandCorrectArgumentCorrectValue() throws IOException { File f = File.createTempFile("robozonky-", ".tmp"); System.setIn(new ByteArrayInputStream("\n".getBytes())); final int exit = Cli.parse("strategy-validator", "--location=" + f.toURI() .toURL()); assertThat(exit).isEqualTo(CommandLine.ExitCode.SOFTWARE + 1); }
@Test void helpWithNonexistentSubcommand() { final int exit = Cli.parse("help", UUID.randomUUID() .toString()); assertThat(exit).isEqualTo(CommandLine.ExitCode.USAGE); }