sequence) {
}
/**
- * Finds a node in the tree that contains the given data.
- *
- *
- * It uses a depth-first search to find the node that contains the given data.
+ * Finds a direct child of the given node that contains the given data.
*
+ * @param node the parent node
* @param data the data to find
- * @return the node that contains the data, or null if the data is not found
+ * @return the direct child node that contains the data, or null if not found
*/
- public Node findNode(Node node, T data) {
+ public Node findDirectChild(Node node, T data) {
if (node.getData().equals(data)) {
return node;
}
for (Node child : node.getChildren()) {
- Node found = findNode(child, data);
- if (found != null) {
- return found;
+ if (child.getData().equals(data)) {
+ return child;
}
}
return null;
diff --git a/src/test/java/dev/hugog/minecraft/dev_command/commands/BukkitDevCommandTest.java b/src/test/java/dev/hugog/minecraft/dev_command/commands/BukkitDevCommandTest.java
index b0bdff2..0288a48 100644
--- a/src/test/java/dev/hugog/minecraft/dev_command/commands/BukkitDevCommandTest.java
+++ b/src/test/java/dev/hugog/minecraft/dev_command/commands/BukkitDevCommandTest.java
@@ -1,14 +1,13 @@
package dev.hugog.minecraft.dev_command.commands;
import dev.hugog.minecraft.dev_command.arguments.CommandArgument;
-import dev.hugog.minecraft.dev_command.commands.data.BukkitCommandData;
-import dev.hugog.minecraft.dev_command.exceptions.ArgumentsConfigException;
-import dev.hugog.minecraft.dev_command.exceptions.InvalidArgumentsException;
-import dev.hugog.minecraft.dev_command.exceptions.PermissionConfigException;
import dev.hugog.minecraft.dev_command.arguments.parsers.BooleanArgumentParser;
import dev.hugog.minecraft.dev_command.arguments.parsers.DoubleArgumentParser;
import dev.hugog.minecraft.dev_command.arguments.parsers.IntegerArgumentParser;
import dev.hugog.minecraft.dev_command.arguments.parsers.StringArgumentParser;
+import dev.hugog.minecraft.dev_command.commands.data.BukkitCommandData;
+import dev.hugog.minecraft.dev_command.exceptions.ArgumentsConfigException;
+import dev.hugog.minecraft.dev_command.exceptions.PermissionConfigException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.junit.jupiter.api.BeforeEach;
@@ -21,7 +20,8 @@
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
@@ -390,33 +390,6 @@ public List onTabComplete(String[] args) {
}
- @Test
- @DisplayName("Test getArgumentParser() method with invalid arguments.")
- void parseArgument_Invalid() {
-
- String[] arguments = new String[] {"-78","yes",".22", "-0.44"};
- bukkitDevCommandStub = new BukkitDevCommand(bukkitCommandDataMock, commandSenderMock, arguments) {
- @Override
- public void execute() {
- System.out.println("Command Executed");
- }
- @Override
- public List onTabComplete(String[] args) {
- return List.of();
- }
- };
-
- when(bukkitCommandDataMock.getArguments()).thenReturn(new CommandArgument[]{
- new CommandArgument("integer", "Integer to test", 0, IntegerArgumentParser.class, false),
- new CommandArgument("boolean", "Boolean to test", 1, BooleanArgumentParser.class, false),
- new CommandArgument("integer", "Integer to test", 2, IntegerArgumentParser.class, false)}
- );
-
- assertFalse(bukkitDevCommandStub.hasValidArgs());
- assertThrows(InvalidArgumentsException.class, () -> bukkitDevCommandStub.getArgumentParser(2));
-
- }
-
@Test
@DisplayName("Test for call of argument validation without configuration.")
void argumentsConfigExceptionTest() {