在使用picocli的实用程序的单元测试中,我想断言picocli为选项分配了正确的值。如何在单元测试中获得与选项相关的值?
下面是单元测试的当前版本:
@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());
}
Picocli提供了getValue()
方法来获取选项的解析值。
assertThat(parseResult.matchedOption("--suffix").String>getValue())
.hasValue("DELTA");