Fix tests and checkstyle

This commit is contained in:
MD 2023-06-07 02:12:37 +01:00
parent 56973926d7
commit 03c7e1298d

View File

@ -4,7 +4,6 @@ import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.FakeServer; import com.earth2me.essentials.FakeServer;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.mockito.InOrder; import org.mockito.InOrder;
import java.util.Arrays; import java.util.Arrays;
@ -40,7 +39,9 @@ class EssentialsCommandNodeTest {
System.out.println(Arrays.toString(ctx.args())); System.out.println(Arrays.toString(ctx.args()));
})); }));
root.literal("bye", bye -> { root.literal("bye", bye -> {
bye.literal("forever just kidding", bye1 -> { bye1.execute(ctx -> { throw new RuntimeException("this shouldn't happen"); }); }); bye.literal("forever just kidding", bye1 -> bye1.execute(ctx -> {
throw new RuntimeException("this shouldn't happen");
}));
bye.literal("forever", bye2 -> bye2.execute(ctx -> ctx.sender().sendMessage(":(("))); bye.literal("forever", bye2 -> bye2.execute(ctx -> ctx.sender().sendMessage(":((")));
bye.execute(ctx -> { bye.execute(ctx -> {
@ -68,24 +69,17 @@ class EssentialsCommandNodeTest {
void testEval() { void testEval() {
final EssentialsCommandNode.Root<CommandSource> rootNode = buildCommonTree(); final EssentialsCommandNode.Root<CommandSource> rootNode = buildCommonTree();
assertThrows(NoChargeException.class, () -> rootNode.run(fakeServer, playerSource, "test", new String[]{""}), "wrongly parsed empty arg"); assertThrows(NotEnoughArgumentsException.class, () -> rootNode.run(fakeServer, playerSource, "test", new String[]{""}), "wrongly parsed empty arg");
assertThrows(NoChargeException.class, () -> rootNode.run(fakeServer, playerSource, "test", new String[]{"wilkommen"}), "wrongly parsed unknown literal"); // wrongly parsed German assertThrows(NotEnoughArgumentsException.class, () -> rootNode.run(fakeServer, playerSource, "test", new String[]{"wilkommen"}), "wrongly parsed unknown literal"); // wrongly parsed German
Executable playerHelloNoArgs = () -> rootNode.run(fakeServer, playerSource, "test", new String[]{"hello"}); assertDoesNotThrow(() -> rootNode.run(fakeServer, playerSource, "test", new String[]{"hello"}), "parsing first level no-arg command");
Executable playerHelloOneArg = () -> rootNode.run(fakeServer, playerSource, "test", new String[]{"hello", "world"}); assertDoesNotThrow(() -> rootNode.run(fakeServer, playerSource, "test", new String[]{"hello", "world"}), "parsing first level 1 arg command");
Executable playerHelloManyArgs = () -> rootNode.run(fakeServer, playerSource, "test", new String[]{"hello", "jroy", "pop", "lax", "evident"}); assertDoesNotThrow(() -> rootNode.run(fakeServer, playerSource, "test", new String[]{"hello", "jroy", "pop", "lax", "evident"}), "parsing first level multi-arg command");
Executable playerBye = () -> rootNode.run(fakeServer, playerSource, "test", new String[]{"bye", "legacy", "code"}); assertDoesNotThrow(() -> rootNode.run(fakeServer, playerSource, "test", new String[]{"bye", "legacy", "code"}));
Executable consoleFarewell = () -> rootNode.run(fakeServer, consoleSource, "test", new String[]{"fAREWELL", "player", "data"}); assertDoesNotThrow(() -> rootNode.run(fakeServer, consoleSource, "test", new String[]{"fAREWELL", "player", "data"}), "parsing with literal alias");
Executable consoleByeForeverJk = () -> rootNode.run(fakeServer, consoleSource, "test", new String[]{"bye", "forever", "just", "kidding"}); assertDoesNotThrow(() -> rootNode.run(fakeServer, consoleSource, "test", new String[]{"bye", "forever", "just", "kidding"}));
assertDoesNotThrow(playerHelloNoArgs, "parsing first level no-arg command"); final InOrder ordered = inOrder(playerSource, consoleSource);
assertDoesNotThrow(playerHelloOneArg, "parsing first level 1 arg command");
assertDoesNotThrow(playerHelloManyArgs, "parsing first level multi-arg command");
assertDoesNotThrow(playerBye);
assertDoesNotThrow(consoleFarewell, "parsing with literal alias");
assertDoesNotThrow(consoleByeForeverJk);
InOrder ordered = inOrder(playerSource, consoleSource);
ordered.verify(playerSource).sendMessage("hello to who?"); ordered.verify(playerSource).sendMessage("hello to who?");
ordered.verify(playerSource).sendMessage("hi there world"); ordered.verify(playerSource).sendMessage("hi there world");
ordered.verify(playerSource).sendMessage("woah hi jroy and pop and lax and evident"); ordered.verify(playerSource).sendMessage("woah hi jroy and pop and lax and evident");