我有springboot 2.7运行项目和junit jupiter 5.8.2。
在为同样的问题编写Junit时,代码运行得非常好。
嘲笑TemplateEngine时
when(templateEngine.process(anyString(), any(Context.class))).thenReturn("Processed template");
我得到InvalidUseOfMatcherException
我不能使用我不能在组织中使用的力量mockito。
public void sendEmail(File f, String name) throws MessagingException {
Context contaxt = new Context();
context.setVariable(âXâ, 1);
context.setVariable("Y", 2);
// Process the Thymeleaf template
String emailContent = templateEngine process(âemail-template", context);
MimeMessage message = emailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(â[email protected]â);
helper.setTo(fileName.equals(âx.csvâ) ? â[email protected]â : â[email protected]â);
helper.setCc(â[email protected]â);
helper.setSubject("Repoâ);
if(!fileName.equals(acceptFileName)){
helper.setText(emailContent,true);
ï½
else {
helper.setText("New Details");
}
helper.addAttachment (name, f);
emailSender.send(message);
}
我试过这样做,我得到了一个不能模拟/间谍的最后一堂课
// Mocked email content
String mockedEmailContent = "Mocked email content";
when(templateEngine.process(eq("email-template"), any(Context.class))).thenReturn(mockedEmailContent);
有办法解决这个问题吗