@Override
    public Optional<IndexSet> get(final String indexSetId) {
        return this.indexSetsCache.get()
                .stream()
                .filter(indexSet -> Objects.equals(indexSet.id(), indexSetId))
                .map(indexSetConfig -> (IndexSet) mongoIndexSetFactory.create(indexSetConfig))
                .findFirst();
    }
@Test
    public void indexSetsCacheShouldBeInvalidatedForIndexSetDeletion() {
        final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
        final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
        when(indexSetService.findAll()).thenReturn(indexSetConfigs);

        final List<IndexSetConfig> result = this.indexSetsCache.get();
        assertThat(result)
            .isNotNull()
            .hasSize(1)
            .containsExactly(indexSetConfig);

        this.indexSetsCache.handleIndexSetDeletion(mock(IndexSetDeletedEvent.class));

        final IndexSetConfig newIndexSetConfig = mock(IndexSetConfig.class);
        final List<IndexSetConfig> newIndexSetConfigs = Collections.singletonList(newIndexSetConfig);
        when(indexSetService.findAll()).thenReturn(newIndexSetConfigs);


        final List<IndexSetConfig> newResult = this.indexSetsCache.get();
        assertThat(newResult)
            .isNotNull()
            .hasSize(1)
            .containsExactly(newIndexSetConfig);

        verify(indexSetService, times(2)).findAll();
    }