More progress on command method parsing

This commit is contained in:
Alexander Söderberg 2020-09-18 14:34:14 +02:00
parent da68a6bc87
commit 1e58ca3f13
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
4 changed files with 153 additions and 30 deletions

View file

@ -24,13 +24,18 @@
package com.intellectualsites.commands.annotations;
import com.google.common.collect.Maps;
import com.intellectualsites.commands.Command;
import com.intellectualsites.commands.CommandManager;
import com.intellectualsites.commands.annotations.specifier.Range;
import com.intellectualsites.commands.meta.SimpleCommandMeta;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.CompletionException;
class AnnotationParserTest {
@ -54,4 +59,20 @@ class AnnotationParserTest {
Assertions.assertEquals(map, arguments);
}
@Test
void testMethodConstruction() {
final Collection<Command<TestCommandSender, SimpleCommandMeta>> commands = annotationParser.parse(this);
Assertions.assertFalse(commands.isEmpty());
manager.executeCommand(new TestCommandSender(), "test 10").join();
Assertions.assertThrows(CompletionException.class, () ->
manager.executeCommand(new TestCommandSender(), "test 101").join());
}
@CommandMethod("test <int> [string]")
public void testCommand(@Nonnull final TestCommandSender sender,
@Argument("int") @Range(max = "100") final int argument,
@Nonnull @Argument(value = "string", defaultValue = "potato") final String string) {
System.out.printf("Received int: %d and string '%s'\n", argument, string);
}
}