KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > core > MailImplTest


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, *
13  * software distributed under the License is distributed on an *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15  * KIND, either express or implied. See the License for the *
16  * specific language governing permissions and limitations *
17  * under the License. *
18  ****************************************************************/

19
20
21
22 package org.apache.james.core;
23
24 import org.apache.james.test.mock.james.MockMailServer;
25 import org.apache.james.test.mock.javaxmail.MockMimeMessage;
26 import org.apache.mailet.MailAddress;
27 import org.apache.mailet.Mail;
28
29 import javax.mail.MessagingException JavaDoc;
30 import java.util.ArrayList JavaDoc;
31
32 public class MailImplTest extends MailTestAllImplementations {
33
34     protected Mail createMailImplementation() {
35         return new MailImpl();
36     }
37
38     public void testConstr1() throws MessagingException JavaDoc {
39         MailImpl mail = new MailImpl();
40
41         helperTestInitialState(mail);
42         helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
43
assertNull("no initial message", mail.getMessage());
44         assertNull("no initial sender", mail.getSender());
45         assertNull("no initial name", mail.getName());
46     }
47
48     public void testConstr2() throws MessagingException JavaDoc {
49         ArrayList JavaDoc recepients = new ArrayList JavaDoc();
50         String JavaDoc name = MockMailServer.newId();
51         String JavaDoc sender = "sender@localhost";
52         MailAddress senderMailAddress = new MailAddress(sender);
53         MailImpl mail = new MailImpl(name, senderMailAddress, recepients);
54
55         helperTestInitialState(mail); // MimeMessageWrapper default is 0
56
helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
57
assertNull("no initial message", mail.getMessage());
58         assertEquals("sender", sender, mail.getSender().toString());
59         assertEquals("name", name, mail.getName());
60
61         mail.setMessage(new MockMimeMessage());
62         assertNotNull("message", mail.getMessage());
63     }
64
65     public void testConstr3() throws MessagingException JavaDoc {
66         ArrayList JavaDoc recepients = new ArrayList JavaDoc();
67         String JavaDoc name = MockMailServer.newId();
68         String JavaDoc sender = "sender@localhost";
69         MailAddress senderMailAddress = new MailAddress(sender);
70         MockMimeMessage mimeMessage = new MockMimeMessage();
71         MailImpl mail = new MailImpl(name, senderMailAddress, recepients, mimeMessage);
72
73         helperTestInitialState(mail);
74         helperTestMessageSize(mail, 0);
75         assertEquals("initial message", mimeMessage.getMessageID(), mail.getMessage().getMessageID());
76         assertEquals("sender", sender, mail.getSender().toString());
77         assertEquals("name", name, mail.getName());
78         mail.dispose();
79     }
80
81     public void testDuplicate() throws MessagingException JavaDoc {
82         MailImpl mail = new MailImpl();
83         MailImpl duplicate = (MailImpl) mail.duplicate();
84         assertNotSame("is real duplicate", mail, duplicate);
85         helperTestInitialState(duplicate);
86         helperTestMessageSize(duplicate, 0);
87     }
88
89     public void testDuplicateNewName() throws MessagingException JavaDoc {
90         String JavaDoc newName = "aNewName";
91         
92         MailImpl mail = new MailImpl();
93         assertFalse("before + after names differ", newName.equals(mail.getName()));
94         
95         MailImpl duplicate = (MailImpl) mail.duplicate(newName);
96         assertEquals("new name set", newName, duplicate.getName());
97         helperTestInitialState(duplicate);
98         helperTestMessageSize(duplicate, 0);
99     }
100 }
101
Popular Tags