I'm trying to stub an injected dependency upon its void method:
@Autowired
private FeedbackService service;
@MockBean
private MailSender sender;
@Test
public void testMonitor() {
// mocking MailSender#sendMessage
Mockito.doAnswer(invocation -> {
log.info("SUBJECT: {}", invocation.getArgument(0, String.class));
log.info("CONTENT: {}", invocation.getArgument(1, String.class));
for (String dest : (String[]) invocation.getArgument(2)) {
log.info("DEST: {}", dest);
}
return null; // Void anyway
}).when(sender).sendMessage(anyString(), anyString(), any(String[].class)); //FIXME still doNothing
// invoking the service which calls MailSender#sendMessage
service.monitor();
}
But logging and debugging shows that no interception occurs at runtime. Does anybody know what I'm doing wrong, please ?
Aucun commentaire:
Enregistrer un commentaire