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());
}
How can I do that?
-- N Oliver B. Fischer A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany P +49 30 44793251 M +49 178 7903538 E o.b.f...@swe-blog.net S oliver.b.fischer J oliver.b...@jabber.org X http://xing.to/obf
assertThat(parseResult.matchedOption("--suffix").<Optional<String>>getValue()).hasValue("DELTA");BTW: Picocli is awesome. I will use it also for the command line distribution of jQAssistant
Hi Oliver,
Some ideas using the ParseResult:
assertEquals(parseResult.matchedOption("--suffix").getValue(), "DELTA");
orassertEquals(parseResult.matchedOptionValue("--suffix", null), "DELTA");
alternatively you can query the NextMajorSubcommand object (if it has visible getters):
assertEquals(command.getSuffix(), "DELTA");