### Question:
ContextValidator implements ApplicationContextAware { protected Set<String> getEntityIdsToValidateForgiving(Collection<Entity> entities, boolean isTransitive){ Set<String> entityIdsToValidate = new HashSet<String>(); for (Entity ent : entities) { if (isOrphanCreatedByUser(ent)) { LOG.debug("Entity is orphaned: id {} of type {}", ent.getEntityId(), ent.getType()); } else if (SecurityUtil.getSLIPrincipal().getEntity() != null && SecurityUtil.getSLIPrincipal().getEntity().getEntityId().equals(ent.getEntityId())) { LOG.debug("Entity is themselves: id {} of type {}", ent.getEntityId(), ent.getType()); } else { try{ if (ownership.canAccess(ent, isTransitive)) { entityIdsToValidate.add(ent.getEntityId()); } } catch (AccessDeniedException aex) { LOG.error(aex.getMessage()); } } } return entityIdsToValidate; }  @Override void setApplicationContext(ApplicationContext applicationContext); void validateContextToUri(ContainerRequest request, SLIPrincipal principal); boolean isUrlBlocked(ContainerRequest request); List<PathSegment> cleanEmptySegments(List<PathSegment> pathSegments); void validateContextToCallUri(List<PathSegment> segments); boolean checkAccessOfStudentsThroughDisciplineIncidents(List<PathSegment> segments); void validateContextToEntities(EntityDefinition def, Collection<String> ids, boolean isTransitive); Set<String> getValidIdsIncludeOrphans(EntityDefinition def, Set<String> ids, boolean isTransitive); Map<String, SecurityUtil.UserContext> getValidatedEntityContexts(EntityDefinition def, Collection<Entity> entities, boolean isTransitive, boolean isRead); IContextValidator findValidator(String toType, boolean isTransitive); static boolean isTransitive(List<PathSegment> segs); List<IContextValidator> findContextualValidators(String toType, boolean isTransitive); boolean isGlobalEntity(String type);  }### Answer:
@Test public void testgetEntityIdsToValidateForgiving() { Entity student0 = createEntity("student", 0); Entity student1 = createEntity("student", 1); Entity student2 = createEntity("student", 2); List<Entity> students = Arrays.asList(student0, student1, student2); boolean isTransitive = false; Mockito.when(ownership.canAccess(student0, isTransitive)).thenReturn(true); Mockito.when(ownership.canAccess(student1, isTransitive)).thenReturn(true); Mockito.when(ownership.canAccess(student2, isTransitive)).thenThrow(new AccessDeniedException("")); Set<String> ids = contextValidator.getEntityIdsToValidateForgiving(students, isTransitive); Assert.assertEquals(2, ids.size()); Assert.assertTrue(ids.contains(student0.getEntityId())); Assert.assertTrue(ids.contains(student1.getEntityId())); }