1
0
mirror of https://github.com/AuthMe/AuthMeReloaded.git synced 2025-03-28 22:35:58 +01:00

Fix nullpointer when command requires no permissions

- Add test to verify connections among the command initialization
This commit is contained in:
ljacqu 2015-11-29 12:04:01 +01:00
parent 7c652feac2
commit d7513ecc7b
2 changed files with 29 additions and 4 deletions
src
main/java/fr/xephi/authme/command
test/java/fr/xephi/authme/command

View File

@ -108,12 +108,15 @@ public class FoundCommandResult {
* @return True if the command sender has permission, false otherwise.
*/
public boolean hasPermission(CommandSender sender) {
// Make sure the command description is valid
if (this.commandDescription == null)
if (commandDescription == null) {
return false;
} else if (commandDescription.getCommandPermissions() == null) {
return true;
}
// Get and return the permission
return this.commandDescription.getCommandPermissions().hasPermission(sender);
// TODO: Move permissions check to the permission package; command package should not define permission-checking
// API
return commandDescription.getCommandPermissions().hasPermission(sender);
}
/**

View File

@ -65,6 +65,28 @@ public class CommandManagerTest {
walkThroughCommands(manager.getCommandDescriptions(), descriptionTester);
}
/** Ensure that all children of a command stored the parent. */
@Test
public void shouldHaveConnectionBetweenParentAndChild() {
// given
BiConsumer connectionTester = new BiConsumer() {
@Override
public void accept(CommandDescription command, int depth) {
if (command.hasChildren()) {
for (CommandDescription child : command.getChildren()) {
assertThat(command.equals(child.getParent()), equalTo(true));
}
}
// Checking that the parent has the current command as child is redundant as this is how we can traverse
// the "command tree" in the first place - if we're here, it's that the parent definitely has the
// command as child.
}
};
// when/then
walkThroughCommands(manager.getCommandDescriptions(), connectionTester);
}
@Test
public void shouldNotDefineSameLabelTwice() {
// given