james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [1/3] james-project git commit: MAILET-100 migrate AddSubjectPrefixTest to modern style
Date Fri, 26 Aug 2016 07:41:49 GMT
Repository: james-project
Updated Branches:
  refs/heads/master f91fc653f -> 240bed003


MAILET-100 migrate AddSubjectPrefixTest to modern style


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

Branch: refs/heads/master
Commit: 0f87b4358b05cc5239269f176888bcd77fb45991
Parents: f91fc65
Author: Matthieu Baechler <matthieu.baechler@linagora.com>
Authored: Wed Aug 24 17:33:19 2016 +0200
Committer: Matthieu Baechler <matthieu.baechler@linagora.com>
Committed: Thu Aug 25 17:13:54 2016 +0200

----------------------------------------------------------------------
 .../transport/mailets/AddSubjectPrefixTest.java | 129 ++++++++-----------
 1 file changed, 52 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0f87b435/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java
b/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java
index d7425df..b2c102b 100644
--- a/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java
+++ b/mailet/standard/src/test/java/org/apache/james/transport/mailets/AddSubjectPrefixTest.java
@@ -20,105 +20,80 @@
 
 package org.apache.james.transport.mailets;
 
-import junit.framework.TestCase;
-
-import org.apache.james.transport.mailets.AddSubjectPrefix;
-import org.apache.mailet.base.test.FakeMailContext;
-import org.apache.mailet.base.test.FakeMailetConfig;
-import org.apache.mailet.base.test.MailUtil;
-import org.apache.mailet.Mail;
-import org.apache.mailet.Mailet;
+import static org.assertj.core.api.Assertions.assertThat;
 
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
-import javax.mail.internet.ParseException;
-import java.io.UnsupportedEncodingException;
-
-public class AddSubjectPrefixTest extends TestCase {
 
-    private MimeMessage mockedMimeMessage;
+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;
 
-    private Mail mockedMail;
+public class AddSubjectPrefixTest {
 
+    @Rule public ExpectedException expectedException = ExpectedException.none();
+    
     private Mailet mailet;
+    private FakeMailetConfig mailetConfig;
 
-    private final String SUBJECT_PREFIX = "JUNIT";
-
-    private String subject = null;
-
-    public AddSubjectPrefixTest(String arg0)
-            throws UnsupportedEncodingException {
-        super(arg0);
-    }
-
-    private void setSubject(String subject) {
-        this.subject = subject;
-    }
-
-    private void setupMockedMimeMessage() throws MessagingException {
-        mockedMimeMessage = MailUtil.createMimeMessageWithSubject(subject);
-    }
-
-    private void setupMockedMail(MimeMessage m) throws ParseException {
-        mockedMail = MailUtil.createMockMail2Recipients(m);
-    }
-
-    private void setupMailet() throws MessagingException {
-        setupMockedMimeMessage();
+    @Before
+    public void setup() {
         mailet = new AddSubjectPrefix();
-        FakeMailetConfig mci = new FakeMailetConfig("Test", new FakeMailContext());
-        mci.setProperty("subjectPrefix", SUBJECT_PREFIX);
-
-        mailet.init(mci);
+        mailetConfig = new FakeMailetConfig("Test", new FakeMailContext());
     }
-
-    private void setupInvalidMailet() throws MessagingException {
-        setupMockedMimeMessage();
-        mailet = new AddSubjectPrefix();
-        FakeMailetConfig mci = new FakeMailetConfig("Test", new FakeMailContext());
-        mci.setProperty("subjectPrefix", "");
-
-        mailet.init(mci);
+    
+    @Test
+    public void shouldAddPrefixToSubject() throws MessagingException {
+        mailetConfig.setProperty("subjectPrefix", "JUNIT");
+        mailet.init(mailetConfig);
+
+        MimeMessage mockedMimeMessage = MailUtil.createMimeMessageWithSubject("test");
+        FakeMail mail = MailUtil.createMockMail2Recipients(mockedMimeMessage);
+        
+        mailet.service(mail);
+
+        assertThat(mail.getMessage().getSubject()).isEqualTo("JUNIT test");
     }
 
-    // test if prefix was added
-    public void testSubjectPrefixWasAdded() throws MessagingException {
-        setSubject("test");
-        setupMockedMimeMessage();
-        setupMockedMail(mockedMimeMessage);
-        setupMailet();
+    @Test
+    public void shouldDefinePrefixAsSubjectWhenNoSubject() throws MessagingException {
+        mailetConfig.setProperty("subjectPrefix", "JUNIT");
+        mailet.init(mailetConfig);
 
-        mailet.service(mockedMail);
+        String noSubject = null;
+        MimeMessage mockedMimeMessage = MailUtil.createMimeMessageWithSubject(noSubject);
+        FakeMail mail = MailUtil.createMockMail2Recipients(mockedMimeMessage);
 
-        assertEquals(SUBJECT_PREFIX + " " + subject, mockedMail.getMessage().getSubject());
+        mailet.service(mail);
 
+        assertThat(mail.getMessage().getSubject()).isEqualTo("JUNIT");
     }
 
-    // test if prefix was added to message without subject
-    public void testSubjectPrefixWasAddedWithoutSubject()
-            throws MessagingException {
-        setupMockedMimeMessage();
-        setupMockedMail(mockedMimeMessage);
-        setupMailet();
+    @Test
+    public void shouldDefinePrefixAsSubjectWhenEmptySubject() throws MessagingException {
+        mailetConfig.setProperty("subjectPrefix", "JUNIT");
+        mailet.init(mailetConfig);
 
-        mailet.service(mockedMail);
+        MimeMessage mockedMimeMessage = MailUtil.createMimeMessageWithSubject("");
+        FakeMail mail = MailUtil.createMockMail2Recipients(mockedMimeMessage);
 
-        assertEquals(SUBJECT_PREFIX, mockedMail.getMessage().getSubject());
+        mailet.service(mail);
 
+        assertThat(mail.getMessage().getSubject()).isEqualTo("JUNIT");
     }
+    
+    @Test
+    public void shouldThrowWhenEmptyPrefix() throws MessagingException {
+        mailetConfig.setProperty("subjectPrefix", "");
 
-    // test if exception was thrown cause missing configure value
-    public void testThrowException() throws MessagingException {
-        boolean exceptionThrown = false;
-        setupMockedMimeMessage();
-        setupMockedMail(mockedMimeMessage);
-
-        try {
-            setupInvalidMailet();
-        } catch (MessagingException m) {
-            exceptionThrown = true;
-        }
-        assertTrue(exceptionThrown);
+        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