### Question:
EdOrgOwnershipArbiter extends OwnershipArbiter { public Set<String> determineHierarchicalEdorgs(Iterable<Entity> entities, String entityType) { Set<String> hierarchicalEdorgs = new HashSet<String>(); List<Entity> edorgs = findOwner(entities, entityType, true); for (Entity edorg : edorgs) { hierarchicalEdorgs.add(edorg.getEntityId()); hierarchicalEdorgs.addAll(helper.getParentEdOrgs(edorg)); } return hierarchicalEdorgs; }  @SuppressWarnings("unused") @PostConstruct void init(); Set<String> determineEdorgs(Iterable<Entity> entities, String entityType); Set<String> determineHierarchicalEdorgs(Iterable<Entity> entities, String entityType); boolean isEntityOwnedByEdOrg(String entityType);  }### Answer:
@Test public void testHierarchicalEdOrgs() { securityContextInjector.setStaffContext(); Entity edorg1 = createEntity(EntityNames.SCHOOL, "edorg1", new HashMap<String, Object>()); Mockito.when(repo.findAll(Mockito.eq(EntityNames.EDUCATION_ORGANIZATION), Mockito.any(NeutralQuery.class))).thenReturn( Arrays.asList(edorg1)); Mockito.when(helper.getParentEdOrgs(edorg1)).thenReturn(Arrays.asList("edorg1Parent1", "edorg1Parent2")); Map<String, Object> attendanceBody = new HashMap<String, Object>(); attendanceBody.put(ParameterConstants.SCHOOL_ID, "edorg1"); Entity attendance = createEntity(EntityNames.ATTENDANCE, "attendance1", attendanceBody); Set<String> edorgIds = arbiter.determineHierarchicalEdorgs(Arrays.asList(attendance), EntityNames.ATTENDANCE); Assert.assertEquals(3, edorgIds.size()); Assert.assertTrue(edorgIds.contains("edorg1")); Assert.assertTrue(edorgIds.contains("edorg1Parent1")); Assert.assertTrue(edorgIds.contains("edorg1Parent2")); }
@Test public void testOrphanedEntity() { securityContextInjector.setStaffContext(); Entity principalEntity = Mockito.mock(Entity.class); Mockito.when(principalEntity.getEntityId()).thenReturn("doofus1_id"); SLIPrincipal principal = Mockito.mock(SLIPrincipal.class); Mockito.when(principal.getEntity()).thenReturn(principalEntity); securityContextInjector.setOauthSecurityContext(principal, false); Mockito.when(repo.findAll(Mockito.anyString(), Mockito.any(NeutralQuery.class))).thenReturn(new ArrayList<Entity>()); Map<String, Object> metaData = new HashMap<String, Object>(); metaData.put("createdBy", "doofus1_id"); metaData.put("isOrphaned", "true"); Entity student1 = new MongoEntity(EntityNames.STUDENT, "student1", new HashMap<String, Object>(), metaData); Set<String> edorgIds = arbiter.determineHierarchicalEdorgs(Arrays.asList(student1), EntityNames.STUDENT); Assert.assertTrue(edorgIds.isEmpty()); }