Search in sources :

Example 1 with Arguments

use of com.karuslabs.commons.command.arguments.Arguments in project Karus-Commons by Pante.

the class CommandTest method complete_delegate.

@Test
void complete_delegate() {
    Arguments arguments = spy(new Arguments("subcommand"));
    Command subcommand = when(mock(Command.class).complete(sender, arguments)).thenReturn(singletonList("a")).getMock();
    command.getSubcommands().put("subcommand", subcommand);
    assertEquals(singletonList("a"), command.complete(sender, arguments));
    verify(arguments).trim();
    verify(subcommand).complete(sender, arguments);
}
Also used : Command(com.karuslabs.commons.command.Command) Arguments(com.karuslabs.commons.command.arguments.Arguments) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with Arguments

use of com.karuslabs.commons.command.arguments.Arguments in project Karus-Commons by Pante.

the class CommandTest method complete_subcommands.

@ParameterizedTest
@MethodSource("complete_parameters")
void complete_subcommands(String name, String permission, List<String> expected) {
    Arguments arguments = new Arguments("subcommand");
    Command subcommand = new Command(name, null);
    subcommand.setPermission(permission);
    command.getSubcommands().put(name, subcommand);
    assertEquals(expected, command.complete(sender, arguments));
}
Also used : Command(com.karuslabs.commons.command.Command) Arguments(com.karuslabs.commons.command.arguments.Arguments) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Arguments

use of com.karuslabs.commons.command.arguments.Arguments in project Karus-Commons by Pante.

the class CommandTest method complete_completions.

@Test
void complete_completions() {
    Arguments arguments = new Arguments("argument");
    Completion completion = when(mock(Completion.class).complete(sender, "argument")).thenReturn(singletonList("a")).getMock();
    command.getCompletions().put(0, completion);
    assertEquals(singletonList("a"), command.complete(sender, arguments));
    verify(completion).complete(sender, "argument");
}
Also used : Completion(com.karuslabs.commons.command.completion.Completion) Arguments(com.karuslabs.commons.command.arguments.Arguments) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Arguments

use of com.karuslabs.commons.command.arguments.Arguments in project Karus-Commons by Pante.

the class CommandTest method execute.

@ParameterizedTest
@CsvSource({ "a, 1, 0", "b, 0, 1" })
void execute(String argument, int delegated, int executor) {
    CommandSource source = mock(CommandSource.class);
    Context context = mock(Context.class);
    Arguments arguments = spy(new Arguments(argument, "argument 2"));
    Command subcommand = when(mock(Command.class).getTranslation()).thenReturn(NONE).getMock();
    command.getSubcommands().put("a", subcommand);
    CommandExecutor stub = mock(CommandExecutor.class);
    command.setExecutor(stub);
    command.execute(source, context, arguments);
    verify(source, times(delegated)).setTranslation(NONE);
    verify(context, times(delegated)).update("a", subcommand);
    verify(arguments, times(delegated)).trim();
    verify(subcommand, times(delegated)).execute(source, context, arguments);
    verify(stub, times(executor)).execute(source, context, arguments);
}
Also used : Command(com.karuslabs.commons.command.Command) Arguments(com.karuslabs.commons.command.arguments.Arguments) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Arguments (com.karuslabs.commons.command.arguments.Arguments)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Command (com.karuslabs.commons.command.Command)3 Test (org.junit.jupiter.api.Test)2 Completion (com.karuslabs.commons.command.completion.Completion)1