james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [06/10] james-project git commit: MAILET-101 use junit 4 and assertj to rewrite MailAttributesToMimeHeadersTest
Date Mon, 05 Sep 2016 13:42:05 GMT
MAILET-101 use junit 4 and assertj to rewrite MailAttributesToMimeHeadersTest


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/51ed5335
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/51ed5335
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/51ed5335

Branch: refs/heads/master
Commit: 51ed5335ec87b1651852c758ed26df491b6218e3
Parents: de8f926
Author: Matthieu Baechler <matthieu.baechler@linagora.com>
Authored: Thu Aug 25 15:05:41 2016 +0200
Committer: Matthieu Baechler <matthieu.baechler@linagora.com>
Committed: Mon Sep 5 14:17:51 2016 +0200

----------------------------------------------------------------------
 .../MailAttributesToMimeHeadersTest.java        | 93 +++++++-------------
 1 file changed, 31 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/51ed5335/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
index 5c66f3e..7c1aeed 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/MailAttributesToMimeHeadersTest.java
@@ -20,97 +20,66 @@
 
 package org.apache.james.transport.mailets;
 
-import java.io.UnsupportedEncodingException;
+
+import static org.assertj.core.api.Assertions.assertThat;
 
 import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.ParseException;
 
 import org.apache.mailet.Mailet;
 import org.apache.mailet.base.test.FakeMail;
 import org.apache.mailet.base.test.FakeMailContext;
 import org.apache.mailet.base.test.FakeMailetConfig;
 import org.apache.mailet.base.test.MailUtil;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
-import junit.framework.TestCase;
-
-public class MailAttributesToMimeHeadersTest extends TestCase {
+public class MailAttributesToMimeHeadersTest {
 
+    @Rule public ExpectedException expectedException = ExpectedException.none();
+    
     private Mailet mailet;
 
     private final String HEADER_NAME1 = "JUNIT";
-
     private final String HEADER_NAME2 = "JUNIT2";
 
     private final String MAIL_ATTRIBUTE_VALUE1 = "test1";
-
     private final String MAIL_ATTRIBUTE_VALUE2 = "test2";
 
     private final String MAIL_ATTRIBUTE_NAME1 = "org.apache.james.test";
-
     private final String MAIL_ATTRIBUTE_NAME2 = "org.apache.james.test2";
 
-    private String config1 = MAIL_ATTRIBUTE_NAME1 + "; " + HEADER_NAME1;
-
-    public MailAttributesToMimeHeadersTest(String arg0)
-            throws UnsupportedEncodingException {
-        super(arg0);
-    }
-
-    private void setConfig1(String config1) {
-        this.config1 = config1;
-    }
-
-    private String getConfig1() {
-        return config1;
-    }
-
-    private void setupMailet() throws MessagingException {
+    @Before
+    public void setup() {
         mailet = new MailAttributesToMimeHeaders();
-        FakeMailetConfig mci = new FakeMailetConfig("Test",
-                FakeMailContext.defaultContext());
-        mci.setProperty("simplemapping", getConfig1());
-        String config2 = MAIL_ATTRIBUTE_NAME2 + "; " + HEADER_NAME2;
-        mci.setProperty("simplemapping", config2);
-        mailet.init(mci);
     }
-
-    private FakeMail setupMail(MimeMessage m) throws ParseException {
-        FakeMail mockedMail = MailUtil.createMockMail2Recipients(m);
+    
+
+    @Test
+    public void shouldPutAttributesIntoHeadersWhenMappingDefined() throws MessagingException
{
+        FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
+        mailetConfig.setProperty("simplemapping", MAIL_ATTRIBUTE_NAME1 + "; " + HEADER_NAME1);
+        mailetConfig.setProperty("simplemapping", MAIL_ATTRIBUTE_NAME2 + "; " + HEADER_NAME2);
+        mailetConfig.setProperty("simplemapping", "another.attribute" + "; " + "Another-Header");
+        mailet.init(mailetConfig);
+        
+        FakeMail mockedMail = MailUtil.createMockMail2Recipients(MailUtil.createMimeMessage());
         mockedMail.setAttribute(MAIL_ATTRIBUTE_NAME1, MAIL_ATTRIBUTE_VALUE1);
         mockedMail.setAttribute(MAIL_ATTRIBUTE_NAME2, MAIL_ATTRIBUTE_VALUE2);
-        return mockedMail;
-    }
-
-    // test if the Headers were added
-    public void testHeadersArePresent() throws MessagingException {
-        FakeMail mockedMail = setupMail(MailUtil.createMimeMessage());
-        setupMailet();
+        mockedMail.setAttribute("unmatched.attribute", "value");
 
         mailet.service(mockedMail);
 
-        assertEquals(MAIL_ATTRIBUTE_VALUE1, mockedMail.getMessage().getHeader(
-                HEADER_NAME1)[0]);
-
-        assertEquals(MAIL_ATTRIBUTE_VALUE2, mockedMail.getMessage().getHeader(
-                HEADER_NAME2)[0]);
-
+        assertThat(mockedMail.getMessage().getHeader(HEADER_NAME1)).containsExactly(MAIL_ATTRIBUTE_VALUE1);
+        assertThat(mockedMail.getMessage().getHeader(HEADER_NAME2)).containsExactly(MAIL_ATTRIBUTE_VALUE2);
     }
 
-    // test if exception was thrown
-    public void testInvalidConfig() throws MessagingException {
-        boolean exception = false;
-        FakeMail mockedMail = setupMail(MailUtil.createMimeMessage());
-        setConfig1("test");
-
-        try {
-            setupMailet();
-            mailet.service(mockedMail);
-        } catch (MessagingException e) {
-            exception = true;
-        }
-
-        assertTrue(exception);
-
+    @Test
+    public void shouldThrowAtInitWhenNoSemicolumnInConfigurationEntry() throws MessagingException
{
+        FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
+        mailetConfig.setProperty("simplemapping", "invalidConfigEntry");
+        expectedException.expect(MessagingException.class);
+        mailet.init(mailetConfig);
     }
 }


---------------------------------------------------------------------
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