【发布时间】:2025-11-27 05:15:02
【问题描述】:
下面是我要测试的代码:
@Autowired
RetryTemplate retryTemplate;
MyResponse response;
response = retryTemplate.execute(new RetryCallback<Mono<MyResponse>, RuntimeException>() {
public Mono<MyResponse> doRetry(RetryContext context) {
return webclient.post.body(Mono.just(requestBodyObj), RequestBodyObj.class).retrieve().bodyToMono(MyResponse.class);
}
});
以下是我正在尝试的测试用例,但出现 Invalid use of matchers 异常。另外,我不确定我的以下代码是否有效。请指导:
MyResponse myResponseObj = new MyResponse();
when(retryTemplate.execute(any(RetryCallback.class))).thenAnswer(invocation -> {
RetryCallback retry = invocation.getArgument(0);
when(retry.doWithRetry(Mockito.any())).thenReturn(Mockito.eq(Mono.just(myResponseObj)))
return retry.doWithRetry(null);
});
请指导这里的错误是什么以及每当调用retry.doWithRetry 时我如何返回retry.doWithRetry。
【问题讨论】:
标签: java spring-boot unit-testing mockito