Search in sources :

Example 1 with AddressException

use of jakarta.mail.internet.AddressException in project spring-framework by spring-projects.

the class JavaMailSenderTests method javaMailSenderWithParseExceptionOnSimpleMessage.

@Test
public void javaMailSenderWithParseExceptionOnSimpleMessage() {
    MockJavaMailSender sender = new MockJavaMailSender();
    SimpleMailMessage simpleMessage = new SimpleMailMessage();
    simpleMessage.setFrom("");
    try {
        sender.send(simpleMessage);
    } catch (MailParseException ex) {
        // expected
        boolean condition = ex.getCause() instanceof AddressException;
        assertThat(condition).isTrue();
    }
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) AddressException(jakarta.mail.internet.AddressException) MailParseException(org.springframework.mail.MailParseException) Test(org.junit.jupiter.api.Test)

Example 2 with AddressException

use of jakarta.mail.internet.AddressException in project spring-framework by spring-projects.

the class JavaMailSenderTests method javaMailSenderWithParseExceptionOnMimeMessagePreparator.

@Test
public void javaMailSenderWithParseExceptionOnMimeMessagePreparator() {
    MockJavaMailSender sender = new MockJavaMailSender();
    MimeMessagePreparator preparator = mimeMessage -> mimeMessage.setFrom(new InternetAddress(""));
    try {
        sender.send(preparator);
    } catch (MailParseException ex) {
        // expected
        boolean condition = ex.getCause() instanceof AddressException;
        assertThat(condition).isTrue();
    }
}
Also used : Arrays(java.util.Arrays) MailParseException(org.springframework.mail.MailParseException) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) FileTypeMap(jakarta.activation.FileTypeMap) AddressException(jakarta.mail.internet.AddressException) InternetAddress(jakarta.mail.internet.InternetAddress) MessagingException(jakarta.mail.MessagingException) MimeMessage(jakarta.mail.internet.MimeMessage) ArrayList(java.util.ArrayList) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Session(jakarta.mail.Session) Properties(java.util.Properties) GregorianCalendar(java.util.GregorianCalendar) NoSuchProviderException(jakarta.mail.NoSuchProviderException) ObjectUtils(org.springframework.util.ObjectUtils) IOException(java.io.IOException) Message(jakarta.mail.Message) Assertions.entry(org.assertj.core.api.Assertions.entry) URLName(jakarta.mail.URLName) Test(org.junit.jupiter.api.Test) List(java.util.List) MailSendException(org.springframework.mail.MailSendException) Transport(jakarta.mail.Transport) Address(jakarta.mail.Address) InternetAddress(jakarta.mail.internet.InternetAddress) AddressException(jakarta.mail.internet.AddressException) MailParseException(org.springframework.mail.MailParseException) Test(org.junit.jupiter.api.Test)

Aggregations

AddressException (jakarta.mail.internet.AddressException)2 Test (org.junit.jupiter.api.Test)2 MailParseException (org.springframework.mail.MailParseException)2 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)2 FileTypeMap (jakarta.activation.FileTypeMap)1 Address (jakarta.mail.Address)1 Message (jakarta.mail.Message)1 MessagingException (jakarta.mail.MessagingException)1 NoSuchProviderException (jakarta.mail.NoSuchProviderException)1 Session (jakarta.mail.Session)1 Transport (jakarta.mail.Transport)1 URLName (jakarta.mail.URLName)1 InternetAddress (jakarta.mail.internet.InternetAddress)1 MimeMessage (jakarta.mail.internet.MimeMessage)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 List (java.util.List)1