### Question:
GenericToProgramValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.PROGRAM, entityType, ids)) { return new HashSet<String>(); } NeutralQuery nq = new NeutralQuery(new NeutralCriteria("body.staffId", "=", SecurityUtil.getSLIPrincipal().getEntity().getEntityId(), false)); if (SecurityUtil.getSLIPrincipal().isStudentAccessFlag()) { nq.addCriteria(new NeutralCriteria(ParameterConstants.STUDENT_RECORD_ACCESS, NeutralCriteria.OPERATOR_EQUAL, true)); } addEndDateToQuery(nq, false); Set<String> validIds = new HashSet<String>(); Iterable<Entity> assocs = getRepo().findAll(EntityNames.STAFF_PROGRAM_ASSOCIATION, nq); for (Entity assoc : assocs) { validIds.add((String) assoc.getBody().get("programId")); } validIds.retainAll(ids); return validIds; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }### Answer:
@Test public void testValidAccessTeacher1() { setupCurrentUser(teacher1); Assert.assertTrue(validator.validate(EntityNames.PROGRAM, new HashSet<String>(Arrays.asList(program1.getEntityId()))).size() == 1); }
@Test public void testValidAccessTeacher2() { setupCurrentUser(teacher2); Assert.assertTrue(validator.validate(EntityNames.PROGRAM, new HashSet<String>(Arrays.asList(program2.getEntityId()))).size() == 1); }
@Test public void testInvalidAccessTeacher1() { setupCurrentUser(teacher1); Set<String> program = new HashSet<String>(Arrays.asList(program2.getEntityId())); Assert.assertFalse(validator.validate(EntityNames.PROGRAM, program).equals(program)); program = new HashSet<String>(Arrays.asList(program3.getEntityId())); Assert.assertFalse(validator.validate(EntityNames.PROGRAM, program).equals(program)); program = new HashSet<String>(Arrays.asList(program4.getEntityId())); Assert.assertFalse(validator.validate(EntityNames.PROGRAM, program).equals(program)); }
@Test public void testInvalidAccessTeacher2() { setupCurrentUser(teacher2); Set<String> program = new HashSet<String>(Arrays.asList(program1.getEntityId())); Assert.assertFalse(validator.validate(EntityNames.PROGRAM, program).equals(program)); program = new HashSet<String>(Arrays.asList(program3.getEntityId())); Assert.assertFalse(validator.validate(EntityNames.PROGRAM, program).equals(program)); program = new HashSet<String>(Arrays.asList(program4.getEntityId())); Assert.assertFalse(validator.validate(EntityNames.PROGRAM, program).equals(program)); }