use of com.karuslabs.commons.command.Command 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);
}
use of com.karuslabs.commons.command.Command 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));
}
use of com.karuslabs.commons.command.Command 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);
}
Aggregations