vendredi 4 mars 2016

DoThrow MailException with mockito

I have a class JavaMailDao that i want to test using JUnit and mockito. I want to test the Catch part

try {
            this.mailSender.send(msg);
    } catch(MailException ex) {
            throw new BackendException(DaoExceptionType.EMAIL_ERROR);
}

In the test i have this:

Mockito.doNothing().doThrow(new MailException()).when(this.mailSenderMock).send(Mockito.any(SimpleMailMessage.class));

The problem it's it says : "can't instantiate the type MailException", and i have the import too by the way.

mport org.springframework.mail.MailException;

Does anyone know how to do it? Thank you!

Aucun commentaire:

Enregistrer un commentaire