From 03c7e1298dbb29f86d1e19d08ba7de072eda3c3f Mon Sep 17 00:00:00 2001 From: MD <1917406+mdcfe@users.noreply.github.com> Date: Wed, 7 Jun 2023 02:12:37 +0100 Subject: [PATCH] Fix tests and checkstyle --- .../commands/EssentialsCommandNodeTest.java | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/Essentials/src/test/java/com/earth2me/essentials/commands/EssentialsCommandNodeTest.java b/Essentials/src/test/java/com/earth2me/essentials/commands/EssentialsCommandNodeTest.java index 38d01ae52..b5c68e6f5 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/commands/EssentialsCommandNodeTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/commands/EssentialsCommandNodeTest.java @@ -4,7 +4,6 @@ import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.FakeServer; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.Executable; import org.mockito.InOrder; import java.util.Arrays; @@ -40,7 +39,9 @@ class EssentialsCommandNodeTest { System.out.println(Arrays.toString(ctx.args())); })); 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.execute(ctx -> { @@ -68,28 +69,21 @@ class EssentialsCommandNodeTest { void testEval() { final EssentialsCommandNode.Root rootNode = buildCommonTree(); - assertThrows(NoChargeException.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[]{""}), "wrongly parsed empty arg"); + 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"}); - Executable playerHelloOneArg = () -> rootNode.run(fakeServer, playerSource, "test", new String[]{"hello", "world"}); - Executable playerHelloManyArgs = () -> rootNode.run(fakeServer, playerSource, "test", new String[]{"hello", "jroy", "pop", "lax", "evident"}); - Executable playerBye = () -> rootNode.run(fakeServer, playerSource, "test", new String[]{"bye", "legacy", "code"}); - Executable consoleFarewell = () -> rootNode.run(fakeServer, consoleSource, "test", new String[]{"fAREWELL", "player", "data"}); - Executable consoleByeForeverJk = () -> rootNode.run(fakeServer, consoleSource, "test", new String[]{"bye", "forever", "just", "kidding"}); + assertDoesNotThrow(() -> rootNode.run(fakeServer, playerSource, "test", new String[]{"hello"}), "parsing first level no-arg command"); + assertDoesNotThrow(() -> rootNode.run(fakeServer, playerSource, "test", new String[]{"hello", "world"}), "parsing first level 1 arg command"); + assertDoesNotThrow(() -> rootNode.run(fakeServer, playerSource, "test", new String[]{"hello", "jroy", "pop", "lax", "evident"}), "parsing first level multi-arg command"); + assertDoesNotThrow(() -> rootNode.run(fakeServer, playerSource, "test", new String[]{"bye", "legacy", "code"})); + assertDoesNotThrow(() -> rootNode.run(fakeServer, consoleSource, "test", new String[]{"fAREWELL", "player", "data"}), "parsing with literal alias"); + assertDoesNotThrow(() -> rootNode.run(fakeServer, consoleSource, "test", new String[]{"bye", "forever", "just", "kidding"})); - assertDoesNotThrow(playerHelloNoArgs, "parsing first level no-arg command"); - 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); + final InOrder ordered = inOrder(playerSource, consoleSource); ordered.verify(playerSource).sendMessage("hello to who?"); ordered.verify(playerSource).sendMessage("hi there world"); ordered.verify(playerSource).sendMessage("woah hi jroy and pop and lax and evident"); ordered.verify(consoleSource).sendMessage("wait you can't leave"); ordered.verify(consoleSource).sendMessage(":(("); } -} \ No newline at end of file +}