FileContentCache { byte[] get(Instant lastModifiedTime) { if (modifiedTime.isEmpty() || lastModifiedTime.isAfter(modifiedTime.get())) { value = Optional.of(path.readBytes()); modifiedTime = Optional.of(lastModifiedTime); } return value.get(); } FileContentCache(UnixPath path);   }
@Test public void get() { when(unixPath.readBytes()).thenReturn(content); assertArrayEquals(content, cache.get(Instant.ofEpochMilli(0))); verify(unixPath, times(1)).readBytes(); verifyNoMoreInteractions(unixPath); assertArrayEquals(content, cache.get(Instant.ofEpochMilli(0))); verify(unixPath, times(1)).readBytes(); verifyNoMoreInteractions(unixPath); when(unixPath.readBytes()).thenReturn(newContent); assertArrayEquals(newContent, cache.get(Instant.ofEpochMilli(1))); verify(unixPath, times(1 + 1)).readBytes(); verifyNoMoreInteractions(unixPath); assertArrayEquals(newContent, cache.get(Instant.ofEpochMilli(0))); verify(unixPath, times(1 + 1)).readBytes(); verifyNoMoreInteractions(unixPath); assertArrayEquals(newContent, cache.get(Instant.ofEpochMilli(1))); verify(unixPath, times(1 + 1)).readBytes(); verifyNoMoreInteractions(unixPath); }