我正在测试某个课程。这个类在内部实例化一个“GetMethod”对象,该对象被传递给一个“HttpClient”对象,该对象被注入到测试类中。
我在嘲笑“HttpClient”类,但我也需要修改“GetMethod”类的一种方法的行为。我正在玩 ArgumentCaptor,但我似乎无法在“何时”调用中获取实例化对象。
例子:
HttpClient mockHttpClient = mock(HttpClient.class);
ArgumentCaptor<GetMethod> getMethod = ArgumentCaptor.forClass(GetMethod.class);
when(mockHttpClient.executeMethod(getMethod.capture())).thenReturn(HttpStatus.SC_OK);
when(getMethod.getValue().getResponseBodyAsStream()).thenReturn(new FileInputStream(source));
回复:
org.mockito.exceptions.base.MockitoException:
No argument value was captured!
You might have forgotten to use argument.capture() in verify()...
...or you used capture() in stubbing but stubbed method was not called.
Be aware that it is recommended to use capture() only with verify()