I have spring boot 2.7 running project and junit-jupiter 5.8.2.
The code is running perfectly fine While writing Junit for the same facing problem.
While mocking TemplateEngine when(templateEngine.process(anyString(), any(Context.class))).thenReturn("Processed template");
I am getting InvalidUseOfMatcherException
I cannot use power mockito i cannot use in my org.
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);
}
i have tried to do like this agian i was getting cannot mock/spy final class
// Mocked email content
String mockedEmailContent = "Mocked email content";
when(templateEngine.process(eq("email-template"), any(Context.class))).thenReturn(mockedEmailContent);
Do we have a solution for this