### Question:
StudentToSubStudentValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(SUB_STUDENT_ENTITIES, entityType, ids)) { return Collections.emptySet(); } Map<String, Set<String>> studentIds = new HashMap<String, Set<String>>(getIdsContainedInFieldOnEntities(entityType, new ArrayList<String>(ids), ParameterConstants.STUDENT_ID)); return getValidIds(getDirectStudentIds(), studentIds); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids);  }### Answer:
@Test public void testValidateSingleEntity() { injector.setStudentContext(student1); Set<String> idsToValidate = new HashSet<String>(Arrays.asList(attendance1.getEntityId())); assertTrue(validator.validate(EntityNames.ATTENDANCE, idsToValidate).containsAll(idsToValidate)); idsToValidate = new HashSet<String>(Arrays.asList(studentAcademicRecord1.getEntityId())); assertTrue(validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, idsToValidate).containsAll(idsToValidate)); injector.setStudentContext(student2); idsToValidate = new HashSet<String>(Arrays.asList(attendance2.getEntityId())); assertTrue(validator.validate(EntityNames.ATTENDANCE, idsToValidate).containsAll(idsToValidate)); idsToValidate = new HashSet<String>(Arrays.asList(studentAcademicRecord2.getEntityId())); assertTrue(validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, idsToValidate).containsAll(idsToValidate)); }
@Test public void testValidateNegativeHeterogeneousList() { injector.setStudentContext(student1); Set<String> idsToValidate = new HashSet<String>(Arrays.asList(attendance1.getEntityId(),attendance2.getEntityId())); assertFalse(validator.validate(EntityNames.ATTENDANCE, idsToValidate).containsAll(idsToValidate)); idsToValidate = new HashSet<String>(Arrays.asList(studentAcademicRecord1.getEntityId(), studentAcademicRecord2.getEntityId())); assertFalse(validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, idsToValidate).containsAll(idsToValidate)); }