use of org.spongepowered.api.command.dispatcher.SimpleDispatcher in project SpongeAPI by SpongePowered.
the class ChildCommandsTest method testSimpleChildCommandIsThrownOnErrorWhenSelected.
@Test
public void testSimpleChildCommandIsThrownOnErrorWhenSelected() throws CommandException {
final AtomicBoolean parentExecuted = new AtomicBoolean();
final AtomicBoolean childExecuted = new AtomicBoolean();
final CommandSpec spec = CommandSpec.builder().children(ImmutableMap.of(ImmutableList.of("child"), CommandSpec.builder().arguments(GenericArguments.literal(Text.of("test"), "test")).executor((src, args) -> {
childExecuted.set(true);
return CommandResult.builder().successCount(1).build();
}).build())).arguments(GenericArguments.literal(Text.of("t"), "child")).executor((src, args) -> {
parentExecuted.set(true);
return CommandResult.success();
}).childArgumentParseExceptionFallback(false).build();
final SimpleDispatcher execute = new SimpleDispatcher();
execute.register(spec, "parent");
try {
execute.process(mock(CommandSource.class), "parent child");
} catch (ArgumentParseException ex) {
// ignored - we check this with the booleans
}
assertFalse(childExecuted.get());
assertFalse(parentExecuted.get());
}
use of org.spongepowered.api.command.dispatcher.SimpleDispatcher in project SpongeAPI by SpongePowered.
the class ChildCommandsTest method testEmptyChildrenWorks.
@Test
public void testEmptyChildrenWorks() throws CommandException {
final AtomicBoolean parent = new AtomicBoolean();
final CommandSpec spec = CommandSpec.builder().children(ImmutableMap.<List<String>, CommandSpec>of()).executor((s, c) -> {
parent.set(true);
return CommandResult.success();
}).build();
final SimpleDispatcher execute = new SimpleDispatcher();
execute.register(spec, "emptyparent");
execute.process(mock(CommandSource.class), "emptyparent");
assertTrue(parent.get());
}
use of org.spongepowered.api.command.dispatcher.SimpleDispatcher in project SpongeAPI by SpongePowered.
the class CommandSpecTest method testNoArgsFunctional.
@Test
public void testNoArgsFunctional() throws CommandException, NoSuchFieldException, IllegalAccessException {
CommandManager cm = mock(CommandManager.class);
TestHooks.setInstance("commandManager", cm);
CommandSpec cmd = CommandSpec.builder().executor((src, args) -> CommandResult.empty()).build();
final SimpleDispatcher dispatcher = new SimpleDispatcher();
dispatcher.register(cmd, "cmd");
dispatcher.process(Mockito.mock(CommandSource.class), "cmd");
}
use of org.spongepowered.api.command.dispatcher.SimpleDispatcher in project SpongeAPI by SpongePowered.
the class ChildCommandsTest method testSimpleChildCommand.
@Test
public void testSimpleChildCommand() throws CommandException {
final AtomicBoolean childExecuted = new AtomicBoolean();
final CommandSpec spec = CommandSpec.builder().children(ImmutableMap.of(ImmutableList.of("child"), CommandSpec.builder().executor((src, args) -> {
childExecuted.set(true);
return CommandResult.builder().successCount(1).build();
}).build())).build();
final SimpleDispatcher execute = new SimpleDispatcher();
execute.register(spec, "parent");
execute.process(mock(CommandSource.class), "parent child");
assertTrue(childExecuted.get());
}
use of org.spongepowered.api.command.dispatcher.SimpleDispatcher in project SpongeAPI by SpongePowered.
the class ChildCommandsTest method testEmptyChildrenWorksWithOptionalArgument.
@Test
public void testEmptyChildrenWorksWithOptionalArgument() throws CommandException {
final AtomicBoolean parent = new AtomicBoolean();
final CommandSpec spec = CommandSpec.builder().arguments(GenericArguments.optional(GenericArguments.string(Text.of("b")))).children(ImmutableMap.<List<String>, CommandSpec>builder().put(Lists.newArrayList("aaa"), CommandSpec.builder().executor((s, c) -> CommandResult.empty()).build()).build()).executor((s, c) -> {
parent.set(true);
return CommandResult.success();
}).build();
final SimpleDispatcher execute = new SimpleDispatcher();
execute.register(spec, "emptyparentwithopt");
execute.process(mock(CommandSource.class), "emptyparentwithopt");
assertTrue(parent.get());
}
Aggregations