### Question:
CommandlineParser { public boolean parseCommandLine(final String... args) { final ConfigFileCommand configFileCommand = new ConfigFileCommand(); final CommandLine configFileCommandLine = new CommandLine(configFileCommand); configFileCommandLine.parseArgs(args); if (configFileCommandLine.isUsageHelpRequested()) { executeCommandUsageHelp(); return true; } else if (configFileCommandLine.isVersionHelpRequested()) { executeCommandVersion(); return true; } final Optional<File> configFile = Optional.ofNullable(configFileCommand.configFileOption) .map(ConfigFileOption::getConfigFile); final CommandLine commandLine = new CommandLine(baseCommand); commandLine.setCaseInsensitiveEnumValuesAllowed(true); commandLine.registerConverter(Level.class, Level::valueOf); commandLine.setOut(outputWriter); commandLine.setErr(errorWriter); commandLine.setExecutionExceptionHandler(this::handleExecutionException); commandLine.setParameterExceptionHandler(this::handleParseException); for (final SignerSubCommand subcommand : signers) { commandLine.addSubcommand(subcommand.getCommandName(), subcommand); } commandLine.setDefaultValueProvider(defaultValueProvider(commandLine, configFile)); final int resultCode = commandLine.execute(args); return resultCode == CommandLine.ExitCode.OK; } CommandlineParser(
      final EthSignerBaseCommand baseCommand,
      final PrintWriter outputWriter,
      final PrintWriter errorWriter,
      final Map<String, String> environment); void registerSigners(final SignerSubCommand... signerSubCommands); boolean parseCommandLine(final String... args); static final String SIGNER_CREATION_ERROR; }### Answer:
@Test void mainCommandHelpIsDisplayedWhenNoOptionsOtherThanHelp() { final boolean result = parser.parseCommandLine("--help"); assertThat(result).isTrue(); assertThat(commandOutput.toString()).isEqualTo(defaultUsageText); }
@Test void mainCommandHelpIsDisplayedWhenNoOptionsOtherThanHelpWithoutDashes() { final boolean result = parser.parseCommandLine("help"); assertThat(result).isTrue(); assertThat(commandOutput.toString()).containsOnlyOnce(defaultUsageText); }
@Test void reverseHelpRequestShowsSubCommandHelp() { final boolean result = parser.parseCommandLine("help", subCommand.getCommandName()); assertThat(result).isTrue(); assertThat(commandOutput.toString()).isEqualTo(nullCommandHelp); }
@Test void illegalSubCommandDisplaysErrorMessage() { parser.parseCommandLine("--downstream-http-port=8500", "--chain-id=1", "illegalSubCommand"); assertThat(commandOutput.toString()) .containsOnlyOnce("Did you mean: " + subCommand.getCommandName()); assertThat(commandOutput.toString()).doesNotContain(defaultUsageText); }
@Test void misspeltCommandLineOptionDisplaysErrorMessage() { final boolean result = parser.parseCommandLine( "--downstream-http-port=8500", "--chain-id=1", "--nonExistentOption=9", subCommand.getCommandName()); assertThat(result).isFalse(); assertThat(commandOutput.toString()).containsOnlyOnce(defaultUsageText); }
@Test void corsCanBeACommaSeparatedList() { final List<String> cmdLine = toOptionsList(baseCommandOptions()); cmdLine.add("--http-cors-origins=sample.com,mydomain.com"); cmdLine.add(subCommand.getCommandName()); final boolean result = parser.parseCommandLine(cmdLine.toArray(String[]::new)); assertThat(result).isTrue(); assertThat(config.getCorsAllowedOrigins()).contains("sample.com", "mydomain.com"); }