### Question:
TeacherToStudentCompetencyValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.STUDENT_COMPETENCY, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, ids)); query.setIncludeFields(Arrays.asList(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID)); Iterable<Entity> comps = getRepo().findAll(EntityNames.STUDENT_COMPETENCY, query); Map<String, Set<String>> secAssocIds = new HashMap<String, Set<String>>(); for (Entity comp : comps) { String id = (String) comp.getBody().get(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID); if (!secAssocIds.containsKey(id)) { secAssocIds.put(id, new HashSet<String>()); } secAssocIds.get(id).add(comp.getEntityId()); } Set<String> validSectionIds = sectionAssocValidator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, secAssocIds.keySet()); return getValidIds(validSectionIds, secAssocIds); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }### Answer:
@Test public void testValidComps() { Set<String> ids = new HashSet<String>(Arrays.asList(sComp1.getEntityId())); assertTrue(validator.validate(EntityNames.STUDENT_COMPETENCY, ids).equals(ids)); ids = new HashSet<String>(Arrays.asList(sComp2.getEntityId())); assertTrue(validator.validate(EntityNames.STUDENT_COMPETENCY, ids).equals(ids)); ids = new HashSet<String>(Arrays.asList(sComp1.getEntityId(), sComp2.getEntityId())); assertTrue(validator.validate(EntityNames.STUDENT_COMPETENCY, ids).equals(ids)); }
@Test public void testInvalidComps() { Set<String> ids = new HashSet<String>(Arrays.asList(sComp3.getEntityId())); assertFalse(validator.validate(EntityNames.STUDENT_COMPETENCY, ids).equals(ids)); ids = new HashSet<String>(Arrays.asList(sComp1.getEntityId(), sComp3.getEntityId())); assertFalse(validator.validate(EntityNames.STUDENT_COMPETENCY, ids).equals(ids)); }