1 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 ; 30 import java.util.ArrayList ; 31 32 public class MailImplTest extends MailTestAllImplementations { 33 34 protected Mail createMailImplementation() { 35 return new MailImpl(); 36 } 37 38 public void testConstr1() throws MessagingException { 39 MailImpl mail = new MailImpl(); 40 41 helperTestInitialState(mail); 42 helperTestMessageSize(mail, 0); 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 { 49 ArrayList recepients = new ArrayList (); 50 String name = MockMailServer.newId(); 51 String sender = "sender@localhost"; 52 MailAddress senderMailAddress = new MailAddress(sender); 53 MailImpl mail = new MailImpl(name, senderMailAddress, recepients); 54 55 helperTestInitialState(mail); helperTestMessageSize(mail, 0); 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 { 66 ArrayList recepients = new ArrayList (); 67 String name = MockMailServer.newId(); 68 String 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 { 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 { 90 String 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 |