james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [05/10] james-project git commit: MAILET-112 Give possibility to set message of FakeMail from a MimeMessage
Date Tue, 30 Aug 2016 18:01:40 GMT
MAILET-112 Give possibility to set message of FakeMail from a MimeMessage


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

Branch: refs/heads/master
Commit: a5195b34a5f7c2754a98bd3690da184c9062fc61
Parents: 284424d
Author: Benoit Tellier <btellier@linagora.com>
Authored: Tue Aug 30 12:02:05 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Aug 31 00:59:27 2016 +0700

----------------------------------------------------------------------
 .../test/java/org/apache/mailet/base/test/FakeMail.java  | 11 +++++++++++
 1 file changed, 11 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a5195b34/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java
index 31f0ebb..12b0a7c 100644
--- a/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java
+++ b/mailet/base/src/test/java/org/apache/mailet/base/test/FakeMail.java
@@ -40,6 +40,7 @@ import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
 public class FakeMail implements Mail {
@@ -62,6 +63,7 @@ public class FakeMail implements Mail {
     public static class Builder {
 
         private Optional<String> fileName = Optional.absent();
+        private Optional<MimeMessage> mimeMessage = Optional.absent();
         private List<MailAddress> recipients = new ArrayList<MailAddress>();
         private MailAddress sender;
 
@@ -70,6 +72,11 @@ public class FakeMail implements Mail {
             return this;
         }
 
+        public Builder mimeMessage(MimeMessage mimeMessage) {
+            this.mimeMessage = Optional.of(mimeMessage);
+            return this;
+        }
+
         public Builder recipients(List<MailAddress> recipients) {
             this.recipients.addAll(recipients);
             return this;
@@ -91,10 +98,14 @@ public class FakeMail implements Mail {
         }
 
         public FakeMail build() throws MessagingException {
+            Preconditions.checkState(!(fileName.isPresent() && mimeMessage.isPresent()),
"You can not specify a MimeMessage object when you alredy set Content from a file");
             FakeMail mail = new FakeMail();
             if (fileName.isPresent()) {
                 mail.setMessage(new MimeMessage(Session.getInstance(new Properties()), ClassLoader.getSystemResourceAsStream(fileName.get())));
             }
+            if (mimeMessage.isPresent()) {
+                mail.setMessage(mimeMessage.get());
+            }
             mail.setSender(sender);
             mail.setRecipients(recipients);
             return mail;


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