【发布时间】:2022-10-20 20:33:03
【问题描述】:
我正在对反应式 WebClient 使用进行单元测试,当我尝试使用方法 timeout(Duration d) 模拟 Mono 的行为时,我的问题就出现了。
我只想控制调用的结果,例如:
private Mono<String> withTimeout(Mono<String> myMono) {
return myMono.timeout(Duration.of(globalDuration));
}
所以我正在使用这个:
@Test
void test() {
...
Mono<String> monoMock = (Mono<String>) Mockito.mock(Mono.class);
when(monoMock.timeout(Mockito.any(Duration.class))).thenReturn(Mono.just("OK"));
...
}
但它会产生一个
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Misplaces or misused argument matcher detected here:
-> at service.UserServiceTest.test(UserServiceTest.java:98)
You cannot use argument matchers outside of verification or stubbing.
Examples of correct usage of argument matchers:
when(mock.get(anyInt())).thenReturn(null);
doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());
verify(mock).someMethod(contains("foo"))
This message may appear after an NullPointerException if the last matcher is retur....
我应该怎么做什么时候这个结果Mono.timeout方法?
【问题讨论】: