MockCommandSender, inspect the output messages, and assert on success or failure — all without a real player connection.
MockCommandSender
A fake command sender that captures messages and has configurable permissions. Create one viaTestContext.
With permissions
MockCommandSender Methods
| Method | Description |
|---|---|
getMessages() | All messages sent to this sender, in order |
getLastMessage() | Last message sent, or null |
hasReceivedMessage(substring) | Check if any message contains the substring |
clearMessages() | Clear all captured messages |
getPermissions() | Get the set of granted permissions |
hasPermission(perm) | Check for a specific permission |
addPermission(perm) | Grant a permission |
removePermission(perm) | Revoke a permission |
getName() | Display name of the sender |
CommandAssert Methods
| Method | Description |
|---|---|
assertCommandSucceeds(ctx, sender, cmd) | Execute command and assert no exception |
assertCommandFails(ctx, sender, cmd) | Execute command and assert it throws |
assertCommandFailsWithMessage(ctx, sender, cmd, msg) | Assert failure contains expected message |
assertSenderReceivedMessage(sender, substring) | Assert sender got a message containing text |
assertSenderReceivedMessageCount(sender, count) | Assert sender received exactly N messages |
@RequiresPlayer
Annotate a test with@RequiresPlayer to indicate it needs player-like context. This is a marker for tests that exercise command logic requiring a player sender.
Examples
Test a command succeeds
Test a command succeeds
Test a command fails without permission
Test a command fails without permission
Verify output messages
Verify output messages
Test permission management
Test permission management
Executing Commands
Besides usingCommandAssert, you can execute commands directly through the context:
sender receives any output messages that the command sends.
executeCommand() dispatches through the real Hytale command system. If the command is not registered or the sender lacks permission, the behavior matches what would happen in production.Next Steps
- Event Testing — capture and verify events
- Codec Testing — test serialization round-trips
- Filtering & Tags — filter tests by tag