james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ieu...@apache.org
Subject svn commit: r1299494 - /james/server/trunk/core/src/test/java/org/apache/james/core/
Date Mon, 12 Mar 2012 00:03:04 GMT
Author: ieugen
Date: Mon Mar 12 00:03:03 2012
New Revision: 1299494

URL: http://svn.apache.org/viewvc?rev=1299494&view=rev
Log:
JAMES-1393

- updated tests to juni 4.x style
- added @Override and reformated code
Issue #JAMES-1393 - Upgrate all test suites to junit 4.10

Modified:
    james/server/trunk/core/src/test/java/org/apache/james/core/MailHeadersTest.java
    james/server/trunk/core/src/test/java/org/apache/james/core/MailImplTest.java
    james/server/trunk/core/src/test/java/org/apache/james/core/MailTestAllImplementations.java
    james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java
    james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromMimeMessageTest.java
    james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromSharedStreamTest.java
    james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromStreamTest.java
    james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageTest.java
    james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageUtilTest.java
    james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageWrapperTest.java

Modified: james/server/trunk/core/src/test/java/org/apache/james/core/MailHeadersTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core/src/test/java/org/apache/james/core/MailHeadersTest.java?rev=1299494&r1=1299493&r2=1299494&view=diff
==============================================================================
--- james/server/trunk/core/src/test/java/org/apache/james/core/MailHeadersTest.java (original)
+++ james/server/trunk/core/src/test/java/org/apache/james/core/MailHeadersTest.java Mon Mar 12 00:03:03 2012
@@ -16,28 +16,27 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
 package org.apache.james.core;
 
-import org.apache.mailet.base.RFC2822Headers;
-
-import javax.mail.MessagingException;
-
 import java.io.ByteArrayInputStream;
 import java.util.Enumeration;
+import javax.mail.MessagingException;
+import org.apache.mailet.base.RFC2822Headers;
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
 
-import junit.framework.TestCase;
-
-public class MailHeadersTest extends TestCase {
+public class MailHeadersTest {
 
+    @Test
     public void testHeadersOrder() throws MessagingException {
-        MailHeaders header = new MailHeaders(new ByteArrayInputStream((RFC2822Headers.SUBJECT + ": testsubject\r\n").getBytes()));
-        header.setHeader(RFC2822Headers.RETURN_PATH, "<test@test>");
-        header.setHeader(RFC2822Headers.FROM, "<test2@test.de>");
-        Enumeration h = header.getAllHeaderLines();
-
-        assertEquals(h.nextElement(), "Return-Path: <test@test>");
-        assertEquals(h.nextElement(), "From: <test2@test.de>");
-        assertEquals(h.nextElement(), "Subject: testsubject");
+	MailHeaders header = new MailHeaders(new ByteArrayInputStream((RFC2822Headers.SUBJECT + ": testsubject\r\n").
+		getBytes()));
+	header.setHeader(RFC2822Headers.RETURN_PATH, "<test@test>");
+	header.setHeader(RFC2822Headers.FROM, "<test2@test.de>");
+	Enumeration h = header.getAllHeaderLines();
+
+	assertEquals(h.nextElement(), "Return-Path: <test@test>");
+	assertEquals(h.nextElement(), "From: <test2@test.de>");
+	assertEquals(h.nextElement(), "Subject: testsubject");
     }
 }

Modified: james/server/trunk/core/src/test/java/org/apache/james/core/MailImplTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core/src/test/java/org/apache/james/core/MailImplTest.java?rev=1299494&r1=1299493&r2=1299494&view=diff
==============================================================================
--- james/server/trunk/core/src/test/java/org/apache/james/core/MailImplTest.java (original)
+++ james/server/trunk/core/src/test/java/org/apache/james/core/MailImplTest.java Mon Mar 12 00:03:03 2012
@@ -16,7 +16,6 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
 package org.apache.james.core;
 
 import org.apache.mailet.base.test.FakeMimeMessage;
@@ -26,73 +25,81 @@ import org.apache.mailet.Mail;
 
 import javax.mail.MessagingException;
 import java.util.ArrayList;
+import static org.junit.Assert.*;
+import org.junit.Test;
 
 public class MailImplTest extends MailTestAllImplementations {
 
+    @Override
     protected Mail createMailImplementation() {
-        return new MailImpl();
+	return new MailImpl();
     }
 
+    @Test
     public void testConstr1() throws MessagingException {
-        MailImpl mail = new MailImpl();
+	MailImpl mail = new MailImpl();
 
-        helperTestInitialState(mail);
-        helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
-        assertNull("no initial message", mail.getMessage());
-        assertNull("no initial sender", mail.getSender());
-        assertNull("no initial name", mail.getName());
+	helperTestInitialState(mail);
+	helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
+	assertNull("no initial message", mail.getMessage());
+	assertNull("no initial sender", mail.getSender());
+	assertNull("no initial name", mail.getName());
     }
 
+    @Test
     public void testConstr2() throws MessagingException {
-        ArrayList recepients = new ArrayList();
-        String name = MailUtil.newId();
-        String sender = "sender@localhost";
-        MailAddress senderMailAddress = new MailAddress(sender);
-        MailImpl mail = new MailImpl(name, senderMailAddress, recepients);
-
-        helperTestInitialState(mail); // MimeMessageWrapper default is 0
-        helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
-        assertNull("no initial message", mail.getMessage());
-        assertEquals("sender", sender, mail.getSender().toString());
-        assertEquals("name", name, mail.getName());
+	ArrayList recepients = new ArrayList();
+	String name = MailUtil.newId();
+	String sender = "sender@localhost";
+	MailAddress senderMailAddress = new MailAddress(sender);
+	MailImpl mail = new MailImpl(name, senderMailAddress, recepients);
+
+	helperTestInitialState(mail); // MimeMessageWrapper default is 0
+	helperTestMessageSize(mail, 0); // MimeMessageWrapper default is 0
+	assertNull("no initial message", mail.getMessage());
+	assertEquals("sender", sender, mail.getSender().toString());
+	assertEquals("name", name, mail.getName());
 
-        mail.setMessage(new FakeMimeMessage());
-        assertNotNull("message", mail.getMessage());
+	mail.setMessage(new FakeMimeMessage());
+	assertNotNull("message", mail.getMessage());
     }
 
+    @Test
     public void testConstr3() throws MessagingException {
-        ArrayList recepients = new ArrayList();
-        String name = MailUtil.newId();
-        String sender = "sender@localhost";
-        MailAddress senderMailAddress = new MailAddress(sender);
-        FakeMimeMessage mimeMessage = new FakeMimeMessage();
-        MailImpl mail = new MailImpl(name, senderMailAddress, recepients, mimeMessage);
-
-        helperTestInitialState(mail);
-        helperTestMessageSize(mail, 0);
-        assertEquals("initial message", mimeMessage.getMessageID(), mail.getMessage().getMessageID());
-        assertEquals("sender", sender, mail.getSender().toString());
-        assertEquals("name", name, mail.getName());
-        mail.dispose();
+	ArrayList recepients = new ArrayList();
+	String name = MailUtil.newId();
+	String sender = "sender@localhost";
+	MailAddress senderMailAddress = new MailAddress(sender);
+	FakeMimeMessage mimeMessage = new FakeMimeMessage();
+	MailImpl mail = new MailImpl(name, senderMailAddress, recepients, mimeMessage);
+
+	helperTestInitialState(mail);
+	helperTestMessageSize(mail, 0);
+	assertEquals("initial message", mimeMessage.getMessageID(), mail.getMessage().getMessageID());
+	assertEquals("sender", sender, mail.getSender().toString());
+	assertEquals("name", name, mail.getName());
+	mail.dispose();
     }
 
+    @Test
     public void testDuplicate() throws MessagingException {
-        MailImpl mail = new MailImpl();
-        MailImpl duplicate = (MailImpl) mail.duplicate();
-        assertNotSame("is real duplicate", mail, duplicate);
-        helperTestInitialState(duplicate);
-        helperTestMessageSize(duplicate, 0);
+	MailImpl mail = new MailImpl();
+	MailImpl duplicate = (MailImpl) mail.duplicate();
+	assertNotSame("is real duplicate", mail, duplicate);
+	helperTestInitialState(duplicate);
+	helperTestMessageSize(duplicate, 0);
     }
 
+    @Test
     public void testDuplicateNewName() throws MessagingException {
-        String newName = "aNewName";
+	String newName = "aNewName";
 
-        MailImpl mail = new MailImpl();
-        assertFalse("before + after names differ", newName.equals(mail.getName()));
+	MailImpl mail = new MailImpl();
+	assertFalse("before + after names differ", newName.equals(mail.getName()));
 
-        MailImpl duplicate = (MailImpl) mail.duplicate(newName);
-        assertEquals("new name set", newName, duplicate.getName());
-        helperTestInitialState(duplicate);
-        helperTestMessageSize(duplicate, 0);
+	MailImpl duplicate = (MailImpl) mail.duplicate(newName);
+	assertEquals("new name set", newName, duplicate.getName());
+	helperTestInitialState(duplicate);
+	helperTestMessageSize(duplicate, 0);
     }
 }

Modified: james/server/trunk/core/src/test/java/org/apache/james/core/MailTestAllImplementations.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core/src/test/java/org/apache/james/core/MailTestAllImplementations.java?rev=1299494&r1=1299493&r2=1299494&view=diff
==============================================================================
--- james/server/trunk/core/src/test/java/org/apache/james/core/MailTestAllImplementations.java (original)
+++ james/server/trunk/core/src/test/java/org/apache/james/core/MailTestAllImplementations.java Mon Mar 12 00:03:03 2012
@@ -16,58 +16,57 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
 package org.apache.james.core;
 
-import junit.framework.TestCase;
-
 import javax.mail.MessagingException;
 
 import org.apache.mailet.Mail;
+import org.junit.Test;
+import static org.junit.Assert.*;
 
 /**
  * testing common behavior of Mail implementors. subclasses automatically get
  * their Mail-behavior tested.
  */
-public abstract class MailTestAllImplementations extends TestCase {
+public abstract class MailTestAllImplementations {
 
     /** provide the concrete implementation to test */
     protected abstract Mail createMailImplementation();
 
     protected void helperTestInitialState(Mail mail) throws MessagingException {
-        assertFalse("no initial attributes", mail.hasAttributes());
-        assertNull("no initial error", mail.getErrorMessage());
-        assertNotNull("initial last update set", mail.getLastUpdated());
-        try {
-            assertTrue("no initial recipient", mail.getRecipients().isEmpty());
-        } catch (NullPointerException e) {
-            // current behavior. *BUT*, shouldn't this method better return with
-            // an empty list?!
-        }
-        assertEquals("initial remote address is localhost ip", "127.0.0.1", mail.getRemoteAddr());
-        assertEquals("initial remote host is localhost", "localhost", mail.getRemoteHost());
-        assertEquals("default initial state", Mail.DEFAULT, mail.getState());
+	assertFalse("no initial attributes", mail.hasAttributes());
+	assertNull("no initial error", mail.getErrorMessage());
+	assertNotNull("initial last update set", mail.getLastUpdated());
+	try {
+	    assertTrue("no initial recipient", mail.getRecipients().isEmpty());
+	} catch (NullPointerException e) {
+	    // current behavior. *BUT*, shouldn't this method better return with
+	    // an empty list?!
+	}
+	assertEquals("initial remote address is localhost ip", "127.0.0.1", mail.getRemoteAddr());
+	assertEquals("initial remote host is localhost", "localhost", mail.getRemoteHost());
+	assertEquals("default initial state", Mail.DEFAULT, mail.getState());
     }
 
     protected void helperTestMessageSize(Mail mail, int expectedMsgSize) throws MessagingException {
-        try {
-            assertEquals("initial message size == " + expectedMsgSize, expectedMsgSize, mail.getMessageSize());
-        } catch (NullPointerException e) {
-            // current behavior. *BUT*, shouldn't this method return more
-            // gracefully?!
-        }
+	try {
+	    assertEquals("initial message size == " + expectedMsgSize, expectedMsgSize, mail.getMessageSize());
+	} catch (NullPointerException e) {
+	    // current behavior. *BUT*, shouldn't this method return more
+	    // gracefully?!
+	}
     }
 
+    @Test
     public void testAttributes() {
-        Mail mail = createMailImplementation();
-        assertFalse("no initial attributes", mail.hasAttributes());
-        assertFalse("attributes initially empty", mail.getAttributeNames().hasNext());
-        assertNull("not found on emtpy list", mail.getAttribute("test"));
-        assertNull("no previous item with key", mail.setAttribute("testKey", "testValue"));
-        assertEquals("item found", "testValue", mail.getAttribute("testKey"));
-        assertTrue("has attribute", mail.hasAttributes());
-        assertEquals("item removed", "testValue", mail.removeAttribute("testKey"));
-        assertNull("item no longer found", mail.getAttribute("testKey"));
+	Mail mail = createMailImplementation();
+	assertFalse("no initial attributes", mail.hasAttributes());
+	assertFalse("attributes initially empty", mail.getAttributeNames().hasNext());
+	assertNull("not found on emtpy list", mail.getAttribute("test"));
+	assertNull("no previous item with key", mail.setAttribute("testKey", "testValue"));
+	assertEquals("item found", "testValue", mail.getAttribute("testKey"));
+	assertTrue("has attribute", mail.hasAttributes());
+	assertEquals("item removed", "testValue", mail.removeAttribute("testKey"));
+	assertNull("item no longer found", mail.getAttribute("testKey"));
     }
-
 }

Modified: james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java?rev=1299494&r1=1299493&r2=1299494&view=diff
==============================================================================
--- james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java (original)
+++ james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageCopyOnWriteProxyTest.java Mon Mar 12 00:03:03 2012
@@ -16,7 +16,6 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
 package org.apache.james.core;
 
 import java.util.ArrayList;
@@ -30,6 +29,8 @@ import javax.mail.util.SharedByteArrayIn
 import org.apache.james.lifecycle.api.LifecycleUtil;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
+import static org.junit.Assert.*;
+import org.junit.Test;
 
 public class MimeMessageCopyOnWriteProxyTest extends MimeMessageFromStreamTest {
 
@@ -37,82 +38,87 @@ public class MimeMessageCopyOnWriteProxy
     String sep = "\r\n\r\n";
     String body = "bar\r\n.\r\n";
 
+    @Override
     protected MimeMessage getMessageFromSources(String sources) throws Exception {
-        MimeMessageInputStreamSource mmis = null;
-        try {
-            mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream(sources.getBytes()));
-        } catch (MessagingException e) {
-        }
-        return new MimeMessageCopyOnWriteProxy(mmis);
-        // return new MimeMessage(Session.getDefaultInstance(new
-        // Properties()),new ByteArrayInputStream(sources.getBytes()));
+	MimeMessageInputStreamSource mmis = null;
+	try {
+	    mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream(sources.getBytes()));
+	} catch (MessagingException e) {
+	}
+	return new MimeMessageCopyOnWriteProxy(mmis);
+	// return new MimeMessage(Session.getDefaultInstance(new
+	// Properties()),new ByteArrayInputStream(sources.getBytes()));
     }
 
+    @Test
     public void testMessageCloning1() throws Exception {
-        ArrayList r = new ArrayList();
-        r.add(new MailAddress("recipient@test.com"));
-        MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(content + sep + body);
-        MailImpl mail = new MailImpl("test", new MailAddress("test@test.com"), r, messageFromSources);
-        MailImpl m2 = (MailImpl) mail.duplicate();
-        System.out.println("mail: " + getReferences(mail.getMessage()) + " m2: " + getReferences(m2.getMessage()));
-        assertNotSame(m2, mail);
-        assertNotSame(m2.getMessage(), mail.getMessage());
-        // test that the wrapped message is the same
-        assertTrue(isSameMimeMessage(m2.getMessage(), mail.getMessage()));
-        // test it is the same after read only operations!
-        mail.getMessage().getSubject();
-        assertTrue(isSameMimeMessage(m2.getMessage(), mail.getMessage()));
-        mail.getMessage().setText("new body");
-        mail.getMessage().saveChanges();
-        // test it is different after a write operation!
-        mail.getMessage().setSubject("new Subject");
-        assertTrue(!isSameMimeMessage(m2.getMessage(), mail.getMessage()));
-        LifecycleUtil.dispose(mail);
-        LifecycleUtil.dispose(m2);
-        LifecycleUtil.dispose(messageFromSources);
+	ArrayList r = new ArrayList();
+	r.add(new MailAddress("recipient@test.com"));
+	MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(
+		content + sep + body);
+	MailImpl mail = new MailImpl("test", new MailAddress("test@test.com"), r, messageFromSources);
+	MailImpl m2 = (MailImpl) mail.duplicate();
+	System.out.println("mail: " + getReferences(mail.getMessage()) + " m2: " + getReferences(m2.getMessage()));
+	assertNotSame(m2, mail);
+	assertNotSame(m2.getMessage(), mail.getMessage());
+	// test that the wrapped message is the same
+	assertTrue(isSameMimeMessage(m2.getMessage(), mail.getMessage()));
+	// test it is the same after read only operations!
+	mail.getMessage().getSubject();
+	assertTrue(isSameMimeMessage(m2.getMessage(), mail.getMessage()));
+	mail.getMessage().setText("new body");
+	mail.getMessage().saveChanges();
+	// test it is different after a write operation!
+	mail.getMessage().setSubject("new Subject");
+	assertTrue(!isSameMimeMessage(m2.getMessage(), mail.getMessage()));
+	LifecycleUtil.dispose(mail);
+	LifecycleUtil.dispose(m2);
+	LifecycleUtil.dispose(messageFromSources);
     }
 
+    @Test
     public void testMessageCloning2() throws Exception {
-        ArrayList r = new ArrayList();
-        r.add(new MailAddress("recipient@test.com"));
-        MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(content + sep + body);
-        MailImpl mail = new MailImpl("test", new MailAddress("test@test.com"), r, messageFromSources);
-        MailImpl m2 = (MailImpl) mail.duplicate();
-        System.out.println("mail: " + getReferences(mail.getMessage()) + " m2: " + getReferences(m2.getMessage()));
-        assertNotSame(m2, mail);
-        assertNotSame(m2.getMessage(), mail.getMessage());
-        // test that the wrapped message is the same
-        assertTrue(isSameMimeMessage(m2.getMessage(), mail.getMessage()));
-        // test it is the same after real only operations!
-        m2.getMessage().getSubject();
-        assertTrue(isSameMimeMessage(m2.getMessage(), mail.getMessage()));
-        m2.getMessage().setText("new body");
-        m2.getMessage().saveChanges();
-        // test it is different after a write operation!
-        m2.getMessage().setSubject("new Subject");
-        assertTrue(!isSameMimeMessage(m2.getMessage(), mail.getMessage()));
-        // check that the subjects are correct on both mails!
-        assertEquals(m2.getMessage().getSubject(), "new Subject");
-        assertEquals(mail.getMessage().getSubject(), "foo");
-        // cloning again the messages
-        Mail m2clone = m2.duplicate();
-        assertTrue(isSameMimeMessage(m2clone.getMessage(), m2.getMessage()));
-        MimeMessage mm = getWrappedMessage(m2.getMessage());
-        assertNotSame(m2.getMessage(), m2clone.getMessage());
-        // test that m2clone has a valid wrapped message
-        MimeMessage mm3 = getWrappedMessage(m2clone.getMessage());
-        assertNotNull(mm3);
-        // dispose m2 and check that the clone has still a valid message and it
-        // is the same!
-        LifecycleUtil.dispose(m2);
-        assertEquals(mm3, getWrappedMessage(m2clone.getMessage()));
-        // change the message that should be not referenced by m2 that has
-        // been disposed, so it should not clone it!
-        m2clone.getMessage().setSubject("new Subject 2");
-        m2clone.getMessage().setText("new Body 3");
-        assertTrue(isSameMimeMessage(m2clone.getMessage(), mm));
-        LifecycleUtil.dispose(mail);
-        LifecycleUtil.dispose(messageFromSources);
+	ArrayList r = new ArrayList();
+	r.add(new MailAddress("recipient@test.com"));
+	MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(
+		content + sep + body);
+	MailImpl mail = new MailImpl("test", new MailAddress("test@test.com"), r, messageFromSources);
+	MailImpl m2 = (MailImpl) mail.duplicate();
+	System.out.println("mail: " + getReferences(mail.getMessage()) + " m2: " + getReferences(m2.getMessage()));
+	assertNotSame(m2, mail);
+	assertNotSame(m2.getMessage(), mail.getMessage());
+	// test that the wrapped message is the same
+	assertTrue(isSameMimeMessage(m2.getMessage(), mail.getMessage()));
+	// test it is the same after real only operations!
+	m2.getMessage().getSubject();
+	assertTrue(isSameMimeMessage(m2.getMessage(), mail.getMessage()));
+	m2.getMessage().setText("new body");
+	m2.getMessage().saveChanges();
+	// test it is different after a write operation!
+	m2.getMessage().setSubject("new Subject");
+	assertTrue(!isSameMimeMessage(m2.getMessage(), mail.getMessage()));
+	// check that the subjects are correct on both mails!
+	assertEquals(m2.getMessage().getSubject(), "new Subject");
+	assertEquals(mail.getMessage().getSubject(), "foo");
+	// cloning again the messages
+	Mail m2clone = m2.duplicate();
+	assertTrue(isSameMimeMessage(m2clone.getMessage(), m2.getMessage()));
+	MimeMessage mm = getWrappedMessage(m2.getMessage());
+	assertNotSame(m2.getMessage(), m2clone.getMessage());
+	// test that m2clone has a valid wrapped message
+	MimeMessage mm3 = getWrappedMessage(m2clone.getMessage());
+	assertNotNull(mm3);
+	// dispose m2 and check that the clone has still a valid message and it
+	// is the same!
+	LifecycleUtil.dispose(m2);
+	assertEquals(mm3, getWrappedMessage(m2clone.getMessage()));
+	// change the message that should be not referenced by m2 that has
+	// been disposed, so it should not clone it!
+	m2clone.getMessage().setSubject("new Subject 2");
+	m2clone.getMessage().setText("new Body 3");
+	assertTrue(isSameMimeMessage(m2clone.getMessage(), mm));
+	LifecycleUtil.dispose(mail);
+	LifecycleUtil.dispose(messageFromSources);
     }
 
     /**
@@ -120,33 +126,35 @@ public class MimeMessageCopyOnWriteProxy
      * MimeMessageCopyOnWriteProxy, I remove references to the first and I
      * change the second, then it should not clone
      */
+    @Test
     public void testMessageAvoidCloning() throws Exception {
-        ArrayList r = new ArrayList();
-        r.add(new MailAddress("recipient@test.com"));
-        MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(content + sep + body);
-        MailImpl mail = new MailImpl("test", new MailAddress("test@test.com"), r, messageFromSources);
-        // cloning the message
-        Mail mailClone = mail.duplicate();
-        assertTrue(isSameMimeMessage(mailClone.getMessage(), mail.getMessage()));
-        MimeMessage mm = getWrappedMessage(mail.getMessage());
-        assertNotSame(mail.getMessage(), mailClone.getMessage());
-        // dispose mail and check that the clone has still a valid message and
-        // it is the same!
-        LifecycleUtil.dispose(mail);
-        LifecycleUtil.dispose(messageFromSources);
-        // need to add a gc and a wait, because the original mimemessage should
-        // be finalized before the test.
-        System.gc();
-        Thread.sleep(1000);
-        // dumb test
-        assertTrue(isSameMimeMessage(mailClone.getMessage(), mailClone.getMessage()));
-        // change the message that should be not referenced by mail that has
-        // been disposed, so it should not clone it!
-        mailClone.getMessage().setSubject("new Subject 2");
-        mailClone.getMessage().setText("new Body 3");
-        assertTrue(isSameMimeMessage(mailClone.getMessage(), mm));
-        LifecycleUtil.dispose(mailClone);
-        LifecycleUtil.dispose(mm);
+	ArrayList r = new ArrayList();
+	r.add(new MailAddress("recipient@test.com"));
+	MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(
+		content + sep + body);
+	MailImpl mail = new MailImpl("test", new MailAddress("test@test.com"), r, messageFromSources);
+	// cloning the message
+	Mail mailClone = mail.duplicate();
+	assertTrue(isSameMimeMessage(mailClone.getMessage(), mail.getMessage()));
+	MimeMessage mm = getWrappedMessage(mail.getMessage());
+	assertNotSame(mail.getMessage(), mailClone.getMessage());
+	// dispose mail and check that the clone has still a valid message and
+	// it is the same!
+	LifecycleUtil.dispose(mail);
+	LifecycleUtil.dispose(messageFromSources);
+	// need to add a gc and a wait, because the original mimemessage should
+	// be finalized before the test.
+	System.gc();
+	Thread.sleep(1000);
+	// dumb test
+	assertTrue(isSameMimeMessage(mailClone.getMessage(), mailClone.getMessage()));
+	// change the message that should be not referenced by mail that has
+	// been disposed, so it should not clone it!
+	mailClone.getMessage().setSubject("new Subject 2");
+	mailClone.getMessage().setText("new Body 3");
+	assertTrue(isSameMimeMessage(mailClone.getMessage(), mm));
+	LifecycleUtil.dispose(mailClone);
+	LifecycleUtil.dispose(mm);
     }
 
     /**
@@ -154,109 +162,115 @@ public class MimeMessageCopyOnWriteProxy
      * change the new message, the original should be unaltered and the proxy
      * should clone the message.
      */
+    @Test
     public void testMessageCloning3() throws Exception {
-        ArrayList r = new ArrayList();
-        r.add(new MailAddress("recipient@test.com"));
-        MimeMessage m = new MimeMessage(Session.getDefaultInstance(new Properties(null)));
-        m.setText("CIPS");
-        MailImpl mail = new MailImpl("test", new MailAddress("test@test.com"), r, m);
-        assertTrue(isSameMimeMessage(m, mail.getMessage()));
-        // change the message that should be not referenced by mail that has
-        // been disposed, so it should not clone it!
-        System.gc();
-        Thread.sleep(100);
-        mail.getMessage().setSubject("new Subject 2");
-        mail.getMessage().setText("new Body 3");
-        System.gc();
-        Thread.sleep(100);
-        assertFalse(isSameMimeMessage(m, mail.getMessage()));
-        LifecycleUtil.dispose(mail);
-        LifecycleUtil.dispose(m);
+	ArrayList r = new ArrayList();
+	r.add(new MailAddress("recipient@test.com"));
+	MimeMessage m = new MimeMessage(Session.getDefaultInstance(new Properties(null)));
+	m.setText("CIPS");
+	MailImpl mail = new MailImpl("test", new MailAddress("test@test.com"), r, m);
+	assertTrue(isSameMimeMessage(m, mail.getMessage()));
+	// change the message that should be not referenced by mail that has
+	// been disposed, so it should not clone it!
+	System.gc();
+	Thread.sleep(100);
+	mail.getMessage().setSubject("new Subject 2");
+	mail.getMessage().setText("new Body 3");
+	System.gc();
+	Thread.sleep(100);
+	assertFalse(isSameMimeMessage(m, mail.getMessage()));
+	LifecycleUtil.dispose(mail);
+	LifecycleUtil.dispose(m);
     }
 
+    @Test
     public void testMessageDisposing() throws Exception {
-        ArrayList r = new ArrayList();
-        r.add(new MailAddress("recipient@test.com"));
-        MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(content + sep + body);
-        MailImpl mail = new MailImpl("test", new MailAddress("test@test.com"), r, messageFromSources);
-        // cloning the message
-        MailImpl mailClone = (MailImpl) mail.duplicate();
-        LifecycleUtil.dispose(mail);
-
-        assertNotNull(getWrappedMessage(mailClone.getMessage()));
-        assertNull(mail.getMessage());
-
-        LifecycleUtil.dispose(mailClone);
-
-        assertNull(mailClone.getMessage());
-        assertNull(mail.getMessage());
-        LifecycleUtil.dispose(mail);
-        LifecycleUtil.dispose(messageFromSources);
+	ArrayList r = new ArrayList();
+	r.add(new MailAddress("recipient@test.com"));
+	MimeMessageCopyOnWriteProxy messageFromSources = (MimeMessageCopyOnWriteProxy) getMessageFromSources(
+		content + sep + body);
+	MailImpl mail = new MailImpl("test", new MailAddress("test@test.com"), r, messageFromSources);
+	// cloning the message
+	MailImpl mailClone = (MailImpl) mail.duplicate();
+	LifecycleUtil.dispose(mail);
+
+	assertNotNull(getWrappedMessage(mailClone.getMessage()));
+	assertNull(mail.getMessage());
+
+	LifecycleUtil.dispose(mailClone);
+
+	assertNull(mailClone.getMessage());
+	assertNull(mail.getMessage());
+	LifecycleUtil.dispose(mail);
+	LifecycleUtil.dispose(messageFromSources);
     }
 
+    @Test
     public void testNPE1() throws MessagingException, InterruptedException {
-        ArrayList recipients = new ArrayList();
-        recipients.add(new MailAddress("recipient@test.com"));
-        MimeMessageCopyOnWriteProxy mw = new MimeMessageCopyOnWriteProxy(new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream(("Return-path: return@test.com\r\n" + "Content-Transfer-Encoding: plain\r\n" + "Subject: test\r\n\r\n" + "Body Text testNPE1\r\n").getBytes())));
-
-        MimeMessageCopyOnWriteProxy mw2 = new MimeMessageCopyOnWriteProxy(mw);
-        LifecycleUtil.dispose(mw2);
-        mw2 = null;
-        System.gc();
-        Thread.sleep(1000);
-        // the NPE was inside this call
-        mw.getMessageSize();
-        LifecycleUtil.dispose(mw);
+	ArrayList recipients = new ArrayList();
+	recipients.add(new MailAddress("recipient@test.com"));
+	MimeMessageCopyOnWriteProxy mw = new MimeMessageCopyOnWriteProxy(new MimeMessageInputStreamSource("test",
+		new SharedByteArrayInputStream(("Return-path: return@test.com\r\n" + "Content-Transfer-Encoding: plain\r\n" + "Subject: test\r\n\r\n" + "Body Text testNPE1\r\n").
+		getBytes())));
+
+	MimeMessageCopyOnWriteProxy mw2 = new MimeMessageCopyOnWriteProxy(mw);
+	LifecycleUtil.dispose(mw2);
+	mw2 = null;
+	System.gc();
+	Thread.sleep(1000);
+	// the NPE was inside this call
+	mw.getMessageSize();
+	LifecycleUtil.dispose(mw);
     }
 
     /**
      * This test throw a NullPointerException when the original message was
      * created by a MimeMessageInputStreamSource.
      */
+    @Test
     public void testMessageCloningViaCoW3() throws Exception {
-        MimeMessage mmorig = getSimpleMessage();
+	MimeMessage mmorig = getSimpleMessage();
 
-        MimeMessage mm = new MimeMessageCopyOnWriteProxy(mmorig);
+	MimeMessage mm = new MimeMessageCopyOnWriteProxy(mmorig);
 
-        LifecycleUtil.dispose(mmorig);
-        mmorig = null;
-        System.gc();
-        Thread.sleep(200);
-
-        try {
-            mm.writeTo(System.out);
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail("Exception while writing the message to output");
-        }
+	LifecycleUtil.dispose(mmorig);
+	mmorig = null;
+	System.gc();
+	Thread.sleep(200);
+
+	try {
+	    mm.writeTo(System.out);
+	} catch (Exception e) {
+	    e.printStackTrace();
+	    fail("Exception while writing the message to output");
+	}
 
-        LifecycleUtil.dispose(mm);
+	LifecycleUtil.dispose(mm);
     }
 
     private static String getReferences(MimeMessage m) {
-        StringBuffer ref = new StringBuffer("/");
-        while (m instanceof MimeMessageCopyOnWriteProxy) {
-            ref.append(((MimeMessageCopyOnWriteProxy) m).refCount.getReferenceCount() + "/");
-            m = ((MimeMessageCopyOnWriteProxy) m).getWrappedMessage();
-        }
-        if (m instanceof MimeMessageWrapper) {
-            ref.append("W");
-        } else {
-            ref.append("M");
-        }
-        return ref.toString();
+	StringBuilder ref = new StringBuilder("/");
+	while (m instanceof MimeMessageCopyOnWriteProxy) {
+	    ref.append(((MimeMessageCopyOnWriteProxy) m).refCount.getReferenceCount()).append("/");
+	    m = ((MimeMessageCopyOnWriteProxy) m).getWrappedMessage();
+	}
+	if (m instanceof MimeMessageWrapper) {
+	    ref.append("W");
+	} else {
+	    ref.append("M");
+	}
+	return ref.toString();
     }
 
     private static MimeMessage getWrappedMessage(MimeMessage m) {
-        while (m instanceof MimeMessageCopyOnWriteProxy) {
-            m = ((MimeMessageCopyOnWriteProxy) m).getWrappedMessage();
-        }
-        return m;
+	while (m instanceof MimeMessageCopyOnWriteProxy) {
+	    m = ((MimeMessageCopyOnWriteProxy) m).getWrappedMessage();
+	}
+	return m;
     }
 
     private static boolean isSameMimeMessage(MimeMessage first, MimeMessage second) {
-        return getWrappedMessage(first) == getWrappedMessage(second);
+	return getWrappedMessage(first) == getWrappedMessage(second);
 
     }
-
 }

Modified: james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromMimeMessageTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromMimeMessageTest.java?rev=1299494&r1=1299493&r2=1299494&view=diff
==============================================================================
--- james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromMimeMessageTest.java (original)
+++ james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromMimeMessageTest.java Mon Mar 12 00:03:03 2012
@@ -23,6 +23,7 @@ import javax.mail.internet.MimeMessage;
 
 public class MimeMessageFromMimeMessageTest extends MimeMessageFromStreamTest {
 
+    @Override
     protected MimeMessage getMessageFromSources(String sources) throws Exception {
         return new MimeMessage(super.getMessageFromSources(sources));
     }

Modified: james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromSharedStreamTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromSharedStreamTest.java?rev=1299494&r1=1299493&r2=1299494&view=diff
==============================================================================
--- james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromSharedStreamTest.java (original)
+++ james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromSharedStreamTest.java Mon Mar 12 00:03:03 2012
@@ -28,6 +28,7 @@ import java.util.Properties;
 
 public class MimeMessageFromSharedStreamTest extends MimeMessageFromStreamTest {
 
+    @Override
     protected MimeMessage getMessageFromSources(String sources) throws Exception {
         return new MimeMessage(Session.getDefaultInstance(new Properties()), new SharedByteArrayInputStream(sources.getBytes()));
     }

Modified: james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromStreamTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromStreamTest.java?rev=1299494&r1=1299493&r2=1299494&view=diff
==============================================================================
--- james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromStreamTest.java (original)
+++ james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageFromStreamTest.java Mon Mar 12 00:03:03 2012
@@ -31,22 +31,27 @@ public class MimeMessageFromStreamTest e
         return new MimeMessage(Session.getDefaultInstance(new Properties()), new ByteArrayInputStream(sources.getBytes()));
     }
 
+    @Override
     protected MimeMessage getMultipartMessage() throws Exception {
         return getMessageFromSources(getMultipartMessageSource());
     }
 
+    @Override
     protected MimeMessage getSimpleMessage() throws Exception {
         return getMessageFromSources(getSimpleMessageCleanedSource());
     }
 
+    @Override
     protected MimeMessage getMessageWithBadReturnPath() throws Exception {
         return getMessageFromSources(getMessageWithBadReturnPathSource());
     }
 
+    @Override
     protected MimeMessage getMissingEncodingAddHeaderMessage() throws Exception {
         return getMessageFromSources(getMissingEncodingAddHeaderSource());
     }
 
+    @Override
     protected MimeMessage getMissingEncodingMessage() throws Exception {
         return getMessageFromSources(getMissingEncodingMessageSource());
     }

Modified: james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageTest.java?rev=1299494&r1=1299493&r2=1299494&view=diff
==============================================================================
--- james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageTest.java (original)
+++ james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageTest.java Mon Mar 12 00:03:03 2012
@@ -16,7 +16,6 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
 package org.apache.james.core;
 
 import org.apache.james.lifecycle.api.LifecycleUtil;
@@ -35,220 +34,222 @@ import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.Properties;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+import org.junit.Test;
 
 /**
  * Test the subject folding issue.
  */
-public class MimeMessageTest extends TestCase {
+public class MimeMessageTest {
 
     protected MimeMessage getSimpleMessage() throws Exception {
-        MimeMessage mmCreated = new MimeMessage(Session.getDefaultInstance(new Properties()));
-        mmCreated.setSubject("test");
-        mmCreated.setText("test body");
-        mmCreated.saveChanges();
-        return mmCreated;
+	MimeMessage mmCreated = new MimeMessage(Session.getDefaultInstance(new Properties()));
+	mmCreated.setSubject("test");
+	mmCreated.setText("test body");
+	mmCreated.saveChanges();
+	return mmCreated;
     }
 
     protected String getSimpleMessageCleanedSource() throws Exception {
-        return "Subject: test\r\n"
-            +"MIME-Version: 1.0\r\n"
-            +"Content-Type: text/plain; charset=us-ascii\r\n"
-            +"Content-Transfer-Encoding: 7bit\r\n"
-            +"\r\n"
-            +"test body";
+	return "Subject: test\r\n"
+		+ "MIME-Version: 1.0\r\n"
+		+ "Content-Type: text/plain; charset=us-ascii\r\n"
+		+ "Content-Transfer-Encoding: 7bit\r\n"
+		+ "\r\n"
+		+ "test body";
     }
-    
 
     protected MimeMessage getMessageWithBadReturnPath() throws Exception {
-        MimeMessage mmCreated = new MimeMessage(Session.getDefaultInstance(new Properties()));
-        mmCreated.setSubject("test");
-        mmCreated.setHeader(RFC2822Headers.RETURN_PATH, "<mybadreturn@example.com>");
-        mmCreated.setText("test body");
-        mmCreated.saveChanges();
-        return mmCreated;
+	MimeMessage mmCreated = new MimeMessage(Session.getDefaultInstance(new Properties()));
+	mmCreated.setSubject("test");
+	mmCreated.setHeader(RFC2822Headers.RETURN_PATH, "<mybadreturn@example.com>");
+	mmCreated.setText("test body");
+	mmCreated.saveChanges();
+	return mmCreated;
     }
-    
+
     protected String getMessageWithBadReturnPathSource() throws Exception {
-        return "Subject: test\r\n"
-            +"Return-Path: <mybadreturn@example.com>\r\n"
-            +"MIME-Version: 1.0\r\n"
-            +"Content-Type: text/plain; charset=us-ascii\r\n"
-            +"Content-Transfer-Encoding: 7bit\r\n"
-            +"\r\n"
-            +"test body";
+	return "Subject: test\r\n"
+		+ "Return-Path: <mybadreturn@example.com>\r\n"
+		+ "MIME-Version: 1.0\r\n"
+		+ "Content-Type: text/plain; charset=us-ascii\r\n"
+		+ "Content-Transfer-Encoding: 7bit\r\n"
+		+ "\r\n"
+		+ "test body";
     }
-    
+
     protected String getSimpleMessageCleanedSourceHeaderExpected() throws Exception {
-        return "X-Test: foo\r\n" + getSimpleMessageCleanedSource();
+	return "X-Test: foo\r\n" + getSimpleMessageCleanedSource();
     }
 
     /*
      * Class under test for String getSubject()
      */
+    @Test
     public void testSimpleMessage() throws Exception {
-        MimeMessage m = getSimpleMessage();
-        assertEquals(getSimpleMessageCleanedSource(), getCleanedMessageSource(m));
-        LifecycleUtil.dispose(m);
+	MimeMessage m = getSimpleMessage();
+	assertEquals(getSimpleMessageCleanedSource(), getCleanedMessageSource(m));
+	LifecycleUtil.dispose(m);
     }
 
     protected MimeMessage getMultipartMessage() throws Exception {
-        MimeMessage mmCreated = new MimeMessage(Session.getDefaultInstance(new Properties()));
-        mmCreated.setSubject("test");
-        MimeMultipart mm = new MimeMultipart("alternative");
-        mm.addBodyPart(new MimeBodyPart(new InternetHeaders(new ByteArrayInputStream("X-header: test1\r\nContent-Type: text/plain; charset=Cp1252\r\n".getBytes())), "first part \u00F2\u00E0\u00F9".getBytes()));
-        mm.addBodyPart(new MimeBodyPart(new InternetHeaders(new ByteArrayInputStream("X-header: test2\r\nContent-Type: text/plain; charset=Cp1252\r\nContent-Transfer-Encoding: quoted-printable\r\n".getBytes())), "second part =E8=E8".getBytes()));
-        mmCreated.setContent(mm);
-        mmCreated.saveChanges();
-        return mmCreated;
+	MimeMessage mmCreated = new MimeMessage(Session.getDefaultInstance(new Properties()));
+	mmCreated.setSubject("test");
+	MimeMultipart mm = new MimeMultipart("alternative");
+	mm.addBodyPart(new MimeBodyPart(new InternetHeaders(new ByteArrayInputStream("X-header: test1\r\nContent-Type: text/plain; charset=Cp1252\r\n".
+		getBytes())), "first part \u00F2\u00E0\u00F9".getBytes()));
+	mm.addBodyPart(new MimeBodyPart(new InternetHeaders(new ByteArrayInputStream("X-header: test2\r\nContent-Type: text/plain; charset=Cp1252\r\nContent-Transfer-Encoding: quoted-printable\r\n".
+		getBytes())), "second part =E8=E8".getBytes()));
+	mmCreated.setContent(mm);
+	mmCreated.saveChanges();
+	return mmCreated;
     }
-    
+
     protected String getMultipartMessageSource() {
-        return "Subject: test\r\n"
-            +"MIME-Version: 1.0\r\n"
-            +"Content-Type: multipart/alternative; \r\n" 
-            +"\tboundary=\"----=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\"\r\n"
-            +"\r\n"
-            +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
-            +"X-header: test1\r\n"
-            +"Content-Type: text/plain; charset=Cp1252\r\n"
-            +"Content-Transfer-Encoding: quoted-printable\r\n"
-            +"\r\n"
-            +"first part =E8\r\n"
-            +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
-            +"X-header: test2\r\n"
-            +"Content-Type: text/plain; charset=Cp1252\r\n"
-            +"Content-Transfer-Encoding: quoted-printable\r\n"
-            +"\r\n"
-            +"second part =E8=E8\r\n"
-            +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX--\r\n";
+	return "Subject: test\r\n"
+		+ "MIME-Version: 1.0\r\n"
+		+ "Content-Type: multipart/alternative; \r\n"
+		+ "\tboundary=\"----=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\"\r\n"
+		+ "\r\n"
+		+ "------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
+		+ "X-header: test1\r\n"
+		+ "Content-Type: text/plain; charset=Cp1252\r\n"
+		+ "Content-Transfer-Encoding: quoted-printable\r\n"
+		+ "\r\n"
+		+ "first part =E8\r\n"
+		+ "------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
+		+ "X-header: test2\r\n"
+		+ "Content-Type: text/plain; charset=Cp1252\r\n"
+		+ "Content-Transfer-Encoding: quoted-printable\r\n"
+		+ "\r\n"
+		+ "second part =E8=E8\r\n"
+		+ "------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX--\r\n";
     }
-    
+
     protected String getMultipartMessageExpected1() {
-        return "Subject: test\r\n"
-            +"MIME-Version: 1.0\r\n"
-            +"Content-Type: multipart/alternative; \r\n" 
-            +"\tboundary=\"----=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\"\r\n"
-            +"\r\n"
-            +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
-            +"X-header: test1\r\n"
-            +"Content-Type: text/plain; charset=Cp1252\r\n"
-            +"Content-Transfer-Encoding: quoted-printable\r\n"
-            +"\r\n"
-            +"test=80\r\n"
-            +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
-            +"X-header: test2\r\n"
-            +"Content-Type: text/plain; charset=Cp1252\r\n"
-            +"Content-Transfer-Encoding: quoted-printable\r\n"
-            +"\r\n"
-            +"second part =E8=E8\r\n"
-            +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX--\r\n";
+	return "Subject: test\r\n"
+		+ "MIME-Version: 1.0\r\n"
+		+ "Content-Type: multipart/alternative; \r\n"
+		+ "\tboundary=\"----=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\"\r\n"
+		+ "\r\n"
+		+ "------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
+		+ "X-header: test1\r\n"
+		+ "Content-Type: text/plain; charset=Cp1252\r\n"
+		+ "Content-Transfer-Encoding: quoted-printable\r\n"
+		+ "\r\n"
+		+ "test=80\r\n"
+		+ "------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
+		+ "X-header: test2\r\n"
+		+ "Content-Type: text/plain; charset=Cp1252\r\n"
+		+ "Content-Transfer-Encoding: quoted-printable\r\n"
+		+ "\r\n"
+		+ "second part =E8=E8\r\n"
+		+ "------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX--\r\n";
     }
-    
-    
+
     protected String getMultipartMessageExpected2() {
-        return "Subject: test\r\n"
-            +"MIME-Version: 1.0\r\n"
-            +"Content-Type: multipart/alternative; \r\n" 
-            +"\tboundary=\"----=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\"\r\n"
-            +"\r\n"
-            +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
-            +"X-header: test1\r\n"
-            +"Content-Type: text/plain; charset=Cp1252\r\n"
-            +"Content-Transfer-Encoding: quoted-printable\r\n"
-            +"\r\n"
-            +"test=80\r\n"
-            +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
-            +"X-header: test2\r\n"
-            +"Content-Type: text/plain; charset=Cp1252\r\n"
-            +"Content-Transfer-Encoding: quoted-printable\r\n"
-            +"\r\n"
-            +"second part =E8=E8\r\n"
-            +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
-            +"Subject: test3\r\n"
-            
-            // javamail 1.4.3 NOTES:
-            // this headers don't get added by version 1.4.3 
-            //which should be the right behavoir anyway
-            //+"Content-Transfer-Encoding: 7bit\r\n"
-            //+"Content-Type: text/plain; charset=us-ascii\r\n"
-            
-            +"\r\n"
-            +"second part\r\n"
-            +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX--\r\n";
+	return "Subject: test\r\n"
+		+ "MIME-Version: 1.0\r\n"
+		+ "Content-Type: multipart/alternative; \r\n"
+		+ "\tboundary=\"----=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\"\r\n"
+		+ "\r\n"
+		+ "------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
+		+ "X-header: test1\r\n"
+		+ "Content-Type: text/plain; charset=Cp1252\r\n"
+		+ "Content-Transfer-Encoding: quoted-printable\r\n"
+		+ "\r\n"
+		+ "test=80\r\n"
+		+ "------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
+		+ "X-header: test2\r\n"
+		+ "Content-Type: text/plain; charset=Cp1252\r\n"
+		+ "Content-Transfer-Encoding: quoted-printable\r\n"
+		+ "\r\n"
+		+ "second part =E8=E8\r\n"
+		+ "------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
+		+ "Subject: test3\r\n"
+		// javamail 1.4.3 NOTES:
+		// this headers don't get added by version 1.4.3
+		//which should be the right behavoir anyway
+		//+"Content-Transfer-Encoding: 7bit\r\n"
+		//+"Content-Type: text/plain; charset=us-ascii\r\n"
+
+		+ "\r\n"
+		+ "second part\r\n"
+		+ "------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX--\r\n";
     }
-    
+
     protected String getMultipartMessageExpected3() {
-        return "Subject: test\r\n"
-            +"MIME-Version: 1.0\r\n"
-            +"Content-Type: binary/octet-stream\r\n"
-            +"Content-Transfer-Encoding: quoted-printable\r\n"
-            +"\r\n"
-            +"mynewco=F2=E0=F9ntent=80=E0!";
+	return "Subject: test\r\n"
+		+ "MIME-Version: 1.0\r\n"
+		+ "Content-Type: binary/octet-stream\r\n"
+		+ "Content-Transfer-Encoding: quoted-printable\r\n"
+		+ "\r\n"
+		+ "mynewco=F2=E0=F9ntent=80=E0!";
     }
-    
+
     /*
      * Class under test for String getSubject()
      */
+    @Test
     public void testMultipartMessageChanges() throws Exception {
 
-        MimeMessage mm = getMultipartMessage();
+	MimeMessage mm = getMultipartMessage();
 
-        // ByteArrayOutputStream out = new ByteArrayOutputStream();
-        // mmCreated.writeTo(out,new String[] {"Message-ID"});
-        // String messageSource = out.toString();
-        // System.out.println(messageSource);
+	// ByteArrayOutputStream out = new ByteArrayOutputStream();
+	// mmCreated.writeTo(out,new String[] {"Message-ID"});
+	// String messageSource = out.toString();
+	// System.out.println(messageSource);
+
+	MimeMultipart content1 = (MimeMultipart) mm.getContent();
+	BodyPart b1 = content1.getBodyPart(0);
+	b1.setContent("test\u20AC", "text/plain; charset=Cp1252");
+	mm.setContent(content1, mm.getContentType());
+	// .setHeader(RFC2822Headers.CONTENT_TYPE,contentType);
+	mm.saveChanges();
+
+	assertEquals(getMultipartMessageExpected1(), getCleanedMessageSource(mm));
+
+	MimeMultipart content2 = (MimeMultipart) mm.getContent();
+	content2.addBodyPart(new MimeBodyPart(new InternetHeaders(new ByteArrayInputStream(
+		"Subject: test3\r\n".getBytes())), "second part".getBytes()));
+	mm.setContent(content2, mm.getContentType());
+	mm.saveChanges();
+
+	assertEquals(getMultipartMessageExpected2(), getCleanedMessageSource(mm));
+
+	mm.setContent("mynewco\u00F2\u00E0\u00F9ntent\u20AC\u00E0!", "text/plain; charset=cp1252");
+	mm.setHeader(RFC2822Headers.CONTENT_TYPE, "binary/octet-stream");
+	// mm.setHeader("Content-Transfer-Encoding","8bit");
+	mm.saveChanges();
 
-        MimeMultipart content1 = (MimeMultipart) mm.getContent();
-        BodyPart b1 = content1.getBodyPart(0);
-        b1.setContent("test\u20AC", "text/plain; charset=Cp1252");
-        mm.setContent(content1, mm.getContentType());
-        // .setHeader(RFC2822Headers.CONTENT_TYPE,contentType);
-        mm.saveChanges();
+	assertEquals(getMultipartMessageExpected3(), getCleanedMessageSource(mm));
 
-        assertEquals(getMultipartMessageExpected1(), getCleanedMessageSource(mm));
-
-        MimeMultipart content2 = (MimeMultipart) mm.getContent();
-        content2.addBodyPart(new MimeBodyPart(new InternetHeaders(new ByteArrayInputStream("Subject: test3\r\n".getBytes())), "second part".getBytes()));
-        mm.setContent(content2, mm.getContentType());
-        mm.saveChanges();
-
-        assertEquals(getMultipartMessageExpected2(), getCleanedMessageSource(mm));
-
-        mm.setContent("mynewco\u00F2\u00E0\u00F9ntent\u20AC\u00E0!", "text/plain; charset=cp1252");
-        mm.setHeader(RFC2822Headers.CONTENT_TYPE, "binary/octet-stream");
-        // mm.setHeader("Content-Transfer-Encoding","8bit");
-        mm.saveChanges();
-
-        assertEquals(getMultipartMessageExpected3(), getCleanedMessageSource(mm));
-
-        LifecycleUtil.dispose(mm);
+	LifecycleUtil.dispose(mm);
 
     }
 
     protected MimeMessage getMissingEncodingAddHeaderMessage() throws Exception {
-        MimeMessage m = new MimeMessage(Session.getDefaultInstance(new Properties()));
-        m.setText("Test\u00E0\r\n");
-        m.setSubject("test");
-        m.saveChanges();
-        return m;
+	MimeMessage m = new MimeMessage(Session.getDefaultInstance(new Properties()));
+	m.setText("Test\u00E0\r\n");
+	m.setSubject("test");
+	m.saveChanges();
+	return m;
     }
 
     protected String getMissingEncodingAddHeaderSource() {
-        return "Subject: test\r\n"+
-                "\r\n"+
-                "Test\u00E0\r\n";
+	return "Subject: test\r\n"
+		+ "\r\n"
+		+ "Test\u00E0\r\n";
     }
-    
+
     protected String getMissingEncodingAddHeaderExpected() {
-        return "Subject: test\r\n"
-            +"MIME-Version: 1.0\r\n"
-            +"Content-Type: text/plain; charset=Cp1252\r\n"
-            +"Content-Transfer-Encoding: quoted-printable\r\n"
-            +"\r\n"
-            +"Test=E0\r\n";
+	return "Subject: test\r\n"
+		+ "MIME-Version: 1.0\r\n"
+		+ "Content-Type: text/plain; charset=Cp1252\r\n"
+		+ "Content-Transfer-Encoding: quoted-printable\r\n"
+		+ "\r\n"
+		+ "Test=E0\r\n";
     }
-    
 
     /**
      * This test is not usable in different locale environment.
@@ -264,156 +265,162 @@ public class MimeMessageTest extends Tes
      * assertEquals(getMissingEncodingAddHeaderExpected(),getCleanedMessageSource
      * (mm)); }
      */
-
     protected String getCleanedMessageSource(MimeMessage mm) throws Exception {
-        ByteArrayOutputStream out2;
-        out2 = new ByteArrayOutputStream();
-        mm.writeTo(out2, new String[] { "Message-ID" });
-
-        String res = out2.toString();
-
-        int p = res.indexOf("\r\n\r\n");
-        if (p > 0) {
-            String head = res.substring(0, p);
-            String[] str = head.split("\r\n");
-            Arrays.sort(str);
-            StringBuffer outputHead = new StringBuffer();
-            for (int i = str.length - 1; i >= 0; i--) {
-                outputHead.append(str[i]);
-                outputHead.append("\r\n");
-            }
-            outputHead.append(res.substring(p + 2));
-            res = outputHead.toString();
-        }
+	ByteArrayOutputStream out2;
+	out2 = new ByteArrayOutputStream();
+	mm.writeTo(out2, new String[]{"Message-ID"});
+
+	String res = out2.toString();
+
+	int p = res.indexOf("\r\n\r\n");
+	if (p > 0) {
+	    String head = res.substring(0, p);
+	    String[] str = head.split("\r\n");
+	    Arrays.sort(str);
+	    StringBuilder outputHead = new StringBuilder();
+	    for (int i = str.length - 1; i >= 0; i--) {
+		outputHead.append(str[i]);
+		outputHead.append("\r\n");
+	    }
+	    outputHead.append(res.substring(p + 2));
+	    res = outputHead.toString();
+	}
 
-        res = res.replaceAll("----=_Part_\\d*_\\d+\\.\\d+", "----=_Part_\\0_XXXXXXXXXXX.XXXXXXXXXXX");
-        return res;
+	res = res.replaceAll("----=_Part_\\d*_\\d+\\.\\d+", "----=_Part_\\0_XXXXXXXXXXX.XXXXXXXXXXX");
+	return res;
     }
 
     protected void debugMessage(MimeMessage mm) throws Exception {
-        System.out.println("-------------------");
-        System.out.println(getCleanedMessageSource(mm));
-        System.out.println("-------------------");
+	System.out.println("-------------------");
+	System.out.println(getCleanedMessageSource(mm));
+	System.out.println("-------------------");
     }
 
     protected MimeMessage getMissingEncodingMessage() throws Exception {
-        MimeMessage mmCreated = new MimeMessage(Session.getDefaultInstance(new Properties()));
-        mmCreated.setSubject("test");
-        MimeMultipart mm = new MimeMultipart("alternative");
-        mm.addBodyPart(new MimeBodyPart(new InternetHeaders(new ByteArrayInputStream("X-header: test2\r\nContent-Type: text/plain; charset=Cp1252\r\nContent-Transfer-Encoding: quoted-printable\r\n".getBytes())), "second part =E8=E8".getBytes()));
-        mmCreated.setContent(mm);
-        mmCreated.saveChanges();
-        return mmCreated;
+	MimeMessage mmCreated = new MimeMessage(Session.getDefaultInstance(new Properties()));
+	mmCreated.setSubject("test");
+	MimeMultipart mm = new MimeMultipart("alternative");
+	mm.addBodyPart(new MimeBodyPart(new InternetHeaders(new ByteArrayInputStream("X-header: test2\r\nContent-Type: text/plain; charset=Cp1252\r\nContent-Transfer-Encoding: quoted-printable\r\n".
+		getBytes())), "second part =E8=E8".getBytes()));
+	mmCreated.setContent(mm);
+	mmCreated.saveChanges();
+	return mmCreated;
     }
 
     protected String getMissingEncodingMessageSource() {
-        return "Subject: test\r\n"
-        +"MIME-Version: 1.0\r\n"
-        +"Content-Type: multipart/alternative; \r\n" 
-        +"\tboundary=\"----=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\"\r\n"
-        +"\r\n"
-        +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
-        +"X-header: test2\r\n"
-        +"Content-Type: text/plain; charset=Cp1252\r\n"
-        +"Content-Transfer-Encoding: quoted-printable\r\n"
-        +"\r\n"
-        +"second part =E8=E8\r\n"
-        +"------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX--\r\n";
+	return "Subject: test\r\n"
+		+ "MIME-Version: 1.0\r\n"
+		+ "Content-Type: multipart/alternative; \r\n"
+		+ "\tboundary=\"----=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\"\r\n"
+		+ "\r\n"
+		+ "------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX\r\n"
+		+ "X-header: test2\r\n"
+		+ "Content-Type: text/plain; charset=Cp1252\r\n"
+		+ "Content-Transfer-Encoding: quoted-printable\r\n"
+		+ "\r\n"
+		+ "second part =E8=E8\r\n"
+		+ "------=_Part_0_XXXXXXXXXXX.XXXXXXXXXXX--\r\n";
     }
 
+    @Test
     public void testGetLineCount() throws Exception {
-        MimeMessage mm = getMissingEncodingMessage();
-        try {
-            int count = mm.getLineCount();
-            assertTrue(count == -1 || count == 7);
-        } catch (Exception e) {
-            fail("Unexpected exception in getLineCount");
-        }
-        LifecycleUtil.dispose(mm);
+	MimeMessage mm = getMissingEncodingMessage();
+	try {
+	    int count = mm.getLineCount();
+	    assertTrue(count == -1 || count == 7);
+	} catch (Exception e) {
+	    fail("Unexpected exception in getLineCount");
+	}
+	LifecycleUtil.dispose(mm);
     }
 
     /**
      * This test throw a NullPointerException when the original message was
      * created by a MimeMessageInputStreamSource.
      */
+    @Test
     public void testMessageCloningViaCoW() throws Exception {
-        MimeMessage mmorig = getSimpleMessage();
+	MimeMessage mmorig = getSimpleMessage();
 
-        MimeMessage mm = new MimeMessageCopyOnWriteProxy(mmorig);
+	MimeMessage mm = new MimeMessageCopyOnWriteProxy(mmorig);
 
-        MimeMessage mm2 = new MimeMessageCopyOnWriteProxy(mm);
+	MimeMessage mm2 = new MimeMessageCopyOnWriteProxy(mm);
 
-        mm2.setHeader("Subject", "Modified");
+	mm2.setHeader("Subject", "Modified");
 
-        LifecycleUtil.dispose(mm2);
-        System.gc();
-        Thread.sleep(200);
-        // ((Disposable)mail_dup.getMessage()).dispose();
+	LifecycleUtil.dispose(mm2);
+	System.gc();
+	Thread.sleep(200);
+	// ((Disposable)mail_dup.getMessage()).dispose();
 
-        mm.setHeader("Subject", "Modified");
+	mm.setHeader("Subject", "Modified");
 
-        LifecycleUtil.dispose(mm);
-        LifecycleUtil.dispose(mmorig);
+	LifecycleUtil.dispose(mm);
+	LifecycleUtil.dispose(mmorig);
     }
 
     /**
      * This test throw a NullPointerException when the original message was
      * created by a MimeMessageInputStreamSource.
      */
+    @Test
     public void testMessageCloningViaCoW2() throws Exception {
-        MimeMessage mmorig = getSimpleMessage();
+	MimeMessage mmorig = getSimpleMessage();
 
-        MimeMessage mm = new MimeMessageCopyOnWriteProxy(mmorig);
+	MimeMessage mm = new MimeMessageCopyOnWriteProxy(mmorig);
 
-        MimeMessage mm2 = new MimeMessageCopyOnWriteProxy(mm);
+	MimeMessage mm2 = new MimeMessageCopyOnWriteProxy(mm);
 
-        LifecycleUtil.dispose(mm);
-        mm = null;
-        System.gc();
-        Thread.sleep(200);
-
-        try {
-            mm2.writeTo(System.out);
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail("Exception while writing the message to output");
-        }
+	LifecycleUtil.dispose(mm);
+	mm = null;
+	System.gc();
+	Thread.sleep(200);
+
+	try {
+	    mm2.writeTo(System.out);
+	} catch (Exception e) {
+	    e.printStackTrace();
+	    fail("Exception while writing the message to output");
+	}
 
-        LifecycleUtil.dispose(mm2);
-        LifecycleUtil.dispose(mmorig);
+	LifecycleUtil.dispose(mm2);
+	LifecycleUtil.dispose(mmorig);
     }
 
     /**
      * This test throw a NullPointerException when the original message was
      * created by a MimeMessageInputStreamSource.
      */
+    @Test
     public void testMessageCloningViaCoWSubjectLost() throws Exception {
-        MimeMessage mmorig = getSimpleMessage();
+	MimeMessage mmorig = getSimpleMessage();
 
-        MimeMessage mm = new MimeMessageCopyOnWriteProxy(mmorig);
+	MimeMessage mm = new MimeMessageCopyOnWriteProxy(mmorig);
 
-        mm.setHeader("X-Test", "foo");
-        mm.saveChanges();
+	mm.setHeader("X-Test", "foo");
+	mm.saveChanges();
 
-        assertEquals(getSimpleMessageCleanedSourceHeaderExpected(), getCleanedMessageSource(mm));
+	assertEquals(getSimpleMessageCleanedSourceHeaderExpected(), getCleanedMessageSource(mm));
 
-        LifecycleUtil.dispose(mm);
-        LifecycleUtil.dispose(mmorig);
+	LifecycleUtil.dispose(mm);
+	LifecycleUtil.dispose(mmorig);
     }
 
+    @Test
     public void testReturnPath() throws Exception {
-        MimeMessage message = getSimpleMessage();
-        assertNull(message.getHeader(RFC2822Headers.RETURN_PATH));
-        LifecycleUtil.dispose(message);
+	MimeMessage message = getSimpleMessage();
+	assertNull(message.getHeader(RFC2822Headers.RETURN_PATH));
+	LifecycleUtil.dispose(message);
     }
 
+    @Test
     public void testHeaderOrder() throws Exception {
-        MimeMessage message = getSimpleMessage();
-        message.setHeader(RFC2822Headers.RETURN_PATH, "<test@test.de>");
-        Enumeration h = message.getAllHeaderLines();
+	MimeMessage message = getSimpleMessage();
+	message.setHeader(RFC2822Headers.RETURN_PATH, "<test@test.de>");
+	Enumeration h = message.getAllHeaderLines();
 
-        assertEquals(h.nextElement(), "Return-Path: <test@test.de>");
-        LifecycleUtil.dispose(message);
+	assertEquals(h.nextElement(), "Return-Path: <test@test.de>");
+	LifecycleUtil.dispose(message);
     }
 
     /**
@@ -422,11 +429,11 @@ public class MimeMessageTest extends Tes
      * This bug was in geronimo-javamail_1.4-1.5 Has been fixed in
      * geronimo-javamail_1.4-1.6
      */
+    @Test
     public void testGeronimoIndexOutOfBounds() throws Exception {
-        String message = "                  \r\n" + "Subject: test\r\n" + "\r\n" + "Body\r\n";
+	String message = "                  \r\n" + "Subject: test\r\n" + "\r\n" + "Body\r\n";
 
-        byte[] messageBytes = message.getBytes("US-ASCII");
-        new MimeMessage(null, new ByteArrayInputStream(messageBytes));
+	byte[] messageBytes = message.getBytes("US-ASCII");
+	new MimeMessage(null, new ByteArrayInputStream(messageBytes));
     }
-
 }

Modified: james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageUtilTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageUtilTest.java?rev=1299494&r1=1299493&r2=1299494&view=diff
==============================================================================
--- james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageUtilTest.java (original)
+++ james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageUtilTest.java Mon Mar 12 00:03:03 2012
@@ -27,11 +27,11 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.Properties;
+import org.junit.Test;
 
-import junit.framework.TestCase;
-
-public class MimeMessageUtilTest extends TestCase {
+public class MimeMessageUtilTest {
 
+    @Test
     public void testWriteMimeMessageMultipartWithMessageID() throws MessagingException, IOException {
         String message = "Received: from localhost.localdomain ([127.0.0.1])\r\n" +
         "          by athlon14 (JAMES SMTP Server 2.3-dev) with SMTP ID 694\r\n" +

Modified: james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageWrapperTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageWrapperTest.java?rev=1299494&r1=1299493&r2=1299494&view=diff
==============================================================================
--- james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageWrapperTest.java (original)
+++ james/server/trunk/core/src/test/java/org/apache/james/core/MimeMessageWrapperTest.java Mon Mar 12 00:03:03 2012
@@ -16,7 +16,6 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
 package org.apache.james.core;
 
 import org.apache.james.lifecycle.api.LifecycleUtil;
@@ -32,6 +31,11 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.Enumeration;
+import org.junit.After;
+
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * Test the subject folding issue.
@@ -40,91 +44,95 @@ public class MimeMessageWrapperTest exte
 
     private final class TestableMimeMessageWrapper extends MimeMessageWrapper {
 
-        boolean messageLoadable = true;
-        boolean headersLoadable = true;
-
-        private TestableMimeMessageWrapper(MimeMessageSource source) throws MessagingException {
-            super(source);
-        }
-
-        public boolean messageParsed() {
-            return messageParsed;
-        }
-
-        public MailHeaders getInnerHeaders() {
-            return (MailHeaders) headers;
-        }
-
-        public boolean isHeadersLoadable() {
-            return headersLoadable;
-        }
-
-        public void setHeadersLoadable(boolean headersLoadable) {
-            this.headersLoadable = headersLoadable;
-        }
-
-        public boolean isMessageLoadable() {
-            return messageLoadable;
-        }
-
-        public void setMessageLoadable(boolean messageLoadable) {
-            this.messageLoadable = messageLoadable;
-        }
-
-        protected synchronized void loadHeaders() throws MessagingException {
-            if (headersLoadable) {
-                super.loadHeaders();
-            } else {
-                throw new IllegalStateException("headersLoadable disabled");
-            }
-        }
-
-        protected synchronized MailHeaders loadHeaders(InputStream is) throws MessagingException {
-            if (headersLoadable) {
-                return (MailHeaders) super.createInternetHeaders(is);
-            } else {
-                throw new IllegalStateException("headersLoadable disabled");
-            }
-        }
-
-        public synchronized void loadMessage() throws MessagingException {
-            if (messageLoadable) {
-                super.loadMessage();
-            } else {
-                throw new IllegalStateException("messageLoadable disabled");
-            }
-        }
+	boolean messageLoadable = true;
+	boolean headersLoadable = true;
 
+	private TestableMimeMessageWrapper(MimeMessageSource source) throws MessagingException {
+	    super(source);
+	}
+
+	public boolean messageParsed() {
+	    return messageParsed;
+	}
+
+	public MailHeaders getInnerHeaders() {
+	    return (MailHeaders) headers;
+	}
+
+	public boolean isHeadersLoadable() {
+	    return headersLoadable;
+	}
+
+	public void setHeadersLoadable(boolean headersLoadable) {
+	    this.headersLoadable = headersLoadable;
+	}
+
+	public boolean isMessageLoadable() {
+	    return messageLoadable;
+	}
+
+	public void setMessageLoadable(boolean messageLoadable) {
+	    this.messageLoadable = messageLoadable;
+	}
+
+	@Override
+	protected synchronized void loadHeaders() throws MessagingException {
+	    if (headersLoadable) {
+		super.loadHeaders();
+	    } else {
+		throw new IllegalStateException("headersLoadable disabled");
+	    }
+	}
+
+	protected synchronized MailHeaders loadHeaders(InputStream is) throws MessagingException {
+	    if (headersLoadable) {
+		return (MailHeaders) super.createInternetHeaders(is);
+	    } else {
+		throw new IllegalStateException("headersLoadable disabled");
+	    }
+	}
+
+	@Override
+	public synchronized void loadMessage() throws MessagingException {
+	    if (messageLoadable) {
+		super.loadMessage();
+	    } else {
+		throw new IllegalStateException("messageLoadable disabled");
+	    }
+	}
     }
-
     TestableMimeMessageWrapper mw = null;
     String content = "Subject: foo\r\nContent-Transfer-Encoding2: plain";
     String sep = "\r\n\r\n";
     String body = "bar\r\n";
 
+    @Override
     protected MimeMessage getMessageFromSources(String sources) throws Exception {
-        MimeMessageInputStreamSource mmis = null;
-        try {
-            mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream(sources.getBytes()));
-        } catch (MessagingException e) {
-        }
-        return new TestableMimeMessageWrapper(mmis);
+	MimeMessageInputStreamSource mmis = null;
+	try {
+	    mmis = new MimeMessageInputStreamSource("test", new SharedByteArrayInputStream(sources.getBytes()));
+	} catch (MessagingException e) {
+	}
+	return new TestableMimeMessageWrapper(mmis);
     }
 
-    protected void setUp() throws Exception {
-        mw = (TestableMimeMessageWrapper) getMessageFromSources(content + sep + body);
+    @Before
+    public void setUp() throws Exception {
+	mw = (TestableMimeMessageWrapper) getMessageFromSources(content + sep + body);
     }
 
-    protected void tearDown() throws Exception {
-        LifecycleUtil.dispose(mw);
+    @After
+    public void tearDown() throws Exception {
+	LifecycleUtil.dispose(mw);
     }
 
+    @Test
     public void testDeferredMessageLoading() throws MessagingException, IOException {
-        assertEquals("foo", mw.getSubject());
-        assertFalse(mw.messageParsed());
-        assertEquals("bar\r\n", mw.getContent());
-        assertTrue(mw.messageParsed());
-        assertFalse(mw.isModified());
+	assertEquals("foo", mw.getSubject());
+	assertFalse(mw.messageParsed());
+	assertEquals("bar\r\n", mw.getContent());
+	assertTrue(mw.messageParsed());
+	assertFalse(mw.isModified());
     }
 
     /**
@@ -138,175 +146,185 @@ public class MimeMessageWrapperTest exte
      * 
      * }
      */
-
+    @Test
     public void testDeferredHeaderLoading() throws MessagingException, IOException {
-        mw.setHeadersLoadable(false);
-        try {
-            assertEquals("foo", mw.getSubject());
-            fail("subject should not be loadable here, headers loading is disabled");
-        } catch (IllegalStateException e) {
-
-        }
+	mw.setHeadersLoadable(false);
+	try {
+	    assertEquals("foo", mw.getSubject());
+	    fail("subject should not be loadable here, headers loading is disabled");
+	} catch (IllegalStateException e) {
+	}
     }
 
     /**
      * See JAMES-474 MimeMessageWrapper(MimeMessage) should clone the original
      * message.
      */
+    @Test
     public void testMessageCloned() throws MessagingException, IOException, InterruptedException {
-        MimeMessageWrapper mmw = new MimeMessageWrapper(mw);
-        LifecycleUtil.dispose(mw);
-        mw = null;
-        System.gc();
-        Thread.sleep(200);
-        mmw.writeTo(System.out);
+	MimeMessageWrapper mmw = new MimeMessageWrapper(mw);
+	LifecycleUtil.dispose(mw);
+	mw = null;
+	System.gc();
+	Thread.sleep(200);
+	mmw.writeTo(System.out);
     }
 
     /*
      * Class under test for String getSubject()
      */
+    @Test
     public void testGetSubjectFolding() {
-        try {
-            StringBuffer res = new StringBuffer();
-            BufferedReader r = new BufferedReader(new InputStreamReader(mw.getInputStream()));
-            String line;
-            while (r.ready()) {
-                line = r.readLine();
-                res.append(line + "\r\n");
-            }
-            r.close();
-            assertEquals(body, res.toString());
-        } catch (MessagingException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
+	try {
+	    StringBuilder res = new StringBuilder();
+	    BufferedReader r = new BufferedReader(new InputStreamReader(mw.getInputStream()));
+	    String line;
+	    while (r.ready()) {
+		line = r.readLine();
+		res.append(line).append("\r\n");
+	    }
+	    r.close();
+	    assertEquals(body, res.toString());
+	} catch (MessagingException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	} catch (IOException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	}
     }
 
     /*
      * Class under test for String getSubject()
      */
+    @Test
     public void testAddHeaderAndSave() {
-        try {
-            mw.addHeader("X-Test", "X-Value");
+	try {
+	    mw.addHeader("X-Test", "X-Value");
 
-            assertEquals("X-Value", mw.getHeader("X-Test")[0]);
+	    assertEquals("X-Value", mw.getHeader("X-Test")[0]);
 
-            mw.saveChanges();
+	    mw.saveChanges();
 
-            ByteArrayOutputStream rawMessage = new ByteArrayOutputStream();
-            mw.writeTo(rawMessage);
+	    ByteArrayOutputStream rawMessage = new ByteArrayOutputStream();
+	    mw.writeTo(rawMessage);
 
-            assertEquals("X-Value", mw.getHeader("X-Test")[0]);
+	    assertEquals("X-Value", mw.getHeader("X-Test")[0]);
 
-            String res = rawMessage.toString();
+	    String res = rawMessage.toString();
 
-            boolean found = res.indexOf("X-Test: X-Value") > 0;
-            assertEquals(true, found);
+	    boolean found = res.indexOf("X-Test: X-Value") > 0;
+	    assertEquals(true, found);
 
-        } catch (MessagingException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
+	} catch (MessagingException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	} catch (IOException e) {
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	}
     }
 
+    @Test
     public void testReplaceReturnPathOnBadMessage() throws Exception {
-        MimeMessage message = getMessageWithBadReturnPath();
-        message.setHeader(RFC2822Headers.RETURN_PATH, "<test@test.de>");
-        Enumeration e = message.getMatchingHeaderLines(new String[] { "Return-Path" });
-        assertEquals("Return-Path: <test@test.de>", e.nextElement());
-        assertFalse(e.hasMoreElements());
-        Enumeration h = message.getAllHeaderLines();
-        assertEquals("Return-Path: <test@test.de>", h.nextElement());
-        assertFalse(h.nextElement().toString().startsWith("Return-Path:"));
-        LifecycleUtil.dispose(message);
+	MimeMessage message = getMessageWithBadReturnPath();
+	message.setHeader(RFC2822Headers.RETURN_PATH, "<test@test.de>");
+	Enumeration e = message.getMatchingHeaderLines(new String[]{"Return-Path"});
+	assertEquals("Return-Path: <test@test.de>", e.nextElement());
+	assertFalse(e.hasMoreElements());
+	Enumeration h = message.getAllHeaderLines();
+	assertEquals("Return-Path: <test@test.de>", h.nextElement());
+	assertFalse(h.nextElement().toString().startsWith("Return-Path:"));
+	LifecycleUtil.dispose(message);
     }
 
+    @Test
     public void testAddReturnPathOnBadMessage() throws Exception {
-        MimeMessage message = getMessageWithBadReturnPath();
-        message.addHeader(RFC2822Headers.RETURN_PATH, "<test@test.de>");
-        // test that we have now 2 return-paths
-        Enumeration e = message.getMatchingHeaderLines(new String[] { "Return-Path" });
-        assertEquals("Return-Path: <test@test.de>", e.nextElement());
-        assertEquals("Return-Path: <mybadreturn@example.com>", e.nextElement());
-        // test that return-path is the first line
-        Enumeration h = message.getAllHeaderLines();
-        assertEquals("Return-Path: <test@test.de>", h.nextElement());
-        LifecycleUtil.dispose(message);
+	MimeMessage message = getMessageWithBadReturnPath();
+	message.addHeader(RFC2822Headers.RETURN_PATH, "<test@test.de>");
+	// test that we have now 2 return-paths
+	Enumeration e = message.getMatchingHeaderLines(new String[]{"Return-Path"});
+	assertEquals("Return-Path: <test@test.de>", e.nextElement());
+	assertEquals("Return-Path: <mybadreturn@example.com>", e.nextElement());
+	// test that return-path is the first line
+	Enumeration h = message.getAllHeaderLines();
+	assertEquals("Return-Path: <test@test.de>", h.nextElement());
+	LifecycleUtil.dispose(message);
     }
 
     /**
      * Test for JAMES-1154
      */
+    @Test
     public void testMessageStreamWithUpatedHeaders() throws MessagingException, IOException {
-        mw.addHeader("X-Test", "X-Value");
+	mw.addHeader("X-Test", "X-Value");
 
-        assertEquals("X-Value", mw.getHeader("X-Test")[0]);
+	assertEquals("X-Value", mw.getHeader("X-Test")[0]);
 
-        mw.saveChanges();
+	mw.saveChanges();
 
-        BufferedReader reader = new BufferedReader(new InputStreamReader(mw.getMessageInputStream()));
-        String line = null;
+	BufferedReader reader = new BufferedReader(new InputStreamReader(mw.getMessageInputStream()));
+	String line = null;
 
-        boolean headerUpdated = false;
-        while ((line = reader.readLine()) != null) {
-            if (line.equals("X-Test: X-Value")) {
-                headerUpdated = true;
-                break;
-            }
-        }
-        reader.close();
-        assertTrue(headerUpdated);
+	boolean headerUpdated = false;
+	while ((line = reader.readLine()) != null) {
+	    if (line.equals("X-Test: X-Value")) {
+		headerUpdated = true;
+		break;
+	    }
+	}
+	reader.close();
+	assertTrue(headerUpdated);
     }
 
     /**
      * Test for JAMES-1154
      */
+    @Test
     public void testMessageStreamWithUpatedContent() throws MessagingException, IOException {
-        String newContent = "This is the new message content!";
-        mw.setText(newContent);
-        assertEquals(newContent, (String) mw.getContent());
-
-        mw.saveChanges();
-
-        BufferedReader reader = new BufferedReader(new InputStreamReader(mw.getMessageInputStream()));
-        String line = null;
-
-        boolean contentUpdated = false;
-        while ((line = reader.readLine()) != null) {
-            if (line.equals(newContent)) {
-                contentUpdated = true;
-                break;
-            }
-        }
-        reader.close();
-        assertTrue(contentUpdated);
+	String newContent = "This is the new message content!";
+	mw.setText(newContent);
+	assertEquals(newContent, (String) mw.getContent());
+
+	mw.saveChanges();
+
+	BufferedReader reader = new BufferedReader(new InputStreamReader(mw.getMessageInputStream()));
+	String line = null;
+
+	boolean contentUpdated = false;
+	while ((line = reader.readLine()) != null) {
+	    if (line.equals(newContent)) {
+		contentUpdated = true;
+		break;
+	    }
+	}
+	reader.close();
+	assertTrue(contentUpdated);
     }
 
+    @Test
     public void testSize() throws MessagingException {
-        assertEquals(body.length(), mw.getSize());
+	assertEquals(body.length(), mw.getSize());
     }
 
+    @Test
     public void testSizeModifiedHeaders() throws MessagingException {
-        mw.addHeader("whatever", "test");
-        assertEquals(body.length(), mw.getSize());
+	mw.addHeader("whatever", "test");
+	assertEquals(body.length(), mw.getSize());
     }
 
+    @Test
     public void testSizeModifiedBodyWithoutSave() throws MessagingException {
-        String newBody = "This is the new body of the message";
-        mw.setText(newBody);
-        assertEquals(body.length(), mw.getSize());
+	String newBody = "This is the new body of the message";
+	mw.setText(newBody);
+	assertEquals(body.length(), mw.getSize());
     }
 
+    @Test
     public void testSizeModifiedBodyWithSave() throws MessagingException {
-        String newBody = "This is the new body of the message";
-        mw.setText(newBody);
-        mw.saveChanges();
-        assertEquals(body.length(), mw.getSize());
+	String newBody = "This is the new body of the message";
+	mw.setText(newBody);
+	mw.saveChanges();
+	assertEquals(body.length(), mw.getSize());
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message