@SuppressWarnings("unchecked") @Test void testFindAll() { EntityType entityType = mock(EntityType.class); when(delegateRepository.getEntityType()).thenReturn(entityType); Object entityId0 = mock(Object.class); Object entityId1 = mock(Object.class); Object entityId2 = mock(Object.class); Object entityId3 = mock(Object.class); Entity entity0 = when(mock(Entity.class).getIdValue()).thenReturn(entityId0).getMock(); Entity entity1 = mock(Entity.class); Entity entity3 = when(mock(Entity.class).getIdValue()).thenReturn(entityId3).getMock(); when(l1Cache.get(entityType, entityId0, null)).thenReturn(Optional.empty()); when(l1Cache.get(entityType, entityId1, null)).thenReturn(Optional.of(CacheHit.of(entity1))); when(l1Cache.get(entityType, entityId2, null)).thenReturn(Optional.of(CacheHit.empty())); when(l1Cache.get(entityType, entityId3, null)).thenReturn(Optional.empty()); doAnswer(invocation -> Stream.of(entity0, entity3)) .when(delegateRepository) .findAll(any(Stream.class)); assertEquals( asList(entity0, entity1, entity3), l1CacheRepositoryDecorator .findAll(Stream.of(entityId0, entityId1, entityId2, entityId3)) .collect(Collectors.toList())); verify(l1Cache).put(entity0); verify(l1Cache).put(entity3); verifyNoMoreInteractions(l1Cache, delegateRepository); }
@Override public Stream<Entity> findAll(Stream<Object> ids) { return useCache() ? findAllWithCache(ids, null) : delegate().findAll(ids); }
L1CacheRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @Override public Stream<Entity> findAll(Stream<Object> ids) { return useCache() ? findAllWithCache(ids, null) : delegate().findAll(ids); } }
L1CacheRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @Override public Stream<Entity> findAll(Stream<Object> ids) { return useCache() ? findAllWithCache(ids, null) : delegate().findAll(ids); } L1CacheRepositoryDecorator(
      Repository<Entity> delegateRepository, L1Cache l1Cache, L1CacheJanitor l1CacheJanitor); }
L1CacheRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @Override public Stream<Entity> findAll(Stream<Object> ids) { return useCache() ? findAllWithCache(ids, null) : delegate().findAll(ids); } L1CacheRepositoryDecorator(
      Repository<Entity> delegateRepository, L1Cache l1Cache, L1CacheJanitor l1CacheJanitor); @Override void add(Entity entity); @Override Integer add(Stream<Entity> entities); @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); @Override void update(Entity entity); @Override void update(Stream<Entity> entities); @Override void delete(Entity entity); @Override void delete(Stream<Entity> entities); @Override void deleteById(Object id); @Override void deleteAll(Stream<Object> ids); @Override void deleteAll(); }
L1CacheRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @Override public Stream<Entity> findAll(Stream<Object> ids) { return useCache() ? findAllWithCache(ids, null) : delegate().findAll(ids); } L1CacheRepositoryDecorator(
      Repository<Entity> delegateRepository, L1Cache l1Cache, L1CacheJanitor l1CacheJanitor); @Override void add(Entity entity); @Override Integer add(Stream<Entity> entities); @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); @Override void update(Entity entity); @Override void update(Stream<Entity> entities); @Override void delete(Entity entity); @Override void delete(Stream<Entity> entities); @Override void deleteById(Object id); @Override void deleteAll(Stream<Object> ids); @Override void deleteAll();  }