How to test a service which uses RestHighLevelClient?

(Inna Korobikhina) #1

Hi, I have a service which uses RestHighLevelClient and which I want to unit test. I have a method that has the following lines:

    IndexRequest request = new IndexRequest(index, type).source(getContentBuilder(update));
    IndexResponse response = restHighLevelClient.index(request);
    return response.getResult() == CREATED;

So, in my test I'm trying to do the following:

RestHighLevelClient esClient = Mockito.mock(RestHighLevelClient.class);
MyService updateService;

And directly in the test:

          .thenReturn(new IndexResponse());

But I get the NullPointerExeption in this line.

I found information that we cannot mock RestHighLevelClient. I would like to get more details about it. So, is it possible to test my method using something like that?

Thanks in advance

(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.