@Override
    public void doRun() {
        final Instant mustBeOlderThan = Instant.now().minus(maximumSearchAge);
        searchDbService.getExpiredSearches(findReferencedSearchIds(),
                mustBeOlderThan).forEach(searchDbService::delete);
    }
@Test
    public void testForMixedReferencedNonReferencedExpiredAndNonexpiredSearches() {
        final ViewSummaryDTO view = ViewSummaryDTO.builder()
                .title("my-view")
                .searchId(IN_USE_SEARCH_ID)
                .build();

        when(viewService.streamAll()).thenReturn(Stream.of(view));

        final SearchSummary search1 = SearchSummary.builder()
                .id(IN_USE_SEARCH_ID)
                .createdAt(DateTime.now(DateTimeZone.UTC).minus(Duration.standardDays(30)))
                .build();

        final SearchSummary search2 = SearchSummary.builder()
                .createdAt(DateTime.now(DateTimeZone.UTC).minus(Duration.standardHours(2)))
                .build();

        final SearchSummary search3 = SearchSummary.builder()
                .id("This search is expired and should be deleted")
                .createdAt(DateTime.now(DateTimeZone.UTC).minus(Duration.standardDays(30)))
                .build();

        when(searchDbService.findSummaries()).thenReturn(Stream.of(search1, search2, search3));
        when(searchDbService.getExpiredSearches(any(), any())).thenCallRealMethod();

        this.searchesCleanUpJob.doRun();

        final ArgumentCaptor<String> deletedSearchId = ArgumentCaptor.forClass(String.class);
        verify(searchDbService, times(1)).delete(deletedSearchId.capture());
        assertThat(deletedSearchId.getValue()).isEqualTo("This search is expired and should be deleted");
    }