@Test public void cacheAndReset() { Map<String, Integer> stats = service.getSummaryStats(); assertThat(stats.get("approvalCount"), is(4)); assertThat(stats.get("userCount"), is(2)); assertThat(stats.get("clientCount"), is(3)); Mockito.when(approvedSiteService.getAll()) .thenReturn(Sets.newHashSet(ap1, ap2, ap3, ap4, ap5, ap6)); Map<String, Integer> stats2 = service.getSummaryStats(); // cache should remain the same due to memoized functions assertThat(stats2.get("approvalCount"), is(4)); assertThat(stats2.get("userCount"), is(2)); assertThat(stats2.get("clientCount"), is(3)); // reset the cache and make sure the count goes up service.resetCache(); Map<String, Integer> stats3 = service.getSummaryStats(); assertThat(stats3.get("approvalCount"), is(6)); assertThat(stats3.get("userCount"), is(2)); assertThat(stats3.get("clientCount"), is(4)); }