### Question:
MappingTypeElasticsearchConnector implements ElasticsearchConnector { @Override public boolean indexExists(String index) throws IOException { Response response = client.getLowLevelClient().performRequest(new Request(HttpHead.METHOD_NAME, "/" + index)); return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK; } MappingTypeElasticsearchConnector(RestHighLevelClient client); @Override boolean isAvailable(); @Override boolean indexExists(String index); @Override boolean createIndex(String index); @Override void storeItems(String index, Collection<QueryVersionReport> reports); @Override void close();  }### Answer:
@Test(expected = IOException.class) public void indexExistsThrowsException_forServerFailure() throws Exception { mockServerClient.when(request().withPath("/" + INDEX_NAME)) .error(HttpError.error().withDropConnection(true)); connector.indexExists(INDEX_NAME); }
@Test public void indexExistsReturnsFalse_whenIndexNotAvailable() throws Exception { mockServerClient.when(request().withPath("/" + INDEX_NAME)) .respond(response().withStatusCode(404)); assertThat(connector.indexExists(INDEX_NAME)).isFalse(); }
@Test public void indexExistsReturnsTrue_whenIndexAvailable() throws Exception { mockServerClient.when(request().withPath("/" + INDEX_NAME)) .respond(response().withStatusCode(200)); assertThat(connector.indexExists(INDEX_NAME)).isTrue(); }