### Question:
UserGroupPermissionEvaluator extends
    PersistentObjectPermissionEvaluator<E> { @Override public boolean hasPermission(User user, E userGroup, Permission permission) { if (user != null && permission.equals(Permission.READ) && userGroup.getMembers().contains(user)) { logger.trace("Granting READ access on group where the user is member."); return true; } return super.hasPermission(user, userGroup, permission); } @SuppressWarnings("unchecked")  UserGroupPermissionEvaluator(); protected  UserGroupPermissionEvaluator(Class<E> entityClass); @Override boolean hasPermission(User user, E userGroup, Permission permission);  }### Answer:
@Test public void hasPermission_shouldAlwaysGrantReadOnGroupsWhereUserIsMember() throws NoSuchFieldException, IllegalAccessException { Permission readPermission = Permission.READ; final User user = new User("First name", "Last Name", "accountName"); IdHelper.setIdOnPersistentObject(user, 42); UserGroup userGroup = new UserGroup(); IdHelper.setIdOnPersistentObject(user, 17); userGroup.getMembers().add(user); boolean permissionResult = persistentObjectPermissionEvaluator.hasPermission(user, userGroup, readPermission); assertThat(permissionResult, equalTo(true)); }
@Test public void hasPermission_shouldNeverGrantAdminDeleteOrWriteOnOwnUserObject() throws NoSuchFieldException, IllegalAccessException { final User user = new User("First name", "Last Name", "accountName"); IdHelper.setIdOnPersistentObject(user, 42); UserGroup userGroup = new UserGroup(); IdHelper.setIdOnPersistentObject(user, 17); userGroup.getMembers().add(user); Set<Permission> permissions = new HashSet<Permission>(Arrays.asList(Permission.values())); permissions.remove(Permission.READ); for (Permission permission : permissions) { boolean permissionResult = persistentObjectPermissionEvaluator.hasPermission(user, userGroup, permission); assertThat(permissionResult, equalTo(false)); } }