Package dev.jorel.commandapi
Class CommandAPITestUtilities
java.lang.Object
dev.jorel.commandapi.CommandAPITestUtilities
Provides static methods to interact with CommandAPI commands registered in the test environment. This includes
verifying that a command runs successfully, fails with a certain error message, runs with certain arguments, or
suggests strings or tooltips.
Tip: The standard way to access static methods is by using the class name (e.g.
CommandAPITestUtilities.assertCommandSucceeds(...)). However, you can also call these methods with just the
method name (assertCommandSucceeds(...)), if you add a static import
(import static dev.jorel.commandapi.CommandAPITestUtilities.assertCommandSucceeds;) or make your test class
extend this class (class Tests extends CommandAPITestUtilities {...}).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.mojang.brigadier.exceptions.CommandSyntaxExceptionassertCommandFails(org.bukkit.command.CommandSender sender, String command, String expectedMessage) Runs a CommandAPI command as asserts that it fails.static voidassertCommandFailsWithArguments(org.bukkit.command.CommandSender sender, String command, String expectedFailureMessage, Object... argumentsArray) Asserts that the given array of argument objects was available when a command executed and threw an exception.static voidassertCommandFailsWithArguments(org.bukkit.command.CommandSender sender, String command, String expectedFailureMessage, Map<String, Object> argumentsMap) Asserts that the given map of argument objects was available when a command executed successfully.static voidassertCommandSucceeds(org.bukkit.command.CommandSender sender, String command) Runs a CommandAPI command and asserts that it succeeds.static voidassertCommandSucceedsWithArguments(org.bukkit.command.CommandSender sender, String command, Object... argumentsArray) Asserts that the given array of argument objects was available when a command executed successfully.static voidassertCommandSucceedsWithArguments(org.bukkit.command.CommandSender sender, String command, Map<String, Object> argumentsMap) Asserts that the given map of argument objects was available when a command executed successfully.static voidassertCommandSuggests(org.bukkit.command.CommandSender sender, String command, int startingAt, String... expectedSuggestions) Asserts that the suggestions provided for the given command start at the given index and have the given texts.static voidassertCommandSuggests(org.bukkit.command.CommandSender sender, String command, int startingAt, List<String> expectedSuggestions) Asserts that the suggestions provided for the given command start at the given index and have the given texts.static voidassertCommandSuggests(org.bukkit.command.CommandSender sender, String command, String... expectedSuggestions) Asserts that the suggestions provided for the given command have the given texts.static voidassertCommandSuggests(org.bukkit.command.CommandSender sender, String command, List<String> expectedSuggestions) Asserts that the suggestions provided for the given command have the given texts.static voidassertCommandSuggestsTooltips(org.bukkit.command.CommandSender sender, String command, int startingAt, com.mojang.brigadier.suggestion.Suggestion... expectedSuggestions) Asserts that the suggestions provided for the given command start at the given index and have the given texts and tooltips.static voidassertCommandSuggestsTooltips(org.bukkit.command.CommandSender sender, String command, int startingAt, List<com.mojang.brigadier.suggestion.Suggestion> expectedSuggestions) Asserts that the suggestions provided for the given command start at the given index and have the given texts and tooltips.static voidassertCommandSuggestsTooltips(org.bukkit.command.CommandSender sender, String command, com.mojang.brigadier.suggestion.Suggestion... expectedSuggestions) Asserts that the suggestions provided for the given command have the given texts and tooltips.static voidassertCommandSuggestsTooltips(org.bukkit.command.CommandSender sender, String command, List<com.mojang.brigadier.suggestion.Suggestion> expectedSuggestions) Asserts that the suggestions provided for the given command have the given texts and tooltips.static voidassertSuggestionEquality(List<String> expectedSuggestions, List<com.mojang.brigadier.suggestion.Suggestion> actualSuggestions) static voidassertSuggestionEqualityTooltips(List<com.mojang.brigadier.suggestion.Suggestion> expectedSuggestions, List<com.mojang.brigadier.suggestion.Suggestion> actualSuggestions) Asserts that theSuggestion.getText()andSuggestion.getTooltip()of each givenSuggestionmatches an expectedSuggestion.static voidassertSuggestionsStartAt(int startingAt, List<com.mojang.brigadier.suggestion.Suggestion> suggestions) Asserts that allSuggestions in the given list start at the given index.static voiddispatchCommand(org.bukkit.command.CommandSender sender, String command) Attempts to run a CommandAPI command.static ExecutionInfo<org.bukkit.command.CommandSender, AbstractCommandSender<? extends org.bukkit.command.CommandSender>> getExecutionInfoOfFailingCommand(org.bukkit.command.CommandSender sender, String command, String expectedFailureMessage) Returns theExecutionInfoused when a CommandAPI command was executed and threw an exception.static ExecutionInfo<org.bukkit.command.CommandSender, AbstractCommandSender<? extends org.bukkit.command.CommandSender>> getExecutionInfoOfSuccessfulCommand(org.bukkit.command.CommandSender sender, String command) Returns theExecutionInfoused when a CommandAPI command was executed successfully.static MockCommandAPIstatic com.mojang.brigadier.suggestion.SuggestionsgetSuggestions(org.bukkit.command.CommandSender sender, String command) Returns the BrigadierSuggestionsprovided for the given command.static com.mojang.brigadier.suggestion.SuggestionmakeTooltip(String text, String tooltip) Creates aSuggestionwith the givenStrings as its text and tooltip.
-
Constructor Details
-
CommandAPITestUtilities
public CommandAPITestUtilities()
-
-
Method Details
-
getMockCommandAPI
- Returns:
- The
MockCommandAPIclass currently loaded.
-
dispatchCommand
public static void dispatchCommand(org.bukkit.command.CommandSender sender, String command) throws com.mojang.brigadier.exceptions.CommandSyntaxException Attempts to run a CommandAPI command.- Parameters:
sender- TheCommandSenderrunning the command.command- The command to execute.- Throws:
com.mojang.brigadier.exceptions.CommandSyntaxException- If the command fails for any reason.- See Also:
-
assertCommandSucceeds
Runs a CommandAPI command and asserts that it succeeds.- Parameters:
sender- TheCommandSenderrunning the command.command- The command to execute.- Throws:
org.opentest4j.AssertionFailedError- If dispatching the command fails for any reason.- See Also:
-
assertCommandFails
@CanIgnoreReturnValue public static com.mojang.brigadier.exceptions.CommandSyntaxException assertCommandFails(org.bukkit.command.CommandSender sender, String command, String expectedMessage) Runs a CommandAPI command as asserts that it fails.- Parameters:
sender- TheCommandSenderrunning the command.command- The command to execute.expectedMessage- The expected message thrown when the command fails.- Returns:
- The
CommandSyntaxExceptionthat resulted when the command failed. This can be ignored if no further checks are necessary. - Throws:
org.opentest4j.AssertionFailedError- If dispatching the command does not fail, or it fails with a different message than expected.- See Also:
-
getExecutionInfoOfSuccessfulCommand
public static ExecutionInfo<org.bukkit.command.CommandSender,AbstractCommandSender<? extends org.bukkit.command.CommandSender>> getExecutionInfoOfSuccessfulCommand(org.bukkit.command.CommandSender sender, String command) Returns theExecutionInfoused when a CommandAPI command was executed successfully.- Parameters:
sender- TheCommandSenderrunning the command.command- The command to execute.- Returns:
- The
ExecutionInfoused when the command was executed. - Throws:
org.opentest4j.AssertionFailedError- If the command does not succeed or a CommandAPI executor is not invoked.- See Also:
-
assertCommandSucceedsWithArguments
public static void assertCommandSucceedsWithArguments(org.bukkit.command.CommandSender sender, String command, Object... argumentsArray) Asserts that the given array of argument objects was available when a command executed successfully.- Parameters:
sender- TheCommandSenderrunning the command.command- The command to execute.argumentsArray- TheCommandArguments.args()that is expected when the command executes.- Throws:
org.opentest4j.AssertionFailedError- If the command does not succeed or the available arguments array is different from expected.- See Also:
-
assertCommandSucceedsWithArguments
public static void assertCommandSucceedsWithArguments(org.bukkit.command.CommandSender sender, String command, Map<String, Object> argumentsMap) Asserts that the given map of argument objects was available when a command executed successfully.- Parameters:
sender- TheCommandSenderrunning the command.command- The command to execute.argumentsMap- TheCommandArguments.argsMap()that is expected when the command executes.- Throws:
org.opentest4j.AssertionFailedError- If the command does not succeed or the available arguments map is different from expected.- See Also:
-
getExecutionInfoOfFailingCommand
public static ExecutionInfo<org.bukkit.command.CommandSender,AbstractCommandSender<? extends org.bukkit.command.CommandSender>> getExecutionInfoOfFailingCommand(org.bukkit.command.CommandSender sender, String command, String expectedFailureMessage) Returns theExecutionInfoused when a CommandAPI command was executed and threw an exception. Note that if the command dispatch fails because the input was not parsed properly, then a CommandAPI executor will not be invoked, and this assertion will fail.- Parameters:
sender- TheCommandSenderrunning the command.command- The command to execute.expectedFailureMessage- The expected message thrown when the command fails.- Returns:
- The
ExecutionInfoused when the command was executed. - Throws:
org.opentest4j.AssertionFailedError- If dispatching the command does not fail, it fails with a different message than expected, or a CommandAPI executor is not invoked.- See Also:
-
assertCommandFailsWithArguments
public static void assertCommandFailsWithArguments(org.bukkit.command.CommandSender sender, String command, String expectedFailureMessage, Object... argumentsArray) Asserts that the given array of argument objects was available when a command executed and threw an exception. Note that if the command dispatch fails because the input was not parsed properly, then a CommandAPI executor will not be invoked, and this assertion will fail.- Parameters:
sender- TheCommandSenderrunning the command.command- The command to execute.expectedFailureMessage- The expected message thrown when the command fails.argumentsArray- TheCommandArguments.args()that is expected when the command executes.- Throws:
org.opentest4j.AssertionFailedError- If the command does not fail or the available arguments array is different from expected.- See Also:
-
assertCommandFailsWithArguments
public static void assertCommandFailsWithArguments(org.bukkit.command.CommandSender sender, String command, String expectedFailureMessage, Map<String, Object> argumentsMap) Asserts that the given map of argument objects was available when a command executed successfully.- Parameters:
sender- TheCommandSenderrunning the command.command- The command to execute.expectedFailureMessage- The expected message thrown when the command fails.argumentsMap- TheCommandArguments.argsMap()that is expected when the command executes.- Throws:
org.opentest4j.AssertionFailedError- If the command does not fail or the available arguments map is different from expected.- See Also:
-
getSuggestions
public static com.mojang.brigadier.suggestion.Suggestions getSuggestions(org.bukkit.command.CommandSender sender, String command) Returns the BrigadierSuggestionsprovided for the given command.- Parameters:
sender- TheCommandSenderrequesting suggestions.command- The command to complete.- Returns:
- The
Suggestionsprovided for this command. - See Also:
-
assertSuggestionsStartAt
public static void assertSuggestionsStartAt(int startingAt, List<com.mojang.brigadier.suggestion.Suggestion> suggestions) Asserts that allSuggestions in the given list start at the given index.- Parameters:
startingAt- The index that the suggestions should start at.suggestions- AListofSuggestions to check.- Throws:
org.opentest4j.AssertionFailedError- If any of the givenSuggestions do not start at the given index.- See Also:
-
assertSuggestionEquality
-
assertSuggestionEqualityTooltips
public static void assertSuggestionEqualityTooltips(List<com.mojang.brigadier.suggestion.Suggestion> expectedSuggestions, List<com.mojang.brigadier.suggestion.Suggestion> actualSuggestions) Asserts that theSuggestion.getText()andSuggestion.getTooltip()of each givenSuggestionmatches an expectedSuggestion. -
assertCommandSuggests
public static void assertCommandSuggests(org.bukkit.command.CommandSender sender, String command, String... expectedSuggestions) Asserts that the suggestions provided for the given command have the given texts.- Parameters:
sender- TheCommandSenderrequesting suggestions.command- The command to complete.expectedSuggestions- The suggestion texts that are expected.- Throws:
org.opentest4j.AssertionFailedError- If any of the actual suggestions do not have the expected text.- See Also:
-
assertCommandSuggests
public static void assertCommandSuggests(org.bukkit.command.CommandSender sender, String command, int startingAt, String... expectedSuggestions) Asserts that the suggestions provided for the given command start at the given index and have the given texts.- Parameters:
sender- TheCommandSenderrequesting suggestions.command- The command to complete.startingAt- The location in the command where the suggestions are expected.expectedSuggestions- The suggestion texts that are expected.- Throws:
org.opentest4j.AssertionFailedError- If any of the actual suggestions do not start or the given index or have the expected text.- See Also:
-
assertCommandSuggests
public static void assertCommandSuggests(org.bukkit.command.CommandSender sender, String command, List<String> expectedSuggestions) Asserts that the suggestions provided for the given command have the given texts.- Parameters:
sender- TheCommandSenderrequesting suggestions.command- The command to complete.expectedSuggestions- The suggestion texts that are expected.- Throws:
org.opentest4j.AssertionFailedError- If any of the actual suggestions do not have the expected text.- See Also:
-
assertCommandSuggests
public static void assertCommandSuggests(org.bukkit.command.CommandSender sender, String command, int startingAt, List<String> expectedSuggestions) Asserts that the suggestions provided for the given command start at the given index and have the given texts.- Parameters:
sender- TheCommandSenderrequesting suggestions.command- The command to complete.startingAt- The location in the command where the suggestions are expected.expectedSuggestions- The suggestion texts that are expected.- Throws:
org.opentest4j.AssertionFailedError- If any of the actual suggestions do not start or the given index or have the expected text.- See Also:
-
makeTooltip
Creates aSuggestionwith the givenStrings as its text and tooltip. -
assertCommandSuggestsTooltips
public static void assertCommandSuggestsTooltips(org.bukkit.command.CommandSender sender, String command, com.mojang.brigadier.suggestion.Suggestion... expectedSuggestions) Asserts that the suggestions provided for the given command have the given texts and tooltips.- Parameters:
sender- TheCommandSenderrequesting suggestions.command- The command to complete.expectedSuggestions- The suggestions that are expected.- Throws:
org.opentest4j.AssertionFailedError- If any of the actual suggestions do not have the expected text or tooltip.- See Also:
-
assertCommandSuggestsTooltips
public static void assertCommandSuggestsTooltips(org.bukkit.command.CommandSender sender, String command, int startingAt, com.mojang.brigadier.suggestion.Suggestion... expectedSuggestions) Asserts that the suggestions provided for the given command start at the given index and have the given texts and tooltips.- Parameters:
sender- TheCommandSenderrequesting suggestions.command- The command to complete.startingAt- The location in the command where the suggestions are expected.expectedSuggestions- The suggestions that are expected.- Throws:
org.opentest4j.AssertionFailedError- If any of the actual suggestions do not start or the given index or have the expected text or tooltip.- See Also:
-
assertCommandSuggestsTooltips
public static void assertCommandSuggestsTooltips(org.bukkit.command.CommandSender sender, String command, List<com.mojang.brigadier.suggestion.Suggestion> expectedSuggestions) Asserts that the suggestions provided for the given command have the given texts and tooltips.- Parameters:
sender- TheCommandSenderrequesting suggestions.command- The command to complete.expectedSuggestions- The suggestions that are expected.- Throws:
org.opentest4j.AssertionFailedError- If any of the actual suggestions do not have the expected text or tooltip.- See Also:
-
assertCommandSuggestsTooltips
public static void assertCommandSuggestsTooltips(org.bukkit.command.CommandSender sender, String command, int startingAt, List<com.mojang.brigadier.suggestion.Suggestion> expectedSuggestions) Asserts that the suggestions provided for the given command start at the given index and have the given texts and tooltips.- Parameters:
sender- TheCommandSenderrequesting suggestions.command- The command to complete.startingAt- The location in the command where the suggestions are expected.expectedSuggestions- The suggestions that are expected.- Throws:
org.opentest4j.AssertionFailedError- If any of the actual suggestions do not start or the given index or have the expected text or tooltip.- See Also:
-