### Question:
EntityRightsFilter { protected void complexFilter(EntityBody entityBody, Collection<GrantedAuthority> auths, String entityType) { if (!auths.contains(Right.READ_RESTRICTED) && (entityType.equals(EntityNames.STAFF) || entityType.equals(EntityNames.TEACHER))) { final String work = "Work"; final String telephoneNumberType = "telephoneNumberType"; final String emailAddressType = "emailAddressType"; final String telephone = "telephone"; final String electronicMail = "electronicMail"; @SuppressWarnings("unchecked") List<Map<String, Object>> telephones = (List<Map<String, Object>>) entityBody.get(telephone); if (telephones != null) { for (Iterator<Map<String, Object>> it = telephones.iterator(); it.hasNext(); ) { if (!work.equals(it.next().get(telephoneNumberType))) { it.remove(); } } } @SuppressWarnings("unchecked") List<Map<String, Object>> emails = (List<Map<String, Object>>) entityBody.get(electronicMail); if (emails != null) { for (Iterator<Map<String, Object>> it = emails.iterator(); it.hasNext(); ) { if (!work.equals(it.next().get(emailAddressType))) { it.remove(); } } } } }  EntityBody makeEntityBody(Entity entity, List<Treatment> treamts, EntityDefinition defn, boolean isSelf,
                                     Collection<GrantedAuthority> nonSelfAuths, SecurityUtil.UserContext context); EntityBody makeEntityBody(Entity entity, List<Treatment> treamts, EntityDefinition defn,
            Collection<GrantedAuthority> nonSelfAuths, Collection<GrantedAuthority> selfAuths); EntityBody exposeTreatments(Entity entity, List<Treatment> treatments, EntityDefinition defn); void setRightAccessValidator(RightAccessValidator rightAccessValidator);  }### Answer:
@Test public void testComplexFilterReadGeneral() { Collection<GrantedAuthority> auths = new HashSet<GrantedAuthority>(); auths.add(Right.READ_GENERAL); Entity staff = createStaffEntity(EntityNames.STAFF, STAFF_ID); EntityBody sb = new EntityBody(staff.getBody()); entityRightsFilter.complexFilter(sb, auths, EntityNames.STAFF); List<Map<String, Object>> telepone = (List<Map<String, Object>>) sb.get(TELEPONE_FEILD); List<Map<String, Object>> emails = (List<Map<String, Object>>) sb.get(EMAIL_FIELD); Assert.assertEquals(1, telepone.size()); Assert.assertEquals(1, emails.size()); Assert.assertEquals(WORK_PHONE, telepone.get(0).get(TELEPONE_VALUE)); Assert.assertEquals(WORK_EMAIL, emails.get(0).get(EMAIL_VALUE)); }
@Test public void testComplexFilterReadRestrict() { Collection<GrantedAuthority> auths = new HashSet<GrantedAuthority>(); auths.add(Right.READ_RESTRICTED); Entity staff = createStaffEntity(EntityNames.STAFF, STAFF_ID); EntityBody sb = new EntityBody(staff.getBody()); entityRightsFilter.complexFilter(sb, auths, EntityNames.STAFF); List<Map<String, Object>> telepone = (List<Map<String, Object>>) sb.get(TELEPONE_FEILD); List<Map<String, Object>> emails = (List<Map<String, Object>>) sb.get(EMAIL_FIELD); Assert.assertEquals(2, telepone.size()); Assert.assertEquals(2, emails.size()); }