### Question:
TeacherToTeacherSchoolAssociationValidator extends AbstractContextValidator { @Override public Set<String> validate(String entityType, Set<String> ids) throws IllegalStateException { if (!areParametersValid(EntityNames.TEACHER_SCHOOL_ASSOCIATION, entityType, ids)) { return Collections.EMPTY_SET; } NeutralQuery nq = new NeutralQuery(new NeutralCriteria(ParameterConstants.TEACHER_ID, NeutralCriteria.OPERATOR_EQUAL, SecurityUtil.getSLIPrincipal().getEntity().getEntityId())); Iterable<String> it = this.repo.findAllIds(EntityNames.TEACHER_SCHOOL_ASSOCIATION, nq); Set<String> fin = Sets.newHashSet(it); fin.retainAll(ids); return fin; }  @Override boolean canValidate(String entityType, boolean isTransitive); @Override Set<String> validate(String entityType, Set<String> ids); @Override SecurityUtil.UserContext getContext();  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testValidateWrongType() { val.validate(EntityNames.ASSESSMENT, new HashSet<String>(Arrays.asList("Jomolungma"))); }
@Test public void testSuccessOne() { Entity tsa = this.vth.generateTeacherSchool(USER_ID, "Myrran"); Set<String> ids = Collections.singleton(tsa.getEntityId()); Assert.assertTrue(val.validate(CORRECT_ENTITY_TYPE, ids).equals(ids)); }
@Test public void testSuccessMulti() { Set<String> ids = new HashSet<String>(); for (int i = 0; i < 100; i++) { ids.add(this.vth.generateTeacherSchool(USER_ID, "Myrran"+i).getEntityId()); } Assert.assertTrue(val.validate(CORRECT_ENTITY_TYPE, ids).equals(ids)); }
@Test public void testWrongId() { Set<String> ids = Collections.singleton("Hammerhands"); Assert.assertFalse(val.validate(CORRECT_ENTITY_TYPE, ids).equals(ids)); ids = Collections.singleton("Nagas"); Assert.assertFalse(val.validate(CORRECT_ENTITY_TYPE, ids).equals(ids)); ids = Collections.singleton("Phantom Warriors"); Assert.assertFalse(val.validate(CORRECT_ENTITY_TYPE, ids).equals(ids)); }
@Test public void testHeterogenousList() { Set<String> ids = new HashSet<String>(Arrays.asList(this.vth.generateTeacherSchool(USER_ID, "Myrran").getEntityId(), "Pikemen", "Pegasi")); Assert.assertFalse(val.validate(CORRECT_ENTITY_TYPE, ids).equals(ids)); }