Add tests
Dieser Commit ist enthalten in:
Ursprung
6bd95ad84c
Commit
75f88d65ac
@ -188,7 +188,7 @@ class CommandPart<T> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Collection<String> strings = typeMapper.tabCompletes(sender, Arrays.copyOf(args, startIndex), args[startIndex]);
|
Collection<String> strings = tabCompletes(sender, args, startIndex);
|
||||||
if (strings != null) {
|
if (strings != null) {
|
||||||
current.addAll(strings);
|
current.addAll(strings);
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@ public class SWCommandUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static <T extends Annotation> T[] getAnnotation(Method method, Class<T> annotation) {
|
static <T extends Annotation> T[] getAnnotation(Method method, Class<T> annotation) {
|
||||||
if (method.getAnnotations().length != 1) return null;
|
if (method.getAnnotations().length == 0) return null;
|
||||||
return method.getDeclaredAnnotationsByType(annotation);
|
return method.getDeclaredAnnotationsByType(annotation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
38
testsrc/de/steamwar/command/CacheCommand.java
Normale Datei
38
testsrc/de/steamwar/command/CacheCommand.java
Normale Datei
@ -0,0 +1,38 @@
|
|||||||
|
package de.steamwar.command;
|
||||||
|
|
||||||
|
import de.steamwar.command.dto.TestSWCommand;
|
||||||
|
import de.steamwar.command.dto.TestTypeMapper;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
public class CacheCommand extends TestSWCommand {
|
||||||
|
|
||||||
|
public CacheCommand() {
|
||||||
|
super("typemapper");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register
|
||||||
|
public void test(String sender, int tabCompleteTest) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private AtomicInteger count = new AtomicInteger();
|
||||||
|
|
||||||
|
@Cached
|
||||||
|
@Mapper(value = "int", local = true)
|
||||||
|
public AbstractTypeMapper<String, Integer> typeMapper() {
|
||||||
|
System.out.println("TypeMapper register");
|
||||||
|
return new TestTypeMapper<Integer>() {
|
||||||
|
@Override
|
||||||
|
public Integer map(String sender, String[] previousArguments, String s) {
|
||||||
|
return Integer.parseInt(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<String> tabCompletes(String sender, String[] previousArguments, String s) {
|
||||||
|
return Arrays.asList(count.getAndIncrement() + "");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
28
testsrc/de/steamwar/command/CacheCommandTest.java
Normale Datei
28
testsrc/de/steamwar/command/CacheCommandTest.java
Normale Datei
@ -0,0 +1,28 @@
|
|||||||
|
package de.steamwar.command;
|
||||||
|
|
||||||
|
import org.hamcrest.Matchers;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
|
public class CacheCommandTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCaching() {
|
||||||
|
CacheCommand cmd = new CacheCommand();
|
||||||
|
List<String> tabCompletions1 = cmd.tabComplete("test", "", new String[]{""});
|
||||||
|
List<String> tabCompletions2 = cmd.tabComplete("test", "", new String[]{""});
|
||||||
|
assertThat(tabCompletions1, is(equalTo(tabCompletions2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCachingWithDifferentSenders() {
|
||||||
|
CacheCommand cmd = new CacheCommand();
|
||||||
|
List<String> tabCompletions1 = cmd.tabComplete("test", "", new String[]{""});
|
||||||
|
List<String> tabCompletions2 = cmd.tabComplete("test2", "", new String[]{""});
|
||||||
|
assertThat(tabCompletions1, is(not(equalTo(tabCompletions2))));
|
||||||
|
}
|
||||||
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren