@Test void streamFetch() { when(delegateRepository.getEntityType()).thenReturn(entityType); Fetch fetch = new Fetch(); Entity entity0 = mock(Entity.class); Entity entity1 = mock(Entity.class); Entity entity0WithRefs = mock(Entity.class); Entity entity1WithRefs = mock(Entity.class); List<Entity> entities = Arrays.asList(entity0, entity1); List<Entity> entitiesWithRefs = Arrays.asList(entity0WithRefs, entity1WithRefs); when(entityManager.resolveReferences(eq(entityType), streamArgumentCaptor.capture(), eq(fetch))) .thenReturn(entitiesWithRefs.stream()); entityReferenceResolverDecorator.forEachBatched(fetch, consumer, 123); verify(delegateRepository).forEachBatched(eq(fetch), consumerArgumentCaptor.capture(), eq(123)); consumerArgumentCaptor.getValue().accept(entities); Stream<Entity> entitiesToDecorate = streamArgumentCaptor.getValue(); assertEquals(entities, entitiesToDecorate.collect(toList())); verify(consumer).accept(entitiesWithRefs); }
@Override public void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize) { delegate() .forEachBatched( fetch, entities -> { List<Entity> resolvedEntities = resolveEntityReferences(entities.stream(), fetch).collect(Collectors.toList()); consumer.accept(resolvedEntities); }, batchSize); }
EntityReferenceResolverDecorator extends AbstractRepositoryDecorator<Entity> { @Override public void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize) { delegate() .forEachBatched( fetch, entities -> { List<Entity> resolvedEntities = resolveEntityReferences(entities.stream(), fetch).collect(Collectors.toList()); consumer.accept(resolvedEntities); }, batchSize); } }
EntityReferenceResolverDecorator extends AbstractRepositoryDecorator<Entity> { @Override public void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize) { delegate() .forEachBatched( fetch, entities -> { List<Entity> resolvedEntities = resolveEntityReferences(entities.stream(), fetch).collect(Collectors.toList()); consumer.accept(resolvedEntities); }, batchSize); } EntityReferenceResolverDecorator(
      Repository<Entity> delegateRepository, EntityManager entityManager); }
EntityReferenceResolverDecorator extends AbstractRepositoryDecorator<Entity> { @Override public void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize) { delegate() .forEachBatched( fetch, entities -> { List<Entity> resolvedEntities = resolveEntityReferences(entities.stream(), fetch).collect(Collectors.toList()); consumer.accept(resolvedEntities); }, batchSize); } EntityReferenceResolverDecorator(
      Repository<Entity> delegateRepository, EntityManager entityManager); @Override Stream<Entity> findAll(Query<Entity> q); @Override Entity findOne(Query<Entity> q); @Override Iterator<Entity> iterator(); @Override void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize); @Override Entity findOneById(Object id); @Override Entity findOneById(Object id, Fetch fetch); @Override Stream<Entity> findAll(Stream<Object> ids); @Override Stream<Entity> findAll(Stream<Object> ids, Fetch fetch); }
EntityReferenceResolverDecorator extends AbstractRepositoryDecorator<Entity> { @Override public void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize) { delegate() .forEachBatched( fetch, entities -> { List<Entity> resolvedEntities = resolveEntityReferences(entities.stream(), fetch).collect(Collectors.toList()); consumer.accept(resolvedEntities); }, batchSize); } EntityReferenceResolverDecorator(
      Repository<Entity> delegateRepository, EntityManager entityManager); @Override Stream<Entity> findAll(Query<Entity> q); @Override Entity findOne(Query<Entity> q); @Override Iterator<Entity> iterator(); @Override void forEachBatched(Fetch fetch, Consumer<List<Entity>> consumer, int batchSize); @Override Entity findOneById(Object id); @Override Entity findOneById(Object id, Fetch fetch); @Override Stream<Entity> findAll(Stream<Object> ids); @Override Stream<Entity> findAll(Stream<Object> ids, Fetch fetch);  }