1 19 20 21 22 package org.apache.james.core; 23 24 import junit.framework.TestCase; 25 26 import javax.mail.MessagingException ; 27 28 import org.apache.mailet.Mail; 29 30 33 public abstract class MailTestAllImplementations extends TestCase { 34 35 36 protected abstract Mail createMailImplementation(); 37 38 protected void helperTestInitialState(Mail mail) throws MessagingException { 39 assertFalse("no initial attributes", mail.hasAttributes()); 40 assertNull("no initial error", mail.getErrorMessage()); 41 assertNotNull("initial last update set", mail.getLastUpdated()); 42 try { 43 assertTrue("no initial recipient", mail.getRecipients().isEmpty()); 44 } catch (NullPointerException e) { 45 } 47 assertEquals("initial remote address is localhost ip", "127.0.0.1", mail.getRemoteAddr()); 48 assertEquals("initial remote host is localhost", "localhost", mail.getRemoteHost()); 49 assertEquals("default initial state", Mail.DEFAULT, mail.getState()); 50 } 51 52 protected void helperTestMessageSize(Mail mail, int expectedMsgSize) throws MessagingException { 53 try { 54 assertEquals("initial message size == " + expectedMsgSize, expectedMsgSize, mail.getMessageSize()); 55 } catch (NullPointerException e) { 56 } 58 } 59 60 public void testAttributes() { 61 Mail mail = createMailImplementation(); 62 assertFalse("no initial attributes", mail.hasAttributes()); 63 assertFalse("attributes initially empty", mail.getAttributeNames().hasNext()); 64 assertNull("not found on emtpy list", mail.getAttribute("test")); 65 assertNull("no previous item with key", mail.setAttribute("testKey", "testValue")); 66 assertEquals("item found", "testValue", mail.getAttribute("testKey")); 67 assertTrue("has attribute", mail.hasAttributes()); 68 assertEquals("item removed", "testValue", mail.removeAttribute("testKey")); 69 assertNull("item no longer found", mail.getAttribute("testKey")); 70 } 71 72 } 73 | Popular Tags |