11/*
2- * Copyright 2002-2016 the original author or authors.
2+ * Copyright 2002-2018 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -56,6 +56,7 @@ public class JavaMailSenderTests {
5656 @ Rule
5757 public final ExpectedException thrown = ExpectedException .none ();
5858
59+
5960 @ Test
6061 public void javaMailSenderWithSimpleMessage () throws MessagingException , IOException {
6162 MockJavaMailSender sender = new MockJavaMailSender ();
@@ -68,8 +69,8 @@ public void javaMailSenderWithSimpleMessage() throws MessagingException, IOExcep
6869 simpleMessage .
setFrom (
"[email protected] " );
6970 simpleMessage .
setReplyTo (
"[email protected] " );
7071 simpleMessage .
setTo (
"[email protected] " );
71- simpleMessage .
setCc (
new String [] { "[email protected] " ,
"[email protected] " } );
72- simpleMessage .
setBcc (
new String [] { "[email protected] " ,
"[email protected] " } );
72+ 73+ 7374 Date sentDate = new GregorianCalendar (2004 , 1 , 1 ).getTime ();
7475 simpleMessage .setSentDate (sentDate );
7576 simpleMessage .setSubject ("my subject" );
@@ -105,7 +106,8 @@ public void javaMailSenderWithSimpleMessage() throws MessagingException, IOExcep
105106 assertEquals ("my text" , sentMessage .getContent ());
106107 }
107108
108- public void testJavaMailSenderWithSimpleMessages () throws MessagingException , IOException {
109+ @ Test
110+ public void javaMailSenderWithSimpleMessages () throws MessagingException {
109111 MockJavaMailSender sender = new MockJavaMailSender ();
110112 sender .setHost ("host" );
111113 sender .setUsername ("username" );
@@ -133,7 +135,8 @@ public void testJavaMailSenderWithSimpleMessages() throws MessagingException, IO
133135 assertEquals (
"[email protected] " , ((
InternetAddress )
tos2 .
get (
0 )).
getAddress ());
134136 }
135137
136- public void testJavaMailSenderWithMimeMessage () throws MessagingException {
138+ @ Test
139+ public void javaMailSenderWithMimeMessage () throws MessagingException {
137140 MockJavaMailSender sender = new MockJavaMailSender ();
138141 sender .setHost ("host" );
139142 sender .setUsername ("username" );
@@ -394,7 +397,7 @@ protected Transport getTransport(Session sess) throws NoSuchProviderException {
394397 }
395398
396399 @ Test
397- public void failedMailServerConnect () throws Exception {
400+ public void failedMailServerConnect () {
398401 MockJavaMailSender sender = new MockJavaMailSender ();
399402 sender .setHost (null );
400403 sender .setUsername ("username" );
@@ -415,7 +418,7 @@ public void failedMailServerConnect() throws Exception {
415418 }
416419
417420 @ Test
418- public void failedMailServerClose () throws Exception {
421+ public void failedMailServerClose () {
419422 MockJavaMailSender sender = new MockJavaMailSender ();
420423 sender .setHost ("" );
421424 sender .setUsername ("username" );
@@ -434,7 +437,7 @@ public void failedMailServerClose() throws Exception {
434437 }
435438
436439 @ Test
437- public void failedSimpleMessage () throws Exception {
440+ public void failedSimpleMessage () throws MessagingException {
438441 MockJavaMailSender sender = new MockJavaMailSender ();
439442 sender .setHost ("host" );
440443 sender .setUsername ("username" );
@@ -466,7 +469,7 @@ public void failedSimpleMessage() throws Exception {
466469 }
467470
468471 @ Test
469- public void fFailedMimeMessage () throws Exception {
472+ public void failedMimeMessage () throws MessagingException {
470473 MockJavaMailSender sender = new MockJavaMailSender ();
471474 sender .setHost ("host" );
472475 sender .setUsername ("username" );
@@ -498,14 +501,14 @@ public void fFailedMimeMessage() throws Exception {
498501 }
499502
500503 @ Test
501- public void testConnection () throws Exception {
504+ public void testConnection () throws MessagingException {
502505 MockJavaMailSender sender = new MockJavaMailSender ();
503506 sender .setHost ("host" );
504507 sender .testConnection ();
505508 }
506509
507510 @ Test
508- public void testConnectionWithFailure () throws Exception {
511+ public void testConnectionWithFailure () throws MessagingException {
509512 MockJavaMailSender sender = new MockJavaMailSender ();
510513 sender .setHost (null );
511514
@@ -592,7 +595,8 @@ public void sendMessage(Message message, Address[] addresses) throws MessagingEx
592595 if ("fail" .equals (message .getSubject ())) {
593596 throw new MessagingException ("failed" );
594597 }
595- if (!ObjectUtils .nullSafeEquals (addresses , message .getAllRecipients ())) {
598+ if (addresses == null || (message .getAllRecipients () == null ? addresses .length > 0 :
599+ !ObjectUtils .nullSafeEquals (addresses , message .getAllRecipients ()))) {
596600 throw new MessagingException ("addresses not correct" );
597601 }
598602 if (message .getSentDate () == null ) {
0 commit comments