-1

In a unit test for a utility using picocli, I would like to assert that picocli assigned the correct value to the option. How can I get the value associated with an option in a unit test?

Here is the current version of the unit test:

@Test
void callWithOptionForSuffix() {
    NextMajorSubcommand command = new NextMajorSubcommand();
    CommandLine cmdline = new CommandLine(command);

    ParseResult parseResult = cmdline.parseArgs("--suffix", "DELTA", "4.5.6");

    assertThat(parseResult.hasMatchedPositional(0)).isTrue();
    assertThat(parseResult.matchedOptions()).isNotEmpty();
    assertThat(parseResult.matchedOption("--suffix").isOption());
}

Oliver
  • 3,815
  • 8
  • 35
  • 63

1 Answers1

0

Picocli offers the method getValue() to get the parsed value for an option.

assertThat(parseResult.matchedOption("--suffix").String>getValue())
    .hasValue("DELTA");
Oliver
  • 3,815
  • 8
  • 35
  • 63