### Question:
TransitiveTeacherToStaffEdOrgAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STAFF_ED_ORG_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } Map<String, Set<String>> requiredEdOrgsToSEOAs = new HashMap<String, Set<String>>(); { Iterable<Entity> requestedAssociations = repo.findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids))); for (Entity entity : requestedAssociations) { String id = (String) entity.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE); if (!requiredEdOrgsToSEOAs.containsKey(id)) { requiredEdOrgsToSEOAs.put(id, new HashSet<String>()); } requiredEdOrgsToSEOAs.get(id).add(entity.getEntityId()); } } Set<String> teachersEdOrgs = new HashSet<String>(); { NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.STAFF_REFERENCE, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.principalId())); Iterable<Entity> teachersAssociations = this.repo.findAll(EntityNames.STAFF_ED_ORG_ASSOCIATION, query); for (Entity entity : teachersAssociations) { if (!dateHelper.isFieldExpired(entity.getBody(), ParameterConstants.END_DATE)) { teachersEdOrgs.add((String) entity.getBody().get(ParameterConstants.EDUCATION_ORGANIZATION_REFERENCE)); } } } return getValidIds(teachersEdOrgs, requiredEdOrgsToSEOAs); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }### Answer:
@Test public void testCanValidateNonExpiredAssociation() { helper.generateStaffEdorg(helper.STAFF_ID, helper.ED_ORG_ID, false); Entity assoc = helper.generateStaffEdorg("staff2", helper.ED_ORG_ID, false); edOrgAssociationIds.add(assoc.getEntityId()); assertTrue(validator.validate(EntityNames.STAFF_ED_ORG_ASSOCIATION, edOrgAssociationIds).equals(edOrgAssociationIds)); }
@Test public void testInvalidateExpiredAssociation() { helper.generateStaffEdorg(helper.STAFF_ID, helper.ED_ORG_ID, true); Entity assoc = helper.generateStaffEdorg("staff2", helper.ED_ORG_ID, false); edOrgAssociationIds.add(assoc.getEntityId()); assertFalse(validator.validate(EntityNames.STAFF_ED_ORG_ASSOCIATION, edOrgAssociationIds).equals(edOrgAssociationIds)); }