Mockito:如何在实际方法调用后调用自定义方法?
Mockito: How to call custom method after real method call?
我有一个 emailService @Spy 对象,它具有发送功能。我想做这样的事情。
when(emailClientService.send(any())).thenCallRealMethod().thenCallMyCustomMethod(...)
我找到答案了!
Mockito.doAnswer((Answer<Object>) invocation -> {
invocation.callRealMethod(); // calling emailService.send()
callMyCustomMethod();
...
return null;
}).when(emailService).send(any());
我有一个 emailService @Spy 对象,它具有发送功能。我想做这样的事情。
when(emailClientService.send(any())).thenCallRealMethod().thenCallMyCustomMethod(...)
我找到答案了!
Mockito.doAnswer((Answer<Object>) invocation -> {
invocation.callRealMethod(); // calling emailService.send()
callMyCustomMethod();
...
return null;
}).when(emailService).send(any());