### Question:
StaffToCourseTranscriptValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.COURSE_TRANSCRIPT, entityType, ids)) { return Collections.emptySet(); } LOG.info("Validating {}'s access to courseTranscripts: [{}]", SecurityUtil.getSLIPrincipal().getName(), ids); NeutralQuery query = new NeutralQuery(new NeutralCriteria(ParameterConstants.ID, NeutralCriteria.CRITERIA_IN, new ArrayList<String>(ids))); Iterable<Entity> entities = getRepo().findAll(EntityNames.COURSE_TRANSCRIPT, query); Map<String, Set<String>> studentAcademicRecords = new HashMap<String, Set<String>>(); for (Entity entity : entities) { Map<String, Object> body = entity.getBody(); if (body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID) instanceof String) { String key = (String) body.get(ParameterConstants.STUDENT_ACADEMIC_RECORD_ID); if(!studentAcademicRecords.containsKey(key)) { studentAcademicRecords.put(key, new HashSet<String>()); } studentAcademicRecords.get(key).add(entity.getEntityId()); } else { LOG.warn("Possible Corrupt Data detected at "+entityType+"/"+entity.getEntityId()); } } if (studentAcademicRecords.isEmpty()) { return Collections.EMPTY_SET; } Set<String> validStudentAcademicRecords = validator.validate(EntityNames.STUDENT_ACADEMIC_RECORD, studentAcademicRecords.keySet()); return getValidIds(validStudentAcademicRecords, studentAcademicRecords); }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }### Answer:
@Test public void testValidAssociationsForStaff1() { setupCurrentUser(staff1); Assert.assertEquals(1, validator.validate(EntityNames.COURSE_TRANSCRIPT, new HashSet<String>(Arrays.asList(courseTranscript1.getEntityId()))).size()); }
@Test public void testValidAssociationsForStaff2() { setupCurrentUser(staff2); Assert.assertEquals(1, validator.validate(EntityNames.COURSE_TRANSCRIPT, new HashSet<String>(Arrays.asList(courseTranscript2.getEntityId()))).size()); }
@Test public void testInValidAssociationsForStaff1() { setupCurrentUser(staff1); Assert.assertEquals(0, validator.validate(EntityNames.COURSE_TRANSCRIPT, new HashSet<String>(Arrays.asList(courseTranscript2.getEntityId()))).size()); }
@Test public void testInValidAssociationsForStaff2() { setupCurrentUser(staff2); Assert.assertEquals(0, validator.validate(EntityNames.COURSE_TRANSCRIPT, new HashSet<String>(Arrays.asList(courseTranscript1.getEntityId()))).size()); }
@Test public void testInvalidAssociations() { setupCurrentUser(staff2); Assert.assertEquals(0, validator.validate(EntityNames.COURSE_TRANSCRIPT, new HashSet<String>(Arrays.asList(UUID.randomUUID().toString()))).size()); Assert.assertEquals(0, validator.validate(EntityNames.COURSE_TRANSCRIPT, new HashSet<String>()).size()); }