### Question:
FilterTimeoutMonitor { void checkFilters() { filterRepository .getFilters() .forEach( filter -> { if (filter.isExpired()) { filterRepository.delete(filter.getId()); } }); } FilterTimeoutMonitor(final FilterRepository filterRepository);   }### Answer:
@Test public void expiredFilterShouldBeDeleted() { final Filter filter = spy(new BlockFilter("foo")); when(filter.isExpired()).thenReturn(true); when(filterRepository.getFilters()).thenReturn(Lists.newArrayList(filter)); timeoutMonitor.checkFilters(); verify(filterRepository).getFilters(); verify(filterRepository).delete("foo"); verifyNoMoreInteractions(filterRepository); }
@Test public void nonExpiredFilterShouldNotBeDeleted() { final Filter filter = mock(Filter.class); when(filter.isExpired()).thenReturn(false); when(filterRepository.getFilters()).thenReturn(Lists.newArrayList(filter)); timeoutMonitor.checkFilters(); verify(filter).isExpired(); verifyNoMoreInteractions(filter); }
@Test public void checkEmptyFilterRepositoryDoesNothing() { when(filterRepository.getFilters()).thenReturn(Collections.emptyList()); timeoutMonitor.checkFilters(); verify(filterRepository).getFilters(); verifyNoMoreInteractions(filterRepository); }