Search in sources :

Example 36 with CommandLine

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);
}
Also used : CommandLine(picocli.CommandLine) ParseResult(picocli.CommandLine.ParseResult) CommandSpec(picocli.CommandLine.Model.CommandSpec) IOException(java.io.IOException) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 37 with CommandLine

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);
    }
}
Also used : CommandLine(picocli.CommandLine) ParseResult(picocli.CommandLine.ParseResult) CommandSpec(picocli.CommandLine.Model.CommandSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 38 with CommandLine

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);
}
Also used : CommandLine(picocli.CommandLine) ParseResult(picocli.CommandLine.ParseResult) TaskPriority(org.aion.zero.impl.cli.Cli.TaskPriority) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 39 with CommandLine

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();
}
Also used : CommandLine(picocli.CommandLine) ParseResult(picocli.CommandLine.ParseResult) CommandSpec(picocli.CommandLine.Model.CommandSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 40 with CommandLine

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);
    }
}
Also used : CommandLine(picocli.CommandLine) ParseResult(picocli.CommandLine.ParseResult) CommandSpec(picocli.CommandLine.Model.CommandSpec) Parameters(junitparams.Parameters) Test(org.junit.Test)

Aggregations

CommandLine (picocli.CommandLine)68 Test (org.junit.jupiter.api.Test)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)20 Copier (org.neo4j.pushtocloud.PushToCloudCommand.Copier)17 ParseResult (picocli.CommandLine.ParseResult)12 Path (java.nio.file.Path)9 Test (org.junit.Test)9 IOException (java.io.IOException)8 Parameters (junitparams.Parameters)8 CommandSpec (picocli.CommandLine.Model.CommandSpec)6 PrintWriter (java.io.PrintWriter)5 DumpCreator (org.neo4j.pushtocloud.PushToCloudCommand.DumpCreator)5 ParameterException (picocli.CommandLine.ParameterException)4 HashMap (java.util.HashMap)3 List (java.util.List)3 Set (java.util.Set)3 OptionSpec (picocli.CommandLine.Model.OptionSpec)3 InputErrorException (eu.stamp_project.dspot.common.configuration.check.InputErrorException)2 File (java.io.File)2 PrintStream (java.io.PrintStream)2