I'm trying to use groovy to write Junit, for a class that uses RestHighLevelClient to call ES and get the search results.
I am not able to mock the client using GroovyMock or normal mock.
Please let me know how to approach this Junit use case
Can you please be more specific, what the problem is, which exceptions are thrown, etc?
Usually when we mock an object of a specific class, the control will not go to the mocked class while unit testing and we can make a specific method from that class , return what result we want when the test is run . But that isn't the case when I mock RestHighLevelClient . Please see the code snippet below , Imagine I'm trying to write a unit test case for the following java class using groovy:
Public class ESService {
Public RestHighLevelClient restHighLevlClient;//(intialisation logic, where we define the url etc)
Public getsearchResult(parameters){
//random code
SearchResponse response = restHighLevlClient.search(searchRequest);
}
If I mock RestHighLevelClient , the control shouldn't go inside search, but that isn't the case , it goes into RestHighLevelClient class and tries to intialize the restClient inside it which throws null pointer exception because I haven't given any URL or anything.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.