CommandLine { @SuppressWarnings({"PMD.AvoidLiteralsInIfCondition", "ReturnCount"}) public Optional<ExitCode> parse(final String... args) { if (args.length == 0) { printUsage(commander); return Optional.of(ExitCode.ARGUMENT_PARSING_ERROR); } try { commander.parse(args); } catch (ParameterException e) { LOGGER.debug("Error during arguments parsing: {}", e); LOGGER.info("Could not parse arguments: {}", e.getMessage()); printUsage(commander); return Optional.of(ExitCode.ARGUMENT_PARSING_ERROR); } final List<Path> reportDirectories = openCommand.getReportDirectories(); if (reportDirectories.size() != 1) { LOGGER.error("Only one main argument is allowed"); return Optional.of(ExitCode.ARGUMENT_PARSING_ERROR); } return Optional.empty(); } CommandLine(final Path allureHome);  CommandLine(final Commands commands); static void main(final String[] args); @SuppressWarnings({"PMD.AvoidLiteralsInIfCondition", "ReturnCount"}) Optional<ExitCode> parse(final String... args); @SuppressWarnings({ "CyclomaticComplexity", "NPathComplexity", "ReturnCount", "PMD.NPathComplexity", "PMD.CyclomaticComplexity", "PMD.ExcessiveMethodLength" }) ExitCode run(); JCommander getCommander(); MainCommand getMainCommand();  }
@Test void shouldParseEmptyArguments() { final Optional<ExitCode> parse = commandLine.parse(); assertThat(parse) .hasValue(ExitCode.ARGUMENT_PARSING_ERROR); }
@Test void shouldAllowResultsDirectoriesThatNotExists() { final Optional<ExitCode> exitCode = commandLine.parse(GENERATE_COMMAND, randomString(), randomString()); assertThat(exitCode) .isEmpty(); }
@Test void shouldNotLetToSpecifyFewReportDirectories(@TempDir final Path temp) throws IOException { final Path first = Files.createDirectories(temp.resolve("first")); final Path second = Files.createDirectories(temp.resolve("second")); final Optional<ExitCode> exitCode = commandLine.parse( OPEN_COMMAND, first.toString(), second.toString() ); assertThat(exitCode) .isPresent() .hasValue(ExitCode.ARGUMENT_PARSING_ERROR); }
@Test void shouldValidatePortValue() { final Optional<ExitCode> exitCode = commandLine.parse(SERVE_COMMAND, "--port", "213123"); assertThat(exitCode) .isPresent() .hasValue(ARGUMENT_PARSING_ERROR); }