@SuppressWarnings("unchecked")
@Test
public void testOverwriteExpiredFilter() {

    final ExpirableBloomFilterConfig config = new ExpirableBloomFilterConfig();
    final ZonedDateTime created = ZonedDateTime.now(ZoneOffset.UTC);
    final ZonedDateTime expiration = created.minus(Duration.ofSeconds(10));
    // a filter factory only to produce expired bloom filters
    final BloomFilterFactory<GuavaBloomFilter, ExpirableBloomFilterConfig> mockedFactory = Mockito.mock(BloomFilterFactory.class);
    Mockito.when(mockedFactory.createFilter(config))
            .thenReturn(new GuavaBloomFilter(
                    config.expectedInsertions(),
                    config.fpp(),
                    created,
                    expiration,
                    null));
    final BloomFilterManagerImpl<GuavaBloomFilter, ExpirableBloomFilterConfig> manager = new BloomFilterManagerImpl<>(mockedFactory);
    final CreateFilterResult<GuavaBloomFilter> firstCreateFilterResult = manager.createFilter(testingFilterName, config);
    assertThat(firstCreateFilterResult.isCreated()).isTrue();
    // overwrite mark is not set, but the exists filter still was overwritten
    final CreateFilterResult<GuavaBloomFilter> secondCreateFilterResult = manager.createFilter(testingFilterName, config);
    assertThat(secondCreateFilterResult.isCreated()).isTrue();
    Mockito.verify(mockedFactory, Mockito.times(2)).createFilter(config);
}