Add CommandFramework (needs Message System for completion)? #1

Zusammengeführt
Lixfel hat 9 Commits von CommandFramework nach master 2022-05-01 22:42:55 +02:00 zusammengeführt
3 geänderte Dateien mit 63 neuen und 21 gelöschten Zeilen
Nur Änderungen aus Commit 9022c62281 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -0,0 +1,26 @@
package de.steamwar;
import de.steamwar.command.CommandFrameworkException;
import lombok.experimental.UtilityClass;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
@UtilityClass
public class AssertionUtils {
public static void assertCMDFramework(Exception e, Class<?> clazz, String message) {
assertThat(e, is(instanceOf(CommandFrameworkException.class)));
assertThat(e.getCause().getCause(), is(instanceOf(clazz)));
assertThat(e.getCause().getCause().getMessage(), is(message));
}
public static <T> void assertTabCompletes(List<T> list, T... elements) {
assertThat(list.size(), is(elements.length));
if (elements.length > 0) {
assertThat(list, containsInAnyOrder(elements));
}
}
}

Datei anzeigen

@ -3,9 +3,10 @@ package de.steamwar.command;
import de.steamwar.command.dto.ExecutionIdentifier;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import java.util.List;
import static de.steamwar.AssertionUtils.assertCMDFramework;
import static de.steamwar.AssertionUtils.assertTabCompletes;
public class ArgumentCommandTest {
@ -25,8 +26,7 @@ public class ArgumentCommandTest {
try {
cmd.execute("test", "", new String[]{"true", "false"});
} catch (Exception e) {
assertThat(e.getCause().getCause(), is(instanceOf(ExecutionIdentifier.class)));
assertThat(e.getCause().getCause().getMessage(), is("RunArgument with Boolean"));
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Boolean");
}
}
@ -36,8 +36,7 @@ public class ArgumentCommandTest {
try {
cmd.execute("test", "", new String[]{"0.0", "0.0", "0.0"});
} catch (Exception e) {
assertThat(e.getCause().getCause(), is(instanceOf(ExecutionIdentifier.class)));
assertThat(e.getCause().getCause().getMessage(), is("RunArgument with Float"));
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Float");
}
}
@ -47,8 +46,7 @@ public class ArgumentCommandTest {
try {
cmd.execute("test", "", new String[]{"0.0", "0.0"});
} catch (Exception e) {
assertThat(e.getCause().getCause(), is(instanceOf(ExecutionIdentifier.class)));
assertThat(e.getCause().getCause().getMessage(), is("RunArgument with Double"));
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Double");
}
}
@ -58,8 +56,7 @@ public class ArgumentCommandTest {
try {
cmd.execute("test", "", new String[]{"0"});
} catch (Exception e) {
assertThat(e.getCause().getCause(), is(instanceOf(ExecutionIdentifier.class)));
assertThat(e.getCause().getCause().getMessage(), is("RunArgument with Integer"));
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Integer");
}
}
@ -69,8 +66,7 @@ public class ArgumentCommandTest {
try {
cmd.execute("test", "", new String[]{"0", "0"});
} catch (Exception e) {
assertThat(e.getCause().getCause(), is(instanceOf(ExecutionIdentifier.class)));
assertThat(e.getCause().getCause().getMessage(), is("RunArgument with Long"));
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Long");
}
}
@ -80,8 +76,21 @@ public class ArgumentCommandTest {
try {
cmd.execute("test", "", new String[]{"Hello World"});
} catch (Exception e) {
assertThat(e.getCause().getCause(), is(instanceOf(ExecutionIdentifier.class)));
assertThat(e.getCause().getCause().getMessage(), is("RunArgument with String"));
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with String");
}
}
@Test
public void testTabComplete() {
ArgumentCommand cmd = new ArgumentCommand();
List<String> strings = cmd.tabComplete("test", "", new String[]{""});
assertTabCompletes(strings, "true", "false");
}
@Test
public void testPartialTabComplete() {
ArgumentCommand cmd = new ArgumentCommand();
List<String> strings = cmd.tabComplete("test", "", new String[]{"t"});
assertTabCompletes(strings, "true", "t");
}
}

Datei anzeigen

@ -3,9 +3,10 @@ package de.steamwar.command;
import de.steamwar.command.dto.ExecutionIdentifier;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import java.util.List;
import static de.steamwar.AssertionUtils.assertCMDFramework;
import static de.steamwar.AssertionUtils.assertTabCompletes;
public class SimpleCommandTest {
@ -14,9 +15,8 @@ public class SimpleCommandTest {
SimpleCommand cmd = new SimpleCommand();
try {
cmd.execute("test", "", new String[0]);
} catch (CommandFrameworkException e) {
assertThat(e.getCause().getCause(), is(instanceOf(ExecutionIdentifier.class)));
assertThat(e.getCause().getCause().getMessage(), is("RunSimple with noArgs"));
} catch (Exception e) {
assertCMDFramework(e, ExecutionIdentifier.class, "RunSimple with noArgs");
}
}
@ -29,4 +29,11 @@ public class SimpleCommandTest {
throw new AssertionError("No exception expected");
}
}
@Test
public void testSimpleTabComplete() {
SimpleCommand cmd = new SimpleCommand();
List<String> strings = cmd.tabComplete("test", "", new String[]{""});
assertTabCompletes(strings);
}
}