Source:
<code>public void setUp() throws Exception { <START> template = new ElasticsearchRestTemplate(client); initTemplate(template); <END> doReturn(indexResponse).when(client).index(any(IndexRequest.class), any(RequestOptions.class)); doReturn("response-id").when(indexResponse).getId(); doReturn(bulkResponse).when(client).bulk(any(BulkRequest.class), any(RequestOptions.class)); doReturn(new BulkItemResponse[] { bulkItemResponse, bulkItemResponse }).when(bulkResponse).getItems(); doReturn("response-id").when(bulkItemResponse).getId(); doReturn(getResponse).when(client).get(any(GetRequest.class), any(RequestOptions.class)); doReturn(true).when(getResponse).isExists(); doReturn(false).when(getResponse).isSourceEmpty(); doReturn(ImmutableMap.of("id", "init", "firstname", "luke")).when(getResponse).getSourceAsMap(); doReturn(multiGetResponse).when(client).mget(any(MultiGetRequest.class), any(RequestOptions.class)); doReturn(new MultiGetItemResponse[]{multiGetItemResponse, multiGetItemResponse}) .when(multiGetResponse).getResponses(); doReturn(getResponse).when(multiGetItemResponse).getResponse(); doReturn(searchResponse).when(client).search(any(SearchRequest.class), any(RequestOptions.class)); doReturn(nSearchHits(2)).when(searchResponse).getHits(); doReturn("scroll-id").when(searchResponse).getScrollId(); doReturn(new BytesArray(new byte[8])).when(searchHit).getSourceRef(); doReturn(ImmutableMap.of("id", "init", "firstname", "luke")).when(searchHit).getSourceAsMap(); MultiSearchResponse multiSearchResponse = new MultiSearchResponse( new MultiSearchResponse.Item[]{ multiSearchResponseItem }, 1L); doReturn(multiSearchResponse).when(client).multiSearch(any(MultiSearchRequest.class), any()); doReturn(searchResponse).when(multiSearchResponseItem).getResponse(); doReturn(searchResponse).when(client).scroll(any(SearchScrollRequest.class), any(RequestOptions.class)); }</code><technical_language>suggestion initTemplate(new ElasticsearchRestTemplate(client)); change in base class</technical_language>

Target:
public void setUp() throws Exception { initTemplate(new ElasticsearchRestTemplate(client)); doReturn(indexResponse).when(client).index(any(IndexRequest.class), any(RequestOptions.class)); doReturn("response-id").when(indexResponse).getId(); doReturn(bulkResponse).when(client).bulk(any(BulkRequest.class), any(RequestOptions.class)); doReturn(new BulkItemResponse[] { bulkItemResponse, bulkItemResponse }).when(bulkResponse).getItems(); doReturn("response-id").when(bulkItemResponse).getId(); doReturn(getResponse).when(client).get(any(GetRequest.class), any(RequestOptions.class)); doReturn(true).when(getResponse).isExists(); doReturn(false).when(getResponse).isSourceEmpty(); doReturn(new HashMap<String, Object>() { { put("id", "init"); put("firstname", "luke"); } }).when(getResponse).getSourceAsMap(); doReturn(multiGetResponse).when(client).mget(any(MultiGetRequest.class), any(RequestOptions.class)); doReturn(new MultiGetItemResponse[]{multiGetItemResponse, multiGetItemResponse}) .when(multiGetResponse).getResponses(); doReturn(getResponse).when(multiGetItemResponse).getResponse(); doReturn(searchResponse).when(client).search(any(SearchRequest.class), any(RequestOptions.class)); doReturn(nSearchHits(2)).when(searchResponse).getHits(); doReturn("scroll-id").when(searchResponse).getScrollId(); doReturn(new BytesArray(new byte[8])).when(searchHit).getSourceRef(); doReturn(new HashMap<String, Object>() { { put("id", "init"); put("firstname", "luke"); } }).when(searchHit).getSourceAsMap(); MultiSearchResponse multiSearchResponse = new MultiSearchResponse( new MultiSearchResponse.Item[]{ multiSearchResponseItem }, 1L); doReturn(multiSearchResponse).when(client).multiSearch(any(MultiSearchRequest.class), any()); doReturn(searchResponse).when(multiSearchResponseItem).getResponse(); doReturn(searchResponse).when(client).scroll(any(SearchScrollRequest.class), any(RequestOptions.class)); }