### Question:
OutputCache implements Reader<T> { @Override public List<T> getRecords() { return new LinkedList<>(records); } OutputCache(Reader<T> reader, Long refreshInterval);  OutputCache(Reader<T> reader, Long refreshInterval, Consumer<IOException> exceptionHandler); @Override List<T> getRecords(); @Override void setConfiguration(ReaderConfiguration configuration); void refresh(); void cancel();  }### Answer:
@Test public void givenReader_ShouldInvokeGetRecords() throws IOException { OutputCache<String> cache = new OutputCache<>(readerSpy, 100L); Awaitility.await() .atMost(90, TimeUnit.MILLISECONDS) .pollInterval(5, TimeUnit.MILLISECONDS) .untilAsserted(() -> { Assert.assertThat(cache.getRecords(), Matchers.hasSize(1)); }); Mockito.verify(readerSpy).getRecords(); }
@Test public void givenReader_AfterRefreshInterval_ShouldHaveInvokedGetRecordsTwice() throws IOException { OutputCache<String> cache = new OutputCache<>(readerSpy, 100L); Awaitility.await() .atMost(190, TimeUnit.MILLISECONDS) .pollInterval(5, TimeUnit.MILLISECONDS) .untilAsserted(() -> { Assert.assertThat(cache.getRecords(), Matchers.hasSize(2)); }); Mockito.verify(readerSpy, Mockito.times(2)).getRecords(); }