KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > mail > javamail > JavaMailSenderTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.mail.javamail;
18
19 import java.io.IOException JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.Arrays JavaDoc;
22 import java.util.Date JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Properties JavaDoc;
25
26 import javax.activation.FileTypeMap JavaDoc;
27 import javax.mail.Address JavaDoc;
28 import javax.mail.Message JavaDoc;
29 import javax.mail.MessagingException JavaDoc;
30 import javax.mail.NoSuchProviderException JavaDoc;
31 import javax.mail.Session JavaDoc;
32 import javax.mail.Transport JavaDoc;
33 import javax.mail.URLName JavaDoc;
34 import javax.mail.internet.AddressException JavaDoc;
35 import javax.mail.internet.InternetAddress JavaDoc;
36 import javax.mail.internet.MimeMessage JavaDoc;
37
38 import junit.framework.TestCase;
39
40 import org.springframework.mail.MailParseException;
41 import org.springframework.mail.MailSendException;
42 import org.springframework.mail.SimpleMailMessage;
43
44 /**
45  * @author Juergen Hoeller
46  * @since 09.10.2004
47  */

48 public class JavaMailSenderTests extends TestCase {
49
50     public void testJavaMailSenderWithSimpleMessage() throws MessagingException JavaDoc, IOException JavaDoc {
51         MockJavaMailSender sender = new MockJavaMailSender();
52         sender.setHost("host");
53         sender.setPort(30);
54         sender.setUsername("username");
55         sender.setPassword("password");
56
57         SimpleMailMessage simpleMessage = new SimpleMailMessage();
58         simpleMessage.setFrom("me@mail.org");
59         simpleMessage.setReplyTo("reply@mail.org");
60         simpleMessage.setTo("you@mail.org");
61         simpleMessage.setCc(new String JavaDoc[] {"he@mail.org", "she@mail.org"});
62         simpleMessage.setBcc(new String JavaDoc[] {"us@mail.org", "them@mail.org"});
63         Date JavaDoc sentDate = new Date JavaDoc(2004, 1, 1);
64         simpleMessage.setSentDate(sentDate);
65         simpleMessage.setSubject("my subject");
66         simpleMessage.setText("my text");
67         sender.send(simpleMessage);
68
69         assertEquals("host", sender.transport.getConnectedHost());
70         assertEquals(30, sender.transport.getConnectedPort());
71         assertEquals("username", sender.transport.getConnectedUsername());
72         assertEquals("password", sender.transport.getConnectedPassword());
73         assertTrue(sender.transport.isCloseCalled());
74
75         assertEquals(1, sender.transport.getSentMessages().size());
76         MimeMessage JavaDoc sentMessage = sender.transport.getSentMessage(0);
77         List JavaDoc froms = Arrays.asList(sentMessage.getFrom());
78         assertEquals(1, froms.size());
79         assertEquals("me@mail.org", ((InternetAddress JavaDoc) froms.get(0)).getAddress());
80         List JavaDoc replyTos = Arrays.asList(sentMessage.getReplyTo());
81         assertEquals("reply@mail.org", ((InternetAddress JavaDoc) replyTos.get(0)).getAddress());
82         List JavaDoc tos = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.TO));
83         assertEquals(1, tos.size());
84         assertEquals("you@mail.org", ((InternetAddress JavaDoc) tos.get(0)).getAddress());
85         List JavaDoc ccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.CC));
86         assertEquals(2, ccs.size());
87         assertEquals("he@mail.org", ((InternetAddress JavaDoc) ccs.get(0)).getAddress());
88         assertEquals("she@mail.org", ((InternetAddress JavaDoc) ccs.get(1)).getAddress());
89         List JavaDoc bccs = Arrays.asList(sentMessage.getRecipients(Message.RecipientType.BCC));
90         assertEquals(2, bccs.size());
91         assertEquals("us@mail.org", ((InternetAddress JavaDoc) bccs.get(0)).getAddress());
92         assertEquals("them@mail.org", ((InternetAddress JavaDoc) bccs.get(1)).getAddress());
93         assertEquals(sentDate.getTime(), sentMessage.getSentDate().getTime());
94         assertEquals("my subject", sentMessage.getSubject());
95         assertEquals("my text", sentMessage.getContent());
96     }
97
98     public void testJavaMailSenderWithSimpleMessages() throws MessagingException JavaDoc, IOException JavaDoc {
99         MockJavaMailSender sender = new MockJavaMailSender();
100         sender.setHost("host");
101         sender.setUsername("username");
102         sender.setPassword("password");
103
104         SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
105         simpleMessage1.setTo("he@mail.org");
106         SimpleMailMessage simpleMessage2 = new SimpleMailMessage();
107         simpleMessage2.setTo("she@mail.org");
108         sender.send(new SimpleMailMessage[] {simpleMessage1, simpleMessage2});
109
110         assertEquals(sender.transport.getConnectedHost(), "host");
111         assertEquals(sender.transport.getConnectedUsername(), "username");
112         assertEquals(sender.transport.getConnectedPassword(), "password");
113         assertTrue(sender.transport.isCloseCalled());
114
115         assertEquals(2, sender.transport.getSentMessages().size());
116         MimeMessage JavaDoc sentMessage1 = sender.transport.getSentMessage(0);
117         List JavaDoc tos1 = Arrays.asList(sentMessage1.getRecipients(Message.RecipientType.TO));
118         assertEquals(1, tos1.size());
119         assertEquals("he@mail.org", ((InternetAddress JavaDoc) tos1.get(0)).getAddress());
120         MimeMessage JavaDoc sentMessage2 = sender.transport.getSentMessage(1);
121         List JavaDoc tos2 = Arrays.asList(sentMessage2.getRecipients(Message.RecipientType.TO));
122         assertEquals(1, tos2.size());
123         assertEquals("she@mail.org", ((InternetAddress JavaDoc) tos2.get(0)).getAddress());
124     }
125
126     public void testJavaMailSenderWithMimeMessage() throws MessagingException JavaDoc {
127         MockJavaMailSender sender = new MockJavaMailSender();
128         sender.setHost("host");
129         sender.setUsername("username");
130         sender.setPassword("password");
131
132         MimeMessage JavaDoc mimeMessage = sender.createMimeMessage();
133         mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress JavaDoc("you@mail.org"));
134         sender.send(mimeMessage);
135
136         assertEquals(sender.transport.getConnectedHost(), "host");
137         assertEquals(sender.transport.getConnectedUsername(), "username");
138         assertEquals(sender.transport.getConnectedPassword(), "password");
139         assertTrue(sender.transport.isCloseCalled());
140         assertEquals(1, sender.transport.getSentMessages().size());
141         assertEquals(mimeMessage, sender.transport.getSentMessage(0));
142     }
143
144     public void testJavaMailSenderWithMimeMessages() throws MessagingException JavaDoc {
145         MockJavaMailSender sender = new MockJavaMailSender();
146         sender.setHost("host");
147         sender.setUsername("username");
148         sender.setPassword("password");
149
150         MimeMessage JavaDoc mimeMessage1 = sender.createMimeMessage();
151         mimeMessage1.setRecipient(Message.RecipientType.TO, new InternetAddress JavaDoc("he@mail.org"));
152         MimeMessage JavaDoc mimeMessage2 = sender.createMimeMessage();
153         mimeMessage2.setRecipient(Message.RecipientType.TO, new InternetAddress JavaDoc("she@mail.org"));
154         sender.send(new MimeMessage JavaDoc[] {mimeMessage1, mimeMessage2});
155
156         assertEquals(sender.transport.getConnectedHost(), "host");
157         assertEquals(sender.transport.getConnectedUsername(), "username");
158         assertEquals(sender.transport.getConnectedPassword(), "password");
159         assertTrue(sender.transport.isCloseCalled());
160         assertEquals(2, sender.transport.getSentMessages().size());
161         assertEquals(mimeMessage1, sender.transport.getSentMessage(0));
162         assertEquals(mimeMessage2, sender.transport.getSentMessage(1));
163     }
164
165     public void testJavaMailSenderWithMimeMessagePreparator() {
166         MockJavaMailSender sender = new MockJavaMailSender();
167         sender.setHost("host");
168         sender.setUsername("username");
169         sender.setPassword("password");
170
171         final List JavaDoc messages = new ArrayList JavaDoc();
172
173         MimeMessagePreparator preparator = new MimeMessagePreparator() {
174             public void prepare(MimeMessage JavaDoc mimeMessage) throws MessagingException JavaDoc {
175                 mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress JavaDoc("you@mail.org"));
176                 messages.add(mimeMessage);
177             }
178         };
179         sender.send(preparator);
180
181         assertEquals(sender.transport.getConnectedHost(), "host");
182         assertEquals(sender.transport.getConnectedUsername(), "username");
183         assertEquals(sender.transport.getConnectedPassword(), "password");
184         assertTrue(sender.transport.isCloseCalled());
185         assertEquals(1, sender.transport.getSentMessages().size());
186         assertEquals(messages.get(0), sender.transport.getSentMessage(0));
187     }
188
189     public void testJavaMailSenderWithMimeMessagePreparators() {
190         MockJavaMailSender sender = new MockJavaMailSender();
191         sender.setHost("host");
192         sender.setUsername("username");
193         sender.setPassword("password");
194
195         final List JavaDoc messages = new ArrayList JavaDoc();
196
197         MimeMessagePreparator preparator1 = new MimeMessagePreparator() {
198             public void prepare(MimeMessage JavaDoc mimeMessage) throws MessagingException JavaDoc {
199                 mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress JavaDoc("he@mail.org"));
200                 messages.add(mimeMessage);
201             }
202         };
203         MimeMessagePreparator preparator2 = new MimeMessagePreparator() {
204             public void prepare(MimeMessage JavaDoc mimeMessage) throws MessagingException JavaDoc {
205                 mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress JavaDoc("she@mail.org"));
206                 messages.add(mimeMessage);
207             }
208         };
209         sender.send(new MimeMessagePreparator[] {preparator1, preparator2});
210
211         assertEquals(sender.transport.getConnectedHost(), "host");
212         assertEquals(sender.transport.getConnectedUsername(), "username");
213         assertEquals(sender.transport.getConnectedPassword(), "password");
214         assertTrue(sender.transport.isCloseCalled());
215         assertEquals(2, sender.transport.getSentMessages().size());
216         assertEquals(messages.get(0), sender.transport.getSentMessage(0));
217         assertEquals(messages.get(1), sender.transport.getSentMessage(1));
218     }
219
220     public void testJavaMailSenderWithMimeMessageHelper() throws MessagingException JavaDoc {
221         MockJavaMailSender sender = new MockJavaMailSender();
222         sender.setHost("host");
223         sender.setUsername("username");
224         sender.setPassword("password");
225
226         MimeMessageHelper message = new MimeMessageHelper(sender.createMimeMessage());
227         assertNull(message.getEncoding());
228         assertTrue(message.getFileTypeMap() instanceof ConfigurableMimeFileTypeMap);
229
230         message.setTo("you@mail.org");
231         sender.send(message.getMimeMessage());
232
233         assertEquals(sender.transport.getConnectedHost(), "host");
234         assertEquals(sender.transport.getConnectedUsername(), "username");
235         assertEquals(sender.transport.getConnectedPassword(), "password");
236         assertTrue(sender.transport.isCloseCalled());
237         assertEquals(1, sender.transport.getSentMessages().size());
238         assertEquals(message.getMimeMessage(), sender.transport.getSentMessage(0));
239     }
240
241     public void testJavaMailSenderWithMimeMessageHelperAndSpecificEncoding() throws MessagingException JavaDoc {
242         MockJavaMailSender sender = new MockJavaMailSender();
243         sender.setHost("host");
244         sender.setUsername("username");
245         sender.setPassword("password");
246
247         MimeMessageHelper message = new MimeMessageHelper(sender.createMimeMessage(), "UTF-8");
248         assertEquals("UTF-8", message.getEncoding());
249         FileTypeMap JavaDoc fileTypeMap = new ConfigurableMimeFileTypeMap();
250         message.setFileTypeMap(fileTypeMap);
251         assertEquals(fileTypeMap, message.getFileTypeMap());
252
253         message.setTo("you@mail.org");
254         sender.send(message.getMimeMessage());
255
256         assertEquals(sender.transport.getConnectedHost(), "host");
257         assertEquals(sender.transport.getConnectedUsername(), "username");
258         assertEquals(sender.transport.getConnectedPassword(), "password");
259         assertTrue(sender.transport.isCloseCalled());
260         assertEquals(1, sender.transport.getSentMessages().size());
261         assertEquals(message.getMimeMessage(), sender.transport.getSentMessage(0));
262     }
263
264     public void testJavaMailSenderWithMimeMessageHelperAndDefaultEncoding() throws MessagingException JavaDoc {
265         MockJavaMailSender sender = new MockJavaMailSender();
266         sender.setHost("host");
267         sender.setUsername("username");
268         sender.setPassword("password");
269         sender.setDefaultEncoding("UTF-8");
270
271         FileTypeMap JavaDoc fileTypeMap = new ConfigurableMimeFileTypeMap();
272         sender.setDefaultFileTypeMap(fileTypeMap);
273         MimeMessageHelper message = new MimeMessageHelper(sender.createMimeMessage());
274         assertEquals("UTF-8", message.getEncoding());
275         assertEquals(fileTypeMap, message.getFileTypeMap());
276
277         message.setTo("you@mail.org");
278         sender.send(message.getMimeMessage());
279
280         assertEquals(sender.transport.getConnectedHost(), "host");
281         assertEquals(sender.transport.getConnectedUsername(), "username");
282         assertEquals(sender.transport.getConnectedPassword(), "password");
283         assertTrue(sender.transport.isCloseCalled());
284         assertEquals(1, sender.transport.getSentMessages().size());
285         assertEquals(message.getMimeMessage(), sender.transport.getSentMessage(0));
286     }
287
288     public void testJavaMailSenderWithParseExceptionOnSimpleMessage() {
289         MockJavaMailSender sender = new MockJavaMailSender();
290         SimpleMailMessage simpleMessage = new SimpleMailMessage();
291         simpleMessage.setFrom("");
292         try {
293             sender.send(simpleMessage);
294         }
295         catch (MailParseException ex) {
296             // expected
297
assertTrue(ex.getCause() instanceof AddressException JavaDoc);
298         }
299     }
300
301     public void testJavaMailSenderWithParseExceptionOnMimeMessagePreparator() {
302         MockJavaMailSender sender = new MockJavaMailSender();
303         MimeMessagePreparator preparator = new MimeMessagePreparator() {
304             public void prepare(MimeMessage JavaDoc mimeMessage) throws MessagingException JavaDoc {
305                 mimeMessage.setFrom(new InternetAddress JavaDoc(""));
306             }
307         };
308         try {
309             sender.send(preparator);
310         }
311         catch (MailParseException ex) {
312             // expected
313
assertTrue(ex.getCause() instanceof AddressException JavaDoc);
314         }
315     }
316
317     public void testJavaMailSenderWithCustomSession() throws MessagingException JavaDoc {
318         final Session JavaDoc session = Session.getInstance(new Properties JavaDoc());
319         MockJavaMailSender sender = new MockJavaMailSender() {
320             protected Transport JavaDoc getTransport(Session JavaDoc sess) throws NoSuchProviderException JavaDoc {
321                 assertEquals(session, sess);
322                 return super.getTransport(sess);
323             }
324         };
325         sender.setSession(session);
326         sender.setHost("host");
327         sender.setUsername("username");
328         sender.setPassword("password");
329
330         MimeMessage JavaDoc mimeMessage = sender.createMimeMessage();
331         mimeMessage.setSubject("custom");
332         mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress JavaDoc("you@mail.org"));
333         mimeMessage.setSentDate(new Date JavaDoc(2005, 3, 1));
334         sender.send(mimeMessage);
335
336         assertEquals(sender.transport.getConnectedHost(), "host");
337         assertEquals(sender.transport.getConnectedUsername(), "username");
338         assertEquals(sender.transport.getConnectedPassword(), "password");
339         assertTrue(sender.transport.isCloseCalled());
340         assertEquals(1, sender.transport.getSentMessages().size());
341         assertEquals(mimeMessage, sender.transport.getSentMessage(0));
342     }
343
344     public void testJavaMailProperties() throws MessagingException JavaDoc {
345         Properties JavaDoc props = new Properties JavaDoc();
346         props.setProperty("bogusKey", "bogusValue");
347         MockJavaMailSender sender = new MockJavaMailSender() {
348             protected Transport JavaDoc getTransport(Session JavaDoc sess) throws NoSuchProviderException JavaDoc {
349                 assertEquals("bogusValue", sess.getProperty("bogusKey"));
350                 return super.getTransport(sess);
351             }
352         };
353         sender.setJavaMailProperties(props);
354         sender.setHost("host");
355         sender.setUsername("username");
356         sender.setPassword("password");
357
358         MimeMessage JavaDoc mimeMessage = sender.createMimeMessage();
359         mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress JavaDoc("you@mail.org"));
360         sender.send(mimeMessage);
361
362         assertEquals(sender.transport.getConnectedHost(), "host");
363         assertEquals(sender.transport.getConnectedUsername(), "username");
364         assertEquals(sender.transport.getConnectedPassword(), "password");
365         assertTrue(sender.transport.isCloseCalled());
366         assertEquals(1, sender.transport.getSentMessages().size());
367         assertEquals(mimeMessage, sender.transport.getSentMessage(0));
368     }
369
370     public void testFailedMailServerConnect() throws Exception JavaDoc {
371         MockJavaMailSender sender = new MockJavaMailSender();
372         sender.setHost(null);
373         sender.setUsername("username");
374         sender.setPassword("password");
375         SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
376         try {
377             sender.send(simpleMessage1);
378             fail("Should have thrown MailSendException");
379         }
380         catch (MailSendException ex) {
381             // expected
382
assertTrue(ex.getFailedMessages() != null);
383             assertTrue(ex.getFailedMessages().isEmpty());
384         }
385     }
386
387     public void testFailedSimpleMessage() throws Exception JavaDoc {
388         MockJavaMailSender sender = new MockJavaMailSender();
389         sender.setHost("host");
390         sender.setUsername("username");
391         sender.setPassword("password");
392
393         SimpleMailMessage simpleMessage1 = new SimpleMailMessage();
394         simpleMessage1.setTo("he@mail.org");
395         simpleMessage1.setSubject("fail");
396         SimpleMailMessage simpleMessage2 = new SimpleMailMessage();
397         simpleMessage2.setTo("she@mail.org");
398
399         try {
400             sender.send(new SimpleMailMessage[] {simpleMessage1, simpleMessage2});
401         }
402         catch (MailSendException ex) {
403             assertEquals(sender.transport.getConnectedHost(), "host");
404             assertEquals(sender.transport.getConnectedUsername(), "username");
405             assertEquals(sender.transport.getConnectedPassword(), "password");
406             assertTrue(sender.transport.isCloseCalled());
407             assertEquals(1, sender.transport.getSentMessages().size());
408             assertEquals(new InternetAddress JavaDoc("she@mail.org"), sender.transport.getSentMessage(0).getAllRecipients()[0]);
409             assertEquals(1, ex.getFailedMessages().size());
410             assertEquals(simpleMessage1, ex.getFailedMessages().keySet().iterator().next());
411             Object JavaDoc subEx = ex.getFailedMessages().values().iterator().next();
412             assertTrue(subEx instanceof MessagingException JavaDoc);
413             assertEquals("failed", ((MessagingException JavaDoc) subEx).getMessage());
414         }
415     }
416
417     public void testFailedMimeMessage() throws Exception JavaDoc {
418         MockJavaMailSender sender = new MockJavaMailSender();
419         sender.setHost("host");
420         sender.setUsername("username");
421         sender.setPassword("password");
422
423         MimeMessage JavaDoc mimeMessage1 = sender.createMimeMessage();
424         mimeMessage1.setRecipient(Message.RecipientType.TO, new InternetAddress JavaDoc("he@mail.org"));
425         mimeMessage1.setSubject("fail");
426         MimeMessage JavaDoc mimeMessage2 = sender.createMimeMessage();
427         mimeMessage2.setRecipient(Message.RecipientType.TO, new InternetAddress JavaDoc("she@mail.org"));
428
429         try {
430             sender.send(new MimeMessage JavaDoc[] {mimeMessage1, mimeMessage2});
431         }
432         catch (MailSendException ex) {
433             assertEquals(sender.transport.getConnectedHost(), "host");
434             assertEquals(sender.transport.getConnectedUsername(), "username");
435             assertEquals(sender.transport.getConnectedPassword(), "password");
436             assertTrue(sender.transport.isCloseCalled());
437             assertEquals(1, sender.transport.getSentMessages().size());
438             assertEquals(mimeMessage2, sender.transport.getSentMessage(0));
439             assertEquals(1, ex.getFailedMessages().size());
440             assertEquals(mimeMessage1, ex.getFailedMessages().keySet().iterator().next());
441             Object JavaDoc subEx = ex.getFailedMessages().values().iterator().next();
442             assertTrue(subEx instanceof MessagingException JavaDoc);
443             assertEquals("failed", ((MessagingException JavaDoc) subEx).getMessage());
444         }
445     }
446
447
448     private static class MockJavaMailSender extends JavaMailSenderImpl {
449
450         private MockTransport transport;
451
452         protected Transport JavaDoc getTransport(Session JavaDoc session) throws NoSuchProviderException JavaDoc {
453             this.transport = new MockTransport(session, null);
454             return transport;
455         }
456     }
457
458
459     private static class MockTransport extends Transport JavaDoc {
460
461         private String JavaDoc connectedHost = null;
462         private int connectedPort = -2;
463         private String JavaDoc connectedUsername = null;
464         private String JavaDoc connectedPassword = null;
465         private boolean closeCalled = false;
466         private List JavaDoc sentMessages = new ArrayList JavaDoc();
467
468         public MockTransport(Session JavaDoc session, URLName JavaDoc urlName) {
469             super(session, urlName);
470         }
471
472         public String JavaDoc getConnectedHost() {
473             return connectedHost;
474         }
475
476         public int getConnectedPort() {
477             return connectedPort;
478         }
479
480         public String JavaDoc getConnectedUsername() {
481             return connectedUsername;
482         }
483
484         public String JavaDoc getConnectedPassword() {
485             return connectedPassword;
486         }
487
488         public boolean isCloseCalled() {
489             return closeCalled;
490         }
491
492         public List JavaDoc getSentMessages() {
493             return sentMessages;
494         }
495
496         public MimeMessage JavaDoc getSentMessage(int index) {
497             return (MimeMessage JavaDoc) this.sentMessages.get(index);
498         }
499
500         public void connect(String JavaDoc host, int port, String JavaDoc username, String JavaDoc password) throws MessagingException JavaDoc {
501             if (host == null) {
502                 throw new MessagingException JavaDoc("no host");
503             }
504             this.connectedHost = host;
505             this.connectedPort = port;
506             this.connectedUsername = username;
507             this.connectedPassword = password;
508         }
509
510         public synchronized void close() throws MessagingException JavaDoc {
511             this.closeCalled = true;
512         }
513
514         public void sendMessage(Message JavaDoc message, Address JavaDoc[] addresses) throws MessagingException JavaDoc {
515             if ("fail".equals(message.getSubject())) {
516                 throw new MessagingException JavaDoc("failed");
517             }
518             List JavaDoc addr1 = Arrays.asList(message.getAllRecipients());
519             List JavaDoc addr2 = Arrays.asList(addresses);
520             if (!addr1.equals(addr2)) {
521                 throw new MessagingException JavaDoc("addresses not correct");
522             }
523             if (message.getSentDate() == null) {
524                 throw new MessagingException JavaDoc("No sentDate specified");
525             }
526             if (message.getSubject() != null && message.getSubject().indexOf("custom") != -1) {
527                 assertEquals(new Date JavaDoc(2005, 3, 1), message.getSentDate());
528             }
529             this.sentMessages.add(message);
530         }
531     }
532
533 }
534
Popular Tags