@Test public void test() { Entity parent = mock(Entity.class); Entity kid1 = mock(Entity.class); when(kid1.getEntityId()).thenReturn("kid1"); Entity kid2 = mock(Entity.class); when(kid2.getEntityId()).thenReturn("kid2"); when(parent.getEntityId()).thenReturn("parentId"); when(repo.findEach(eq("student"), argThat(new BaseMatcher<Query>() { @Override public boolean matches(Object item) { Query q = (Query) item; return q.getQueryObject().get("studentParentAssociation.body.parentId").equals("parentId"); } @Override public void describeTo(Description description) { } }))).thenReturn(Arrays.asList(kid1, kid2).iterator()); when(studentResolver.findGoverningEdOrgs("kid1", parent)).thenReturn(new HashSet<String>(Arrays.asList("lea1", "lea2"))); when(studentResolver.findGoverningEdOrgs("kid2", parent)).thenReturn(new HashSet<String>(Arrays.asList("lea1", "lea3"))); assertEquals(new HashSet<String>(Arrays.asList("lea1", "lea2", "lea3")), underTest.findGoverningEdOrgs(parent)); }
@Override public Set<String> findGoverningEdOrgs(Entity entity) { Set<String> leas = new HashSet<String>(); Iterator<Entity> kids = repo.findEach(EntityNames.STUDENT, Query.query(Criteria.where(PATH_TO_PARENT).is(entity.getEntityId()))); while(kids.hasNext()) { Entity student = kids.next(); leas.addAll(studentResolver.findGoverningEdOrgs(student.getEntityId(), entity)); } return leas; }
ParentContextResolver implements ContextResolver { @Override public Set<String> findGoverningEdOrgs(Entity entity) { Set<String> leas = new HashSet<String>(); Iterator<Entity> kids = repo.findEach(EntityNames.STUDENT, Query.query(Criteria.where(PATH_TO_PARENT).is(entity.getEntityId()))); while(kids.hasNext()) { Entity student = kids.next(); leas.addAll(studentResolver.findGoverningEdOrgs(student.getEntityId(), entity)); } return leas; } }
ParentContextResolver implements ContextResolver { @Override public Set<String> findGoverningEdOrgs(Entity entity) { Set<String> leas = new HashSet<String>(); Iterator<Entity> kids = repo.findEach(EntityNames.STUDENT, Query.query(Criteria.where(PATH_TO_PARENT).is(entity.getEntityId()))); while(kids.hasNext()) { Entity student = kids.next(); leas.addAll(studentResolver.findGoverningEdOrgs(student.getEntityId(), entity)); } return leas; }  }
ParentContextResolver implements ContextResolver { @Override public Set<String> findGoverningEdOrgs(Entity entity) { Set<String> leas = new HashSet<String>(); Iterator<Entity> kids = repo.findEach(EntityNames.STUDENT, Query.query(Criteria.where(PATH_TO_PARENT).is(entity.getEntityId()))); while(kids.hasNext()) { Entity student = kids.next(); leas.addAll(studentResolver.findGoverningEdOrgs(student.getEntityId(), entity)); } return leas; }  @Override Set<String> findGoverningEdOrgs(Entity entity); }
ParentContextResolver implements ContextResolver { @Override public Set<String> findGoverningEdOrgs(Entity entity) { Set<String> leas = new HashSet<String>(); Iterator<Entity> kids = repo.findEach(EntityNames.STUDENT, Query.query(Criteria.where(PATH_TO_PARENT).is(entity.getEntityId()))); while(kids.hasNext()) { Entity student = kids.next(); leas.addAll(studentResolver.findGoverningEdOrgs(student.getEntityId(), entity)); } return leas; }  @Override Set<String> findGoverningEdOrgs(Entity entity); static final String PATH_TO_PARENT; }