### Question:
CachingSessionBlacklist implements SessionBlacklist { @Override public boolean isBlacklisted(final Session session) throws SessionException { final String key = session.getStableStorageID(); if (cache.containsKey(key)) { return true; } boolean isBlacklisted = delegate.isBlacklisted(session); if (isBlacklisted) { cache.put(key, session.getBlacklistExpiryTime(purgeDelayMs)); } return isBlacklisted; } @VisibleForTesting  CachingSessionBlacklist(final SessionBlacklist delegate, final int maxSize, final long purgeDelayMs,
                            final TimeService clock);  CachingSessionBlacklist(final SessionBlacklist delegate, final int maxSize, final long purgeDelayMs); @Override void blacklist(final Session session); @Override boolean isBlacklisted(final Session session); @Override void subscribe(final Listener listener);  }### Answer:
@Test public void shouldHitDelegateIfResultNotCached() throws Exception { given(mockDelegate.isBlacklisted(mockSession)).willReturn(true); boolean result = testBlacklist.isBlacklisted(mockSession); assertThat(result).isTrue(); }
@Test public void shouldCachePositiveResults() throws Exception { given(mockSession.getTimeLeft()).willReturn(1L); given(mockClock.now()).willReturn(0L); given(mockDelegate.isBlacklisted(mockSession)).willReturn(true); testBlacklist.isBlacklisted(mockSession); verify(mockDelegate).isBlacklisted(mockSession); boolean result = testBlacklist.isBlacklisted(mockSession); verifyNoMoreInteractions(mockDelegate); assertThat(result).isTrue(); }
@Test public void shouldNotCacheNegativeResults() throws Exception { given(mockSession.getTimeLeft()).willReturn(1L); given(mockClock.now()).willReturn(0L); given(mockDelegate.isBlacklisted(mockSession)).willReturn(false); testBlacklist.isBlacklisted(mockSession); boolean result = testBlacklist.isBlacklisted(mockSession); verify(mockDelegate, times(2)).isBlacklisted(mockSession); assertThat(result).isFalse(); }