I have a java code to establish a connection to the Solr server. I am not sure how I can mock it. Please check my code below.
SolrClient solrClient = new HttpSolrClient.Builder(url).build();
QueryResponse res = solrClient.query(solrQuery);
SolrDocumentList results = res.getResults();
Can someone please tell me how I can mock the above logic? Thanks.
Well, it depends on what you are actually trying to test. You could do something like:
QueryResponse emptyResponse = new QueryResponse();
emptyResponse.setResponse(new NamedList<>(Map.of("response", new SolrDocumentList())));
when(solrClientMock.query(any())).thenReturn(emptyResponse);