### Question:
TeacherToGradeValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.GRADE, 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> grades = getRepo().findAll(EntityNames.GRADE, query); Map<String, Set<String>> secAssocIdsToGrade = new HashMap<String, Set<String>>(); for(Entity grade : grades) { String id = (String) grade.getBody().get(ParameterConstants.STUDENT_SECTION_ASSOCIATION_ID); if (!secAssocIdsToGrade.containsKey(id)) { secAssocIdsToGrade.put(id, new HashSet<String>()); } secAssocIdsToGrade.get(id).add(grade.getEntityId()); } Set<String> validSecAssocIds = sectionAssocValidator.validate(EntityNames.STUDENT_SECTION_ASSOCIATION, secAssocIdsToGrade.keySet()); return getValidIds(validSecAssocIds, secAssocIdsToGrade); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }### Answer:
@Test public void testValidGrades() { Set<String> ids = new HashSet<String>(Arrays.asList(grade1.getEntityId())); assertTrue(validator.validate(EntityNames.GRADE, ids).equals(ids)); ids = new HashSet<String>(Arrays.asList(grade2.getEntityId())); assertTrue(validator.validate(EntityNames.GRADE, ids).equals(ids)); ids = new HashSet<String>(Arrays.asList(grade1.getEntityId(), grade2.getEntityId())); assertTrue(validator.validate(EntityNames.GRADE, ids).equals(ids)); }
@Test public void testInvalidGrades() { Set<String> ids = new HashSet<String>(Arrays.asList(grade3.getEntityId())); assertFalse(validator.validate(EntityNames.GRADE, ids).equals(ids)); ids = new HashSet<String>(Arrays.asList(grade1.getEntityId(), grade3.getEntityId())); assertFalse(validator.validate(EntityNames.GRADE, ids).equals(ids)); }