我正在尝试在 Spring Java 中为 org.opensearch.client.opensearch.OpenSearchClient API(如 msearch、bulk 等)编写 Junit 测试,但出现编译错误。
被嘲笑的API签名是
public <TDocument> MsearchResponse<TDocument> msearch(MsearchRequest request, Class<TDocument> tDocumentClass)
throws IOException, OpenSearchException
单元测试模拟方法的示例是;
Mockito.when(client.msearch(ArgumentMatchers.any(), ArgumentMatchers.any()))
.thenReturn(mSearchResponse);
看到的错误消息如下'
方法 msearch(MsearchRequest, Class) 对于 输入 OpenSearchClient
任何人都可以指导、分享如何正确模拟和测试 OpenSearchClient API?
我通过将 Mockito when-then 语句更改为下面找到了解决方案;
Mockito.when(client.msearch(ArgumentMatchers.<MsearchRequest>any(), ArgumentMatchers.<Class<Map>>any())).thenReturn(mSearchResponse);
上述问题已为我解决。 干杯,快乐编码!