Added static methods to create ArgumentBuilders directly in the BrigadierCommand class (#1161)

This commit is contained in:
Adrian
2023-12-27 13:33:44 -05:00
committed by GitHub
parent 9450e6600c
commit 6fd03d6f5c
2 changed files with 47 additions and 2 deletions

View File

@@ -20,11 +20,13 @@ package com.velocitypowered.proxy.command;
import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger;
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
import static com.mojang.brigadier.arguments.StringArgumentType.word;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.velocitypowered.api.command.BrigadierCommand;
@@ -349,4 +351,14 @@ public class BrigadierCommandTests extends CommandTestSuite {
assertThrows(CompletionException.class, () ->
manager.offerSuggestions(source, "parent ").join());
}
@Test
void testArgumentBuilderCreationUsingStaticFactory() {
assertDoesNotThrow(() -> BrigadierCommand.literalArgumentBuilder("someCommand"));
assertThrows(IllegalArgumentException.class,
() -> BrigadierCommand.literalArgumentBuilder("some random command"));
assertDoesNotThrow(
() -> BrigadierCommand.requiredArgumentBuilder(
"someRequiredArgument", StringArgumentType.word()));
}
}