0

I'm trying to send an email when my batch job fails. I think I have everything but it keeps giving me a null pointer exception when I get to the send email line of my test class.

package utilities;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

@SpringBootTest
public class EmailTest {

@Autowired
JavaMailSender mailSender;

@Test
public void sendMail()
{
    SimpleMailMessage message = new SimpleMailMessage();
    message.setTo("test@test.com");
    message.setFrom("test@test.com");
    message.setSubject("Important email");
    message.setText("FATAL - Batch Job Failed crash. Please Re-Run your job");
    mailSender.send(message);
}

}

************************ The Email Properties ************************************

spring.mail.host=smtp-mail.outlook.com
spring.mail.port=587

spring.mail.username=

spring.mail.password=

spring.mail.properties.mail.protocol=smtp

spring.mail.properties.mail.tls=true

spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.ssl.trust=smtp-mail.outlook.com

It didn't like the @RunWith line. I think that isn't needed with Junit5. That said when I run it I get the below:

18:56:16.847 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [utilities.EmailTest], using SpringBootContextLoader 18:56:16.850 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [utilities.EmailTest]: class path resource [utilities/EmailTest-context.xml] does not exist 18:56:16.850 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [utilities.EmailTest]: class path resource [utilities/EmailTestContext.groovy] does not exist 18:56:16.850 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [utilities.EmailTest]: no resource found for suffixes {-context.xml, Context.groovy}. 18:56:16.851 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [utilities.EmailTest]: EmailTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration. 18:56:16.888 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [utilities.EmailTest]

skigdmg
  • 3
  • 3

0 Answers0