我正在尝试使用 Mockitoverify
功能验证一个方法是否被多次调用。但是,我遇到的问题是该方法已重载,因此它声称该方法未被调用。要将扳手添加到组合中,我还希望捕获传递给此方法的参数是什么。这是我到目前为止所拥有的:
@Test
public void simpleTest() throws IOException {
FlumeAppender mockAppender = Mockito.mock(FlumeAppender.class);
ArgumentCaptor<LoggingEvent> arguments = ArgumentCaptor.forClass(LoggingEvent.class);
// Load the message that should be sent to the class being tested
InputStream in = this.getClass().getResourceAsStream("/testMessage.xml");
StringWriter writer = new StringWriter();
IOUtils.copy(in, writer, "UTF-8");
String testMessage = writer.toString();
// Send a message to the class being tested. This class will
// (hopefully) call the function I am listening to below
eventSubscriber.handleMessage(testMessage);
// Verify that the append method was called twice
Mockito.verify(mockAppender, Mockito.times(2)).append(
arguments.capture());
// Do something with the arguments
}
就像我说的那样,我试图验证(追加)的功能已重载。是否可以在仍捕获参数的同时指定我要求验证的附加函数?