### Question:
RoleAuditFilterCache extends AuthCache<RoleAuditFilterCacheKey, Boolean> { public boolean isWhitelisted(RoleAuditFilterCacheKey cacheKey) { try { return get(cacheKey); } catch (ExecutionException e) { throw new UncheckedExecutionException(e); } } RoleAuditFilterCache(Function<RoleAuditFilterCacheKey, Boolean> loadFunction); @VisibleForTesting  RoleAuditFilterCache(Function<RoleAuditFilterCacheKey, Boolean> loadFunction, AuditConfig auditConfig); boolean isWhitelisted(RoleAuditFilterCacheKey cacheKey);  }### Answer:
@Test public void testValueIsReadEveryTimeWhenCacheDisabled() { givenCacheValidity(0); when(loadFunction.apply(cacheKey)).thenReturn(true, false); RoleAuditFilterCache cache = new RoleAuditFilterCache(loadFunction, auditConfig); assertThat(cache.isWhitelisted(cacheKey)).isTrue(); assertThat(cache.isWhitelisted(cacheKey)).isFalse(); verify(loadFunction, times(2)).apply(cacheKey); }
@Test public void testValueIsCached() { givenCacheValidity(500); when(loadFunction.apply(cacheKey)).thenReturn(true, false); RoleAuditFilterCache cache = new RoleAuditFilterCache(loadFunction, auditConfig); assertThat(cache.isWhitelisted(cacheKey)).isTrue(); assertThat(cache.isWhitelisted(cacheKey)).isTrue(); verify(loadFunction, times(1)).apply(cacheKey); }
@Test public void testValueIsRefreshed() { givenCacheValidity(500); when(loadFunction.apply(cacheKey)).thenReturn(true, false); RoleAuditFilterCache cache = new RoleAuditFilterCache(loadFunction, auditConfig); assertThat(cache.isWhitelisted(cacheKey)).isTrue(); Awaitility.await().pollInterval(250, TimeUnit.MILLISECONDS) .atMost(1, TimeUnit.SECONDS) .until(() -> cache.isWhitelisted(cacheKey) == false); verify(loadFunction, times(2)).apply(cacheKey); }