Fix tests and checkstyle

This commit is contained in:
MD 2023-06-07 02:12:37 +01:00
parent 56973926d7
commit 03c7e1298d
1 changed files with 13 additions and 19 deletions

View File

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