### Question:
AuditAuthorizer implements IAuthorizer { @Override public Set<Permission> authorize(AuthenticatedUser user, IResource resource) { if (resource.hasParent() && resource instanceof RoleResource) { Set<Permission> permissions = EnumSet.copyOf(wrappedAuthorizer.authorize(user, resource)); permissions.add(Permission.ALTER); return permissions; } else { return wrappedAuthorizer.authorize(user, resource); } } AuditAuthorizer(); @VisibleForTesting  AuditAuthorizer(IAuthorizer wrappedAuthorizer); @Override Set<Permission> authorize(AuthenticatedUser user, IResource resource); @Override void grant(AuthenticatedUser performer, Set<Permission> permissions, IResource resource, RoleResource grantee); @Override void revoke(AuthenticatedUser performer, Set<Permission> permissions, IResource resource, RoleResource revokee); @Override Set<PermissionDetails> list(AuthenticatedUser performer, Set<Permission> permissionFilter, IResource resourceFilter, RoleResource roleFilter); @Override void revokeAllFrom(RoleResource revokee); @Override void revokeAllOn(IResource droppedResource); @Override Set<? extends IResource> protectedResources(); @Override void validateConfiguration(); @Override void setup(); IAuthorizer getWrappedAuthorizer();  }### Answer:
@Test public void testNormalAuthorize() { Set<Permission> expectedPermissions = givenAuthorizedPermission(mockAuthorizer, mockResource); Set<Permission> actualPermissions = authorizer.authorize(mockPerformer, mockResource); assertThat(actualPermissions).isEqualTo(expectedPermissions); verify(mockAuthorizer).authorize(eq(mockPerformer), eq(mockResource)); }
@Test public void testDataInstanceAuthorize() { DataResource dataResource = DataResource.fromName("data/ks"); Set<Permission> expectedPermissions = givenAuthorizedPermission(mockAuthorizer, dataResource); Set<Permission> actualPermissions = authorizer.authorize(mockPerformer, dataResource); assertThat(actualPermissions).isEqualTo(expectedPermissions); verify(mockAuthorizer).authorize(eq(mockPerformer), eq(dataResource)); }
@Test public void testTopRoleAuthorize() { RoleResource roleResource = RoleResource.fromName("roles"); Set<Permission> expectedPermissions = givenAuthorizedPermission(mockAuthorizer, roleResource); Set<Permission> actualPermissions = authorizer.authorize(mockPerformer, roleResource); assertThat(actualPermissions).isEqualTo(expectedPermissions); verify(mockAuthorizer).authorize(eq(mockPerformer), eq(roleResource)); }
@Test public void testRoleInstanceAuthorize() { RoleResource roleResource = RoleResource.role("bob"); Set<Permission> expectedPermissions = givenAuthorizedPermission(mockAuthorizer, roleResource); Set<Permission> actualPermissions = authorizer.authorize(mockPerformer, roleResource); assertThat(actualPermissions).containsAll(expectedPermissions); assertThat(actualPermissions).contains(Permission.ALTER); verify(mockAuthorizer).authorize(eq(mockPerformer), eq(roleResource)); }