james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [1/4] james-project git commit: MAILET-103 Refactor RemoveAllMailAttributes
Date Tue, 30 Aug 2016 07:59:57 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 709cd707f -> 3f528b84d


MAILET-103 Refactor RemoveAllMailAttributes


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

Branch: refs/heads/master
Commit: afdb0e6340fa5ff5d927bcc641fcb1abf1606ad7
Parents: 93d543c
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Thu Aug 25 16:34:20 2016 +0200
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Mon Aug 29 16:16:11 2016 +0200

----------------------------------------------------------------------
 .../mailets/RemoveAllMailAttributes.java        | 24 ++++--------
 .../mailets/RemoveAllMailAttributesTest.java    | 39 +++++++++++---------
 2 files changed, 28 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/afdb0e63/mailet/standard/src/main/java/org/apache/james/transport/mailets/RemoveAllMailAttributes.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/mailets/RemoveAllMailAttributes.java
b/mailet/standard/src/main/java/org/apache/james/transport/mailets/RemoveAllMailAttributes.java
index 672bfd5..257d3bd 100644
--- a/mailet/standard/src/main/java/org/apache/james/transport/mailets/RemoveAllMailAttributes.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/mailets/RemoveAllMailAttributes.java
@@ -21,10 +21,11 @@
 
 package org.apache.james.transport.mailets;
 
-import org.apache.mailet.base.GenericMailet;
-import org.apache.mailet.Mail;
 import javax.mail.MessagingException;
 
+import org.apache.mailet.Mail;
+import org.apache.mailet.base.GenericMailet;
+
 /**
  * This mailet sets removes all attributes set on the Mail instance
  * 
@@ -37,26 +38,15 @@ import javax.mail.MessagingException;
  * @since 2.2.0
  */
 public class RemoveAllMailAttributes extends GenericMailet {
-    
-    /**
-     * Return a string describing this mailet.
-     *
-     * @return a string describing this mailet
-     */
+
+    @Override
     public String getMailetInfo() {
         return "Remove All Mail Attributes Mailet";
     }
 
-    /**
-     * Removes all attributes on the Mail
-     *
-     * @param mail the mail to process
-     *
-     * @throws MessagingException in all cases
-     */
+    @Override
     public void service(Mail mail) throws MessagingException {
-        mail.removeAllAttributes ();
+        mail.removeAllAttributes();
     }
-    
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/afdb0e63/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveAllMailAttributesTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveAllMailAttributesTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveAllMailAttributesTest.java
index 5847018..a6205e3 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveAllMailAttributesTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/RemoveAllMailAttributesTest.java
@@ -20,48 +20,51 @@
 
 package org.apache.james.transport.mailets;
 
+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.Mail;
 import org.apache.mailet.Mailet;
 import org.apache.mailet.base.test.FakeMailContext;
 import org.apache.mailet.base.test.FakeMailetConfig;
 import org.apache.mailet.base.test.MailUtil;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
 public class RemoveAllMailAttributesTest {
 
-    private Mail mockedMail;
-
+    private Mail mail;
     private Mailet mailet;
 
     @Before
     public void setUp() throws Exception {
+        FakeMailetConfig mailetConfig = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
         mailet = new RemoveAllMailAttributes();
-        FakeMailetConfig mci = new FakeMailetConfig("Test", FakeMailContext.defaultContext());
-        mailet.init(mci);
+        mailet.init(mailetConfig);
     }
 
-    private void setupMockedMail(MimeMessage m) throws ParseException {
-        mockedMail = MailUtil.createMockMail2Recipients(m);
-        mockedMail.setAttribute("org.apache.james.test.junit", "true");
+    @Test
+    public void getMailetInfoShouldReturnValue() {
+        assertThat(mailet.getMailetInfo()).isEqualTo("Remove All Mail Attributes Mailet");
     }
 
-    // test if ToProcessor works
     @Test
-    public void testRemoveAllMailAttributes() throws MessagingException {
-        setupMockedMail(null);
-        // check if the mail has a attribute
-        Assert.assertTrue(mockedMail.getAttributeNames().hasNext());
+    public void serviceShouldRemoveAllMailAttributes() throws MessagingException {
+        mail = MailUtil.createMockMail2Recipients(null);
+        mail.setAttribute("org.apache.james.test.junit", "true");
 
-        mailet.service(mockedMail);
+        mailet.service(mail);
 
-        // check if all was removed
-        Assert.assertFalse(mockedMail.getAttributeNames().hasNext());
+        assertThat(mail.getAttributeNames()).isEmpty();
     }
 
+    @Test
+    public void serviceShouldRemoveAllMailAttributesWhenNone() throws MessagingException
{
+        mail = MailUtil.createMockMail2Recipients(null);
+
+        mailet.service(mail);
+
+        assertThat(mail.getAttributeNames()).isEmpty();
+    }
 }


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