@API(status = API.Status.STABLE)
    @SuppressWarnings("unchecked")
    public @NonNull PermissionResult testPermission(
            final @NonNull C sender,
            final @NonNull Permission permission
    ) {
        if (permission instanceof PredicatePermission) {
            return ((PredicatePermission<C>) permission).testPermission(sender);
        } else if (permission instanceof OrPermission) {
            for (final Permission innerPermission : permission.permissions()) {
                final PermissionResult result = this.testPermission(sender, innerPermission);
                if (result.allowed()) {
                    return result; // short circuit the first true result
                }
            }
            return PermissionResult.denied(permission); // none returned true
        } else if (permission instanceof AndPermission) {
            for (final Permission innerPermission : permission.permissions()) {
                final PermissionResult result = this.testPermission(sender, innerPermission);
                if (!result.allowed()) {
                    return result; // short circuit the first false result
                }
            }
            return PermissionResult.allowed(permission); // all returned true
        }
        return PermissionResult.of(permission.isEmpty() || this.hasPermission(sender, permission.permissionString()), permission);
    }
Checks if the command sender has the required permission and returns the result.

@param sender     the command sender
@param permission the permission
@return a {@link PermissionResult} representing whether the sender has the permission
cloud-core/src/main/java/org/incendo/cloud/CommandManager.java