use of picocli.CommandLine in project aion by aionnetwork.
the class CliTest method testAccountCliParseAndRun.
@Parameters(method = "parametersFortestAccountCliParseAndRun")
@Test
public void testAccountCliParseAndRun(String[] options, ReturnType expected) {
CommandLine commandLine = new CommandLine(Arguments.class).addSubcommand(EditCli.class);
ParseResult result;
try {
result = commandLine.parseArgs(options);
} catch (Exception e) {
if (expected.equals(ERROR)) {
return;
} else {
throw e;
}
}
CommandSpec commandSpec = Cli.findCommandSpec(result, AccountCli.class);
// noinspection ConstantConditions
AccountCli spiedAccountCLI = spy((AccountCli) commandSpec.userObject());
doReturn(true).when(spiedAccountCLI).exportPrivateKey(anyString(), any());
doReturn(true).when(spiedAccountCLI).listAccounts();
doReturn(true).when(spiedAccountCLI).createAccount(any());
doReturn(true).when(spiedAccountCLI).importPrivateKey(anyString(), any());
doCallRealMethod().when(spiedAccountCLI).runCommand(any());
assertThat(spiedAccountCLI.runCommand(mockpr)).isEqualTo(expected);
if (spiedAccountCLI.getList()) {
verify(spiedAccountCLI, times(1)).listAccounts();
} else {
verify(spiedAccountCLI, times(0)).listAccounts();
}
if (!spiedAccountCLI.getGroup().getImportAcc().isEmpty()) {
verify(spiedAccountCLI, times(1)).importPrivateKey(anyString(), any());
} else {
verify(spiedAccountCLI, times(0)).importPrivateKey(anyString(), any());
}
if (!spiedAccountCLI.getGroup().getExport().isEmpty()) {
verify(spiedAccountCLI, times(1)).exportPrivateKey(anyString(), any());
} else {
verify(spiedAccountCLI, times(0)).exportPrivateKey(anyString(), any());
}
if (spiedAccountCLI.getGroup().getCreate()) {
verify(spiedAccountCLI, times(1)).createAccount(any());
} else {
verify(spiedAccountCLI, times(0)).createAccount(any());
}
Mockito.clearInvocations(spiedAccountCLI);
}
use of picocli.CommandLine in project aion by aionnetwork.
the class CliTest method testCommandSpec.
@Parameters(method = "parametersFortestCommandSpec")
@Test
public void testCommandSpec(String[] args, Object[] expectedClasses) {
CommandLine cli = new CommandLine(new Arguments()).addSubcommand("edit", new EditCli());
CommandLine.ParseResult result = cli.parseArgs(args);
for (Object expected : expectedClasses) {
CommandLine.Model.CommandSpec spec = Cli.findCommandSpec(result, (Class<?>) expected);
assertThat(spec).isNotNull();
assertThat(spec.userObject().getClass()).isEqualTo(expected);
}
}
use of picocli.CommandLine in project aion by aionnetwork.
the class CliTest method testCheckArguments.
@Test
@Parameters(method = "parametersForArgumentCheck")
public void testCheckArguments(String[] input, TaskPriority expectedPriority, Set<String> expectedTasks) {
Arguments options = new Arguments();
CommandLine parser = new CommandLine(options);
CommandLine.ParseResult result = parser.parseArgs(input);
TaskPriority breakingTaskPriority = cli.getBreakingTaskPriority(options, result);
assertEquals(expectedPriority, breakingTaskPriority);
Set<String> skippedTasks = cli.getSkippedTasks(options, breakingTaskPriority, result);
assertEquals(expectedTasks, skippedTasks);
}
use of picocli.CommandLine in project aion by aionnetwork.
the class CliTest method testParseDev.
@Parameters(method = "parametersForTestParseDev")
@Test
public void testParseDev(String[] command) {
CommandLine commandLine = new CommandLine(new Arguments()).addSubcommand(EditCli.class);
final CommandLine.ParseResult result = commandLine.parseArgs(command);
CommandLine.Model.CommandSpec spec = Cli.findCommandSpec(result, DevCLI.class);
assertThat(spec).isNotNull();
assertThat(spec.userObject()).isNotNull();
assertThat(((DevCLI) spec.userObject()).getArgs()).isNotNull();
((DevCLI) spec.userObject()).getArgs().checkOptions();
}
use of picocli.CommandLine in project aion by aionnetwork.
the class CliTest method testCommandSpecFail.
@Parameters(method = "parametersForTestCommandSpecFail")
@Test(expected = RuntimeException.class)
public void testCommandSpecFail(String[] args, Object[] expectedClasses) {
CommandLine cli = new CommandLine(new Arguments()).addSubcommand("edit", new EditCli());
CommandLine.ParseResult result = cli.parseArgs(args);
for (Object expected : expectedClasses) {
CommandLine.Model.CommandSpec spec = Cli.findCommandSpec(result, (Class<?>) expected);
Objects.requireNonNull(spec);
}
}
Aggregations