ElasticSearchUtils { public static IndicesExistsResponse indexExist(Client client, String indexName) { try { return client.admin().indices() .prepareExists(indexName) .execute().actionGet(); } catch(Exception e) { if(log.isErrorEnabled()) { log.error("Error Checking Index Exist", e); } throw new IndicesExistsFailedException(indexName, e); } } private  ElasticSearchUtils(); static IndicesExistsResponse indexExist(Client client, String indexName); static CreateIndexResponse createIndex(Client client, String indexName); static AcknowledgedResponse putMapping(Client client, String indexName, IElasticSearchMapping mapping);  }
@Test public void indices_exist_throws_correct_exception_when_underlying_client_throws() throws Exception { when(client.admin()).thenThrow(new RuntimeException()); TestUtils.assertThrows(() -> ElasticSearchUtils.indexExist(client, ""), IndicesExistsFailedException.class); }