CachingClientTable implements ClientTable<E> { @Override public Stream<E> findAll() { return getCache().values().stream(); } CachingClientTable(DatabaseAccessor accessor, Function<String, ? extends ClientOperation<E>> operationMap, Function<E, String> idGetter);   CachingClientTable(ClientTable<E> delegate, Function<String, ? extends ClientOperation<E>> operationMap, Function<? super E, String> idGetter); @Override String getName(); @Override Stream<E> findAll(); @Override E findById(String id); @Override synchronized Event append(String user, String operation, String objectId, String data);  }
@Test @DisplayName("Loads data only once") void testFindAll() { when(delegate.findAll()).thenAnswer(__ -> Stream.of("A", "B", "C")); assertThat(table.findAll()).containsOnly("A", "B", "C"); assertThat(table.findAll()).containsOnly("A", "B", "C"); verify(delegate, times(1)).findAll(); verifyNoMoreInteractions(delegate); }