Fix stuff
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Add tests
Dieser Commit ist enthalten in:
yoyosource 2022-06-20 14:06:28 +02:00
Ursprung 6bd95ad84c
Commit 75f88d65ac
4 geänderte Dateien mit 68 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -188,7 +188,7 @@ class CommandPart<T> {
return;
}
Collection<String> strings = typeMapper.tabCompletes(sender, Arrays.copyOf(args, startIndex), args[startIndex]);
Collection<String> strings = tabCompletes(sender, args, startIndex);
if (strings != null) {
current.addAll(strings);
}

Datei anzeigen

@ -313,7 +313,7 @@ public class SWCommandUtils {
}
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);
}
}

Datei anzeigen

@ -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() + "");
}
};
}
}

Datei anzeigen

@ -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))));
}
}