@Test
public void test_run_batch_search_failure() throws Exception {

    Document[] documents = {createDoc("doc").build()};
    firstSearchWillReturn(1, documents);
    when(repository.getQueued()).thenReturn(singletonList(
        new BatchSearch("uuid1", project("test-datashare"), "name1", "desc1", asSet("query1", "query2"), new Date(), BatchSearch.State.RUNNING, User.local())
    ));
    when(repository.saveResults(anyString(), any(), anyList())).thenThrow(new RuntimeException());
    assertThat(new BatchSearchRunner(indexer, repository, new PropertiesProvider(), local()).call()).isEqualTo(0);
    verify(repository).setState("uuid1", BatchSearch.State.RUNNING);
    verify(repository).setState(eq("uuid1"), any(SearchException.class));
}