MAILET-115 Addresses in InitParameters are optional

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

Branch: refs/heads/master
Commit: 9eebd2c3fb1834e213657c7302ce816d6592243c
Parents: a4094db
Author: Antoine Duprat <[email protected]>
Authored: Tue Jan 3 14:18:48 2017 +0100
Committer: Benoit Tellier <[email protected]>
Committed: Wed Jan 11 10:03:32 2017 +0700

----------------------------------------------------------------------
 .../org/apache/mailet/base/GenericMailet.java   | 11 +++
 .../james/transport/mailets/Redirect.java       | 19 ++---
 .../apache/james/transport/mailets/Resend.java  |  5 +-
 .../mailets/redirect/AddressExtractor.java      |  8 +-
 .../mailets/redirect/InitParameters.java        | 12 +--
 .../redirect/LoadedOnceInitParameters.java      | 25 +++---
 .../redirect/NotifyMailetInitParameters.java    | 31 +++----
 .../redirect/RedirectMailetInitParameters.java  | 29 +++----
 .../transport/util/SpecialAddressesUtils.java   |  7 +-
 .../james/transport/mailets/DSNBounceTest.java  |  3 +-
 .../james/transport/mailets/ForwardTest.java    |  9 +-
 .../james/transport/mailets/RedirectTest.java   | 20 ++---
 .../mailets/redirect/AddressExtractorTest.java  | 21 +++--
 .../redirect/LoadedOnceInitParametersTest.java  | 22 ++---
 .../NotifyMailetInitParametersTest.java         | 87 ++++++++++----------
 .../RedirectMailetInitParametersTest.java       | 87 ++++++++++----------
 .../util/SpecialAddressesUtilsTest.java         | 25 ++++--
 17 files changed, 223 insertions(+), 198 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java
----------------------------------------------------------------------
diff --git 
a/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java 
b/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java
index dabe72a..641d90c 100644
--- a/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java
+++ b/mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java
@@ -35,6 +35,9 @@ import org.apache.mailet.MailetConfig;
 import org.apache.mailet.MailetContext;
 import org.apache.mailet.MailetContext.LogLevel;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Strings;
+
 /**
  * GenericMailet makes writing mailets easier. It provides simple
  * versions of the lifecycle methods init and destroy and of the methods
@@ -82,6 +85,14 @@ public abstract class GenericMailet implements Mailet, 
MailetConfig {
         return MailetUtil.getInitParameter(config, name).or(defaultValue);
     }
 
+    public Optional<String> getInitParameterAsOptional(String name) {
+        String value = getInitParameter(name);
+        if (Strings.isNullOrEmpty(value)) {
+            return Optional.absent();
+        }
+        return Optional.of(value);
+    }
+
     /**
      * Gets a boolean valued init parameter that matches 'false', 'no', 'true' 
or 'yes' string values.
      */

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
index 0511e02..5992559 100644
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Redirect.java
@@ -45,7 +45,7 @@ import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.GenericMailet;
 
 import com.google.common.base.Optional;
-import com.google.common.base.Strings;
+import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
 
 /**
@@ -366,7 +366,7 @@ public class Redirect extends GenericMailet implements 
RedirectNotify {
         ImmutableList.Builder<MailAddress> builder = ImmutableList.builder();
         List<MailAddress> mailAddresses = 
AddressExtractor.withContext(getMailetContext())
                 .allowedSpecials(ALLOWED_SPECIALS)
-                .extract(recipientsOrTo);
+                .extract(Optional.of(recipientsOrTo));
         for (MailAddress address : mailAddresses) {
             builder.add(address);
         }
@@ -394,7 +394,7 @@ public class Redirect extends GenericMailet implements 
RedirectNotify {
         return MailAddressUtils.toInternetAddresses(
                 AddressExtractor.withContext(getMailetContext())
                     .allowedSpecials(ALLOWED_SPECIALS)
-                    .extract(toOrRecipients));
+                    .extract(Optional.of(toOrRecipients)));
     }
 
     private String getToOrRecipients() throws MessagingException {
@@ -408,18 +408,13 @@ public class Redirect extends GenericMailet implements 
RedirectNotify {
 
     @Override
     public MailAddress getReplyTo() throws MessagingException {
-        String replyTo = getInitParameters().getReplyTo();
-        if (Strings.isNullOrEmpty(replyTo)) {
-            return null;
-        }
-
+        Optional<String> replyTo = getInitParameters().getReplyTo();
         List<MailAddress> extractAddresses = 
AddressExtractor.withContext(getMailetContext())
                 .allowedSpecials(ImmutableList.of("postmaster", "sender", 
"null", "unaltered"))
                 .extract(replyTo);
-        if (extractAddresses.isEmpty()) {
-            return null;
-        }
-        return extractAddresses.get(0);
+        return FluentIterable.from(extractAddresses)
+                .first()
+                .orNull();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
index 696263b..d282c46 100644
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/Resend.java
@@ -44,7 +44,6 @@ import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.GenericMailet;
 
 import com.google.common.base.Optional;
-import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 
 /**
@@ -362,8 +361,8 @@ public class Resend extends GenericMailet implements 
RedirectNotify {
 
     @Override
     public MailAddress getReplyTo() throws MessagingException {
-        String replyTo = getInitParameters().getReplyTo();
-        if (Strings.isNullOrEmpty(replyTo)) {
+        Optional<String> replyTo = getInitParameters().getReplyTo();
+        if (!replyTo.isPresent()) {
             return null;
         }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AddressExtractor.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AddressExtractor.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AddressExtractor.java
index afb5e81..9b9a97c 100644
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AddressExtractor.java
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/AddressExtractor.java
@@ -57,7 +57,7 @@ public class AddressExtractor {
             return this;
         }
 
-        public List<MailAddress> extract(String addressList) throws 
MessagingException {
+        public List<MailAddress> extract(Optional<String> addressList) throws 
MessagingException {
             checkParameters();
             return new AddressExtractor(mailetContext, 
allowedSpecials).extract(addressList);
         }
@@ -81,7 +81,11 @@ public class AddressExtractor {
         this.allowedSpecials = allowedSpecials;
     }
 
-    private List<MailAddress> extract(String addressList) throws 
MessagingException {
+    private List<MailAddress> extract(Optional<String> maybeAddressList) 
throws MessagingException {
+        if (!maybeAddressList.isPresent()) {
+            return ImmutableList.of();
+        }
+        String addressList = maybeAddressList.get();
         try {
             return 
toMailAddresses(ImmutableList.copyOf(InternetAddress.parse(addressList, 
ENFORCE_RFC822_SYNTAX)));
         } catch (AddressException e) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/InitParameters.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/InitParameters.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/InitParameters.java
index b4bde6e..766038c 100644
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/InitParameters.java
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/InitParameters.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.transport.mailets.redirect;
 
+import com.google.common.base.Optional;
+
 public interface InitParameters {
 
     boolean getPassThrough();
@@ -39,15 +41,15 @@ public interface InitParameters {
 
     boolean isReply();
 
-    String getRecipients();
+    Optional<String> getRecipients();
 
-    String getTo();
+    Optional<String> getTo();
 
-    String getReversePath();
+    Optional<String> getReversePath();
 
-    String getSender();
+    Optional<String> getSender();
 
-    String getReplyTo();
+    Optional<String> getReplyTo();
 
     boolean isDebug();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/LoadedOnceInitParameters.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/LoadedOnceInitParameters.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/LoadedOnceInitParameters.java
index 8deb14e..5b7a44c 100644
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/LoadedOnceInitParameters.java
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/LoadedOnceInitParameters.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.transport.mailets.redirect;
 
+import com.google.common.base.Optional;
+
 public class LoadedOnceInitParameters implements InitParameters {
 
     public static LoadedOnceInitParameters from(InitParameters initParameters) 
{
@@ -50,15 +52,16 @@ public class LoadedOnceInitParameters implements 
InitParameters {
     private final String prefix;
     private final boolean attachError;
     private final boolean isReply;
-    private final String recipients;
-    private final String to;
-    private final String reversePath;
-    private final String sender;
-    private final String replyTo;
+    private final Optional<String> recipients;
+    private final Optional<String> to;
+    private final Optional<String> reversePath;
+    private final Optional<String> sender;
+    private final Optional<String> replyTo;
     private final boolean debug;
 
     private LoadedOnceInitParameters(boolean isStatic, boolean passThrough, 
boolean fakeDomainCheck, TypeCode inline, TypeCode attachment, String message,
-            String subject, String prefix, boolean attachError, boolean 
isReply, String recipients, String to, String reversePath, String sender, 
String replyTo, boolean debug) {
+            String subject, String prefix, boolean attachError, boolean 
isReply, 
+            Optional<String> recipients, Optional<String> to, Optional<String> 
reversePath, Optional<String> sender, Optional<String> replyTo, boolean debug) {
         this.isStatic = isStatic;
         this.passThrough = passThrough;
         this.fakeDomainCheck = fakeDomainCheck;
@@ -123,27 +126,27 @@ public class LoadedOnceInitParameters implements 
InitParameters {
     }
 
     @Override
-    public String getRecipients() {
+    public Optional<String> getRecipients() {
         return recipients;
     }
 
     @Override
-    public String getTo() {
+    public Optional<String> getTo() {
         return to;
     }
 
     @Override
-    public String getReversePath() {
+    public Optional<String> getReversePath() {
         return reversePath;
     }
 
     @Override
-    public String getSender() {
+    public Optional<String> getSender() {
         return sender;
     }
 
     @Override
-    public String getReplyTo() {
+    public Optional<String> getReplyTo() {
         return replyTo;
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/NotifyMailetInitParameters.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/NotifyMailetInitParameters.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/NotifyMailetInitParameters.java
index 94948cc..a9012de 100644
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/NotifyMailetInitParameters.java
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/NotifyMailetInitParameters.java
@@ -21,6 +21,7 @@ package org.apache.james.transport.mailets.redirect;
 
 import org.apache.mailet.base.GenericMailet;
 
+import com.google.common.base.Optional;
 import com.google.common.base.Strings;
 
 public class NotifyMailetInitParameters implements InitParameters {
@@ -86,40 +87,32 @@ public class NotifyMailetInitParameters implements 
InitParameters {
     }
 
     @Override
-    public String getRecipients() {
-        return initParameterOrNull("recipients");
-    }
-
-    private String initParameterOrNull(String parameter) {
-        String value = mailet.getInitParameter(parameter);
-        if (Strings.isNullOrEmpty(value)) {
-            return null;
-        }
-        return value;
+    public Optional<String> getRecipients() {
+        return mailet.getInitParameterAsOptional("recipients");
     }
 
     @Override
-    public String getTo() {
-        return initParameterOrNull("to");
+    public Optional<String> getTo() {
+        return mailet.getInitParameterAsOptional("to");
     }
 
     @Override
-    public String getReversePath() {
-        return initParameterOrNull("reversePath");
+    public Optional<String> getReversePath() {
+        return mailet.getInitParameterAsOptional("reversePath");
     }
 
     @Override
-    public String getSender() {
-        return initParameterOrNull("sender");
+    public Optional<String> getSender() {
+        return mailet.getInitParameterAsOptional("sender");
     }
 
     @Override
-    public String getReplyTo() {
+    public Optional<String> getReplyTo() {
         String recipients = mailet.getInitParameter("replyTo", 
mailet.getInitParameter("replyto"));
         if (Strings.isNullOrEmpty(recipients)) {
-            return null;
+            return Optional.absent();
         }
-        return recipients;
+        return Optional.of(recipients);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectMailetInitParameters.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectMailetInitParameters.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectMailetInitParameters.java
index 289d481..45dcc9b 100644
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectMailetInitParameters.java
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/RedirectMailetInitParameters.java
@@ -99,40 +99,33 @@ public class RedirectMailetInitParameters implements 
InitParameters {
 
 
     @Override
-    public String getRecipients() {
-        return initParameterOrNull("recipients");
+    public Optional<String> getRecipients() {
+        return mailet.getInitParameterAsOptional("recipients");
     }
 
-    private String initParameterOrNull(String parameter) {
-        String value = mailet.getInitParameter(parameter);
-        if (Strings.isNullOrEmpty(value)) {
-            return null;
-        }
-        return value;
-    }
 
     @Override
-    public String getTo() {
-        return initParameterOrNull("to");
+    public Optional<String> getTo() {
+        return mailet.getInitParameterAsOptional("to");
     }
 
     @Override
-    public String getReversePath() {
-        return initParameterOrNull("reversePath");
+    public Optional<String> getReversePath() {
+        return mailet.getInitParameterAsOptional("reversePath");
     }
 
     @Override
-    public String getSender() {
-        return initParameterOrNull("sender");
+    public Optional<String> getSender() {
+        return mailet.getInitParameterAsOptional("sender");
     }
 
     @Override
-    public String getReplyTo() {
+    public Optional<String> getReplyTo() {
         String recipients = mailet.getInitParameter("replyTo", 
mailet.getInitParameter("replyto"));
         if (Strings.isNullOrEmpty(recipients)) {
-            return null;
+            return Optional.absent();
         }
-        return recipients;
+        return Optional.of(recipients);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
index 9097e7a..d2ee392 100644
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/util/SpecialAddressesUtils.java
@@ -35,7 +35,6 @@ import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.RFC2822Headers;
 
 import com.google.common.base.Optional;
-import com.google.common.base.Strings;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
@@ -263,11 +262,7 @@ public class SpecialAddressesUtils {
      * If the givenAddress matches one of the allowedSpecials 
SpecialAddresses, then it's returned
      * else the givenAddress is returned.
      */
-    public Optional<MailAddress> 
getFirstSpecialAddressIfMatchingOrGivenAddress(String givenAddress, 
List<String> allowedSpecials) throws MessagingException {
-        if (Strings.isNullOrEmpty(givenAddress)) {
-            return Optional.absent();
-        }
-
+    public Optional<MailAddress> 
getFirstSpecialAddressIfMatchingOrGivenAddress(Optional<String> givenAddress, 
List<String> allowedSpecials) throws MessagingException {
         List<MailAddress> extractAddresses = AddressExtractor
                 .withContext(mailet.getMailetContext())
                 .allowedSpecials(allowedSpecials)

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java
index b47257c..5f4e249 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/DSNBounceTest.java
@@ -21,6 +21,7 @@
 package org.apache.james.transport.mailets;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.guava.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -119,7 +120,7 @@ public class DSNBounceTest {
     @Test
     public void getReversePathShouldReturnNullSpecialAddress() {
         Mail mail = null;
-        
assertThat(dsnBounce.getReversePath(mail)).isEqualTo(SpecialAddress.NULL);
+        
assertThat(dsnBounce.getReversePath(mail)).contains(SpecialAddress.NULL);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ForwardTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ForwardTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ForwardTest.java
index 6ab65ff..46bfa08 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ForwardTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/ForwardTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.transport.mailets;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.guava.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -146,13 +147,13 @@ public class ForwardTest {
     }
 
     @Test
-    public void getReversePathShouldReturnNull() throws Exception {
-        assertThat(forward.getReversePath()).isNull();
+    public void getReversePathShouldReturnAbsent() throws Exception {
+        assertThat(forward.getReversePath()).isAbsent();
     }
 
     @Test
-    public void getSenderShouldReturnNull() throws Exception {
-        assertThat(forward.getSender()).isNull();
+    public void getSenderShouldReturnAbsent() throws Exception {
+        assertThat(forward.getSender()).isAbsent();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RedirectTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RedirectTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RedirectTest.java
index cf386f8..1d6b2aa 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RedirectTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/RedirectTest.java
@@ -226,14 +226,14 @@ public class RedirectTest {
     }
 
     @Test
-    public void getReversePathShouldReturnNullWhenNoReversePathParameter() 
throws Exception {
+    public void getReversePathShouldReturnAbsentWhenNoReversePathParameter() 
throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName(MAILET_NAME)
                 .mailetContext(fakeMailContext)
                 .build();
         redirect.init(mailetConfig);
 
-        assertThat(redirect.getReversePath()).isNull();
+        assertThat(redirect.getReversePath()).isAbsent();
     }
 
     @Test
@@ -258,7 +258,7 @@ public class RedirectTest {
                 .build();
         redirect.init(mailetConfig);
 
-        assertThat(redirect.getReversePath()).isEqualTo(postmaster);
+        assertThat(redirect.getReversePath()).contains(postmaster);
     }
 
     @Test
@@ -270,11 +270,11 @@ public class RedirectTest {
                 .build();
         redirect.init(mailetConfig);
 
-        assertThat(redirect.getReversePath()).isEqualTo(new 
MailAddress("[email protected]"));
+        assertThat(redirect.getReversePath()).contains(new 
MailAddress("[email protected]"));
     }
 
     @Test
-    public void 
getReversePathWithMailShouldReturnNullWhenNotStaticAndReversePathParameters() 
throws Exception {
+    public void 
getReversePathWithMailShouldReturnAbsentWhenNotStaticAndReversePathParameters() 
throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName(MAILET_NAME)
                 .mailetContext(fakeMailContext)
@@ -286,7 +286,7 @@ public class RedirectTest {
         message.setText("This is a fake mail");
         FakeMail mail = FakeMail.from(message);
 
-        assertThat(redirect.getReversePath(mail)).isNull();
+        assertThat(redirect.getReversePath(mail)).isAbsent();
     }
 
     @Test
@@ -303,7 +303,7 @@ public class RedirectTest {
         message.setText("This is a fake mail");
         FakeMail mail = FakeMail.from(message);
 
-        assertThat(redirect.getReversePath(mail)).isEqualTo(new 
MailAddress("[email protected]"));
+        assertThat(redirect.getReversePath(mail)).contains(new 
MailAddress("[email protected]"));
     }
 
     @Test
@@ -320,7 +320,7 @@ public class RedirectTest {
         message.setText("This is a fake mail");
         FakeMail mail = FakeMail.from(message);
 
-        assertThat(redirect.getReversePath(mail)).isEqualTo(postmaster);
+        assertThat(redirect.getReversePath(mail)).contains(postmaster);
     }
 
     @Test
@@ -338,7 +338,7 @@ public class RedirectTest {
         message.setText("This is a fake mail");
         FakeMail mail = FakeMail.from(message);
 
-        assertThat(redirect.getReversePath(mail)).isEqualTo(postmaster);
+        assertThat(redirect.getReversePath(mail)).contains(postmaster);
     }
 
     @Test
@@ -355,7 +355,7 @@ public class RedirectTest {
         message.setText("This is a fake mail");
         FakeMail mail = FakeMail.from(message);
 
-        assertThat(redirect.getReversePath(mail)).isEqualTo(new 
MailAddress("[email protected]"));
+        assertThat(redirect.getReversePath(mail)).contains(new 
MailAddress("[email protected]"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/AddressExtractorTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/AddressExtractorTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/AddressExtractorTest.java
index bbb7fb9..8303a9e 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/AddressExtractorTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/AddressExtractorTest.java
@@ -59,14 +59,14 @@ public class AddressExtractorTest {
     public void extractShouldThrowWhenMailetContextIsNull() throws Exception {
         expectedException.expect(NullPointerException.class);
         AddressExtractor.withContext(null)
-            .extract("[email protected], [email protected]");
+            .extract(Optional.of("[email protected], [email protected]"));
     }
 
     @Test
     public void extractShouldThrowWhenAllowedSpecialsIsNotGiven() throws 
Exception {
         expectedException.expect(NullPointerException.class);
         AddressExtractor.withContext(mailetContext)
-            .extract("[email protected], [email protected]");
+            .extract(Optional.of("[email protected], [email protected]"));
     }
 
     @Test
@@ -74,7 +74,7 @@ public class AddressExtractorTest {
         expectedException.expect(NullPointerException.class);
         AddressExtractor.withContext(mailetContext)
             .allowedSpecials(null)
-            .extract("[email protected], [email protected]");
+            .extract(Optional.of("[email protected], [email protected]"));
     }
 
     @Test
@@ -100,10 +100,19 @@ public class AddressExtractorTest {
     }
 
     @Test
+    public void extractShouldReturnEmptyWhenAddressListIsAbsent() throws 
Exception {
+        List<MailAddress> extract = AddressExtractor.withContext(mailetContext)
+                .allowedSpecials(ImmutableList.<String> of())
+                .extract(Optional.<String> absent());
+
+        assertThat(extract).isEmpty();;
+    }
+
+    @Test
     public void extractShouldReturnListWhenParsingSucceed() throws Exception {
         List<MailAddress> extract = AddressExtractor.withContext(mailetContext)
                 .allowedSpecials(ImmutableList.<String> of())
-                .extract("[email protected], [email protected]");
+                .extract(Optional.of("[email protected], [email protected]"));
 
         assertThat(extract).containsOnly(new MailAddress("user", "james.org"),
                 new MailAddress("user2", "james.org"));
@@ -113,7 +122,7 @@ public class AddressExtractorTest {
     public void extractShouldReturnSpecialAddressesWhenAddressesAreSpecial() 
throws Exception {
         List<MailAddress> extract = AddressExtractor.withContext(mailetContext)
                 .allowedSpecials(ImmutableList.<String> of("postmaster", "to"))
-                .extract("postmaster, to");
+                .extract(Optional.of("postmaster, to"));
 
         assertThat(extract).containsOnly(new MailAddress("postmaster", 
"james.org"),
                 new MailAddress("to", "address.marker"));
@@ -124,7 +133,7 @@ public class AddressExtractorTest {
         expectedException.expect(MessagingException.class);
         AddressExtractor.withContext(mailetContext)
             .allowedSpecials(ImmutableList.<String> of())
-            .extract("user@james@org");
+            .extract(Optional.of("user@james@org"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/LoadedOnceInitParametersTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/LoadedOnceInitParametersTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/LoadedOnceInitParametersTest.java
index dc54458..5fa59b0 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/LoadedOnceInitParametersTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/LoadedOnceInitParametersTest.java
@@ -23,6 +23,8 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import org.junit.Test;
 
+import com.google.common.base.Optional;
+
 public class LoadedOnceInitParametersTest {
 
     @Test
@@ -97,28 +99,28 @@ public class LoadedOnceInitParametersTest {
         }
 
         @Override
-        public String getRecipients() {
-            return "recipients";
+        public Optional<String> getRecipients() {
+            return Optional.of("recipients");
         }
 
         @Override
-        public String getTo() {
-            return "to";
+        public Optional<String> getTo() {
+            return Optional.of("to");
         }
 
         @Override
-        public String getReversePath() {
-            return "reversePath";
+        public Optional<String> getReversePath() {
+            return Optional.of("reversePath");
         }
 
         @Override
-        public String getSender() {
-            return "sender";
+        public Optional<String> getSender() {
+            return Optional.of("sender");
         }
 
         @Override
-        public String getReplyTo() {
-            return "replyTo";
+        public Optional<String> getReplyTo() {
+            return Optional.of("replyTo");
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/NotifyMailetInitParametersTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/NotifyMailetInitParametersTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/NotifyMailetInitParametersTest.java
index bcb84f9..874fa61 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/NotifyMailetInitParametersTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/NotifyMailetInitParametersTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.transport.mailets.redirect;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.guava.api.Assertions.assertThat;
 
 import javax.mail.MessagingException;
 
@@ -29,6 +30,8 @@ import org.apache.mailet.base.test.FakeMailetConfig;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.base.Optional;
+
 public class NotifyMailetInitParametersTest {
 
     private GenericMailet mailet;
@@ -303,12 +306,12 @@ public class NotifyMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String recipients = testee.getRecipients();
-        assertThat(recipients).isEqualTo("[email protected], [email protected]");
+        Optional<String> recipients = testee.getRecipients();
+        assertThat(recipients).contains("[email protected], [email protected]");
     }
 
     @Test
-    public void getRecipientsShouldReturnNullWhenEmpty() throws Exception {
+    public void getRecipientsShouldReturnAbsentWhenEmpty() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .setProperty("recipients", "")
@@ -316,20 +319,20 @@ public class NotifyMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String recipients = testee.getRecipients();
-        assertThat(recipients).isNull();
+        Optional<String> recipients = testee.getRecipients();
+        assertThat(recipients).isAbsent();
     }
 
     @Test
-    public void getRecipientsShouldReturnNullWhenNotSet() throws Exception {
+    public void getRecipientsShouldReturnAbsentWhenNotSet() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .build();
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String recipients = testee.getRecipients();
-        assertThat(recipients).isNull();
+        Optional<String> recipients = testee.getRecipients();
+        assertThat(recipients).isAbsent();
     }
 
     @Test
@@ -341,12 +344,12 @@ public class NotifyMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String to = testee.getTo();
-        assertThat(to).isEqualTo("[email protected], [email protected]");
+        Optional<String> to = testee.getTo();
+        assertThat(to).contains("[email protected], [email protected]");
     }
 
     @Test
-    public void getToShouldReturnNullWhenEmpty() throws Exception {
+    public void getToShouldReturnAbsentWhenEmpty() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .setProperty("to", "")
@@ -354,20 +357,20 @@ public class NotifyMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String to = testee.getTo();
-        assertThat(to).isNull();
+        Optional<String> to = testee.getTo();
+        assertThat(to).isAbsent();
     }
 
     @Test
-    public void getToShouldReturnNullWhenNotSet() throws Exception {
+    public void getToShouldReturnAbsentWhenNotSet() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .build();
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String to = testee.getTo();
-        assertThat(to).isNull();
+        Optional<String> to = testee.getTo();
+        assertThat(to).isAbsent();
     }
 
     @Test
@@ -379,12 +382,12 @@ public class NotifyMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String reversePath = testee.getReversePath();
-        assertThat(reversePath).isEqualTo("[email protected], [email protected]");
+        Optional<String> reversePath = testee.getReversePath();
+        assertThat(reversePath).contains("[email protected], [email protected]");
     }
 
     @Test
-    public void getReversePathShouldReturnNullWhenEmpty() throws Exception {
+    public void getReversePathShouldReturnAbsentWhenEmpty() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .setProperty("reversePath", "")
@@ -392,20 +395,20 @@ public class NotifyMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String reversePath = testee.getReversePath();
-        assertThat(reversePath).isNull();
+        Optional<String> reversePath = testee.getReversePath();
+        assertThat(reversePath).isAbsent();
     }
 
     @Test
-    public void getReversePathShouldReturnNullWhenNotSet() throws Exception {
+    public void getReversePathShouldReturnAbsentWhenNotSet() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .build();
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String reversePath = testee.getReversePath();
-        assertThat(reversePath).isNull();
+        Optional<String> reversePath = testee.getReversePath();
+        assertThat(reversePath).isAbsent();
     }
 
     @Test
@@ -417,12 +420,12 @@ public class NotifyMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String sender = testee.getSender();
-        assertThat(sender).isEqualTo("[email protected], [email protected]");
+        Optional<String> sender = testee.getSender();
+        assertThat(sender).contains("[email protected], [email protected]");
     }
 
     @Test
-    public void getSenderShouldReturnNullWhenEmpty() throws Exception {
+    public void getSenderShouldReturnAbsentWhenEmpty() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .setProperty("sender", "")
@@ -430,20 +433,20 @@ public class NotifyMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String sender = testee.getSender();
-        assertThat(sender).isNull();
+        Optional<String> sender = testee.getSender();
+        assertThat(sender).isAbsent();
     }
 
     @Test
-    public void getSenderShouldReturnNullWhenNotSet() throws Exception {
+    public void getSenderShouldReturnAbsentWhenNotSet() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .build();
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String sender = testee.getSender();
-        assertThat(sender).isNull();
+        Optional<String> sender = testee.getSender();
+        assertThat(sender).isAbsent();
     }
 
     @Test
@@ -455,8 +458,8 @@ public class NotifyMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String replyTo = testee.getReplyTo();
-        assertThat(replyTo).isEqualTo("[email protected], [email protected]");
+        Optional<String> replyTo = testee.getReplyTo();
+        assertThat(replyTo).contains("[email protected], [email protected]");
     }
 
     @Test
@@ -468,12 +471,12 @@ public class NotifyMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String replyTo = testee.getReplyTo();
-        assertThat(replyTo).isEqualTo("[email protected], [email protected]");
+        Optional<String> replyTo = testee.getReplyTo();
+        assertThat(replyTo).contains("[email protected], [email protected]");
     }
 
     @Test
-    public void getReplyToShouldReturnNullWhenEmpty() throws Exception {
+    public void getReplyToShouldReturnAbsentWhenEmpty() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .setProperty("replyTo", "")
@@ -481,20 +484,20 @@ public class NotifyMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String replyTo = testee.getReplyTo();
-        assertThat(replyTo).isNull();
+        Optional<String> replyTo = testee.getReplyTo();
+        assertThat(replyTo).isAbsent();
     }
 
     @Test
-    public void getReplyToShouldReturnNullWhenNotSet() throws Exception {
+    public void getReplyToShouldReturnAbsentWhenNotSet() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .build();
         mailet.init(mailetConfig);
         InitParameters testee = NotifyMailetInitParameters.from(mailet);
 
-        String replyTo = testee.getReplyTo();
-        assertThat(replyTo).isNull();
+        Optional<String> replyTo = testee.getReplyTo();
+        assertThat(replyTo).isAbsent();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/RedirectMailetInitParametersTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/RedirectMailetInitParametersTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/RedirectMailetInitParametersTest.java
index 6d74167..7134935 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/RedirectMailetInitParametersTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/redirect/RedirectMailetInitParametersTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.transport.mailets.redirect;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.guava.api.Assertions.assertThat;
 
 import javax.mail.MessagingException;
 
@@ -29,6 +30,8 @@ import org.apache.mailet.base.test.FakeMailetConfig;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.base.Optional;
+
 public class RedirectMailetInitParametersTest {
 
     private GenericMailet mailet;
@@ -329,12 +332,12 @@ public class RedirectMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String recipients = testee.getRecipients();
-        assertThat(recipients).isEqualTo("[email protected], [email protected]");
+        Optional<String> recipients = testee.getRecipients();
+        assertThat(recipients).contains("[email protected], [email protected]");
     }
 
     @Test
-    public void getRecipientsShouldReturnNullWhenEmpty() throws Exception {
+    public void getRecipientsShouldReturnAbsentWhenEmpty() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .setProperty("recipients", "")
@@ -342,20 +345,20 @@ public class RedirectMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String recipients = testee.getRecipients();
-        assertThat(recipients).isNull();
+        Optional<String> recipients = testee.getRecipients();
+        assertThat(recipients).isAbsent();
     }
 
     @Test
-    public void getRecipientsShouldReturnNullWhenNotSet() throws Exception {
+    public void getRecipientsShouldReturnAbsentWhenNotSet() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .build();
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String recipients = testee.getRecipients();
-        assertThat(recipients).isNull();
+        Optional<String> recipients = testee.getRecipients();
+        assertThat(recipients).isAbsent();
     }
 
     @Test
@@ -367,12 +370,12 @@ public class RedirectMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String to = testee.getTo();
-        assertThat(to).isEqualTo("[email protected], [email protected]");
+        Optional<String> to = testee.getTo();
+        assertThat(to).contains("[email protected], [email protected]");
     }
 
     @Test
-    public void getToShouldReturnNullWhenEmpty() throws Exception {
+    public void getToShouldReturnAbsentWhenEmpty() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .setProperty("to", "")
@@ -380,20 +383,20 @@ public class RedirectMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String to = testee.getTo();
-        assertThat(to).isNull();
+        Optional<String> to = testee.getTo();
+        assertThat(to).isAbsent();
     }
 
     @Test
-    public void getToShouldReturnNullWhenNotSet() throws Exception {
+    public void getToShouldReturnAbsentWhenNotSet() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .build();
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String to = testee.getTo();
-        assertThat(to).isNull();
+        Optional<String> to = testee.getTo();
+        assertThat(to).isAbsent();
     }
 
     @Test
@@ -405,12 +408,12 @@ public class RedirectMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String reversePath = testee.getReversePath();
-        assertThat(reversePath).isEqualTo("[email protected], [email protected]");
+        Optional<String> reversePath = testee.getReversePath();
+        assertThat(reversePath).contains("[email protected], [email protected]");
     }
 
     @Test
-    public void getReversePathShouldReturnNullWhenEmpty() throws Exception {
+    public void getReversePathShouldReturnAbsentWhenEmpty() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .setProperty("reversePath", "")
@@ -418,20 +421,20 @@ public class RedirectMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String reversePath = testee.getReversePath();
-        assertThat(reversePath).isNull();
+        Optional<String> reversePath = testee.getReversePath();
+        assertThat(reversePath).isAbsent();
     }
 
     @Test
-    public void getReversePathShouldReturnNullWhenNotSet() throws Exception {
+    public void getReversePathShouldReturnAbsentWhenNotSet() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .build();
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String reversePath = testee.getReversePath();
-        assertThat(reversePath).isNull();
+        Optional<String> reversePath = testee.getReversePath();
+        assertThat(reversePath).isAbsent();
     }
 
     @Test
@@ -443,12 +446,12 @@ public class RedirectMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String sender = testee.getSender();
-        assertThat(sender).isEqualTo("[email protected], [email protected]");
+        Optional<String> sender = testee.getSender();
+        assertThat(sender).contains("[email protected], [email protected]");
     }
 
     @Test
-    public void getSenderShouldReturnNullWhenEmpty() throws Exception {
+    public void getSenderShouldReturnAbsentWhenEmpty() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .setProperty("sender", "")
@@ -456,20 +459,20 @@ public class RedirectMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String sender = testee.getSender();
-        assertThat(sender).isNull();
+        Optional<String> sender = testee.getSender();
+        assertThat(sender).isAbsent();
     }
 
     @Test
-    public void getSenderShouldReturnNullWhenNotSet() throws Exception {
+    public void getSenderShouldReturnAbsentWhenNotSet() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .build();
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String sender = testee.getSender();
-        assertThat(sender).isNull();
+        Optional<String> sender = testee.getSender();
+        assertThat(sender).isAbsent();
     }
 
     @Test
@@ -481,8 +484,8 @@ public class RedirectMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String replyTo = testee.getReplyTo();
-        assertThat(replyTo).isEqualTo("[email protected], [email protected]");
+        Optional<String> replyTo = testee.getReplyTo();
+        assertThat(replyTo).contains("[email protected], [email protected]");
     }
 
     @Test
@@ -494,12 +497,12 @@ public class RedirectMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String replyTo = testee.getReplyTo();
-        assertThat(replyTo).isEqualTo("[email protected], [email protected]");
+        Optional<String> replyTo = testee.getReplyTo();
+        assertThat(replyTo).contains("[email protected], [email protected]");
     }
 
     @Test
-    public void getReplyToShouldReturnNullWhenEmpty() throws Exception {
+    public void getReplyToShouldReturnAbsentWhenEmpty() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .setProperty("replyTo", "")
@@ -507,20 +510,20 @@ public class RedirectMailetInitParametersTest {
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String replyTo = testee.getReplyTo();
-        assertThat(replyTo).isNull();
+        Optional<String> replyTo = testee.getReplyTo();
+        assertThat(replyTo).isAbsent();
     }
 
     @Test
-    public void getReplyToShouldReturnNullWhenNotSet() throws Exception {
+    public void getReplyToShouldReturnAbsentWhenNotSet() throws Exception {
         FakeMailetConfig mailetConfig = FakeMailetConfig.builder()
                 .mailetName("mailet")
                 .build();
         mailet.init(mailetConfig);
         InitParameters testee = RedirectMailetInitParameters.from(mailet);
 
-        String replyTo = testee.getReplyTo();
-        assertThat(replyTo).isNull();
+        Optional<String> replyTo = testee.getReplyTo();
+        assertThat(replyTo).isAbsent();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/9eebd2c3/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SpecialAddressesUtilsTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SpecialAddressesUtilsTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SpecialAddressesUtilsTest.java
index 670d518..52d9e68 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SpecialAddressesUtilsTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/util/SpecialAddressesUtilsTest.java
@@ -39,13 +39,18 @@ import org.apache.mailet.base.MailAddressFixture;
 import org.apache.mailet.base.RFC2822Headers;
 import org.apache.mailet.base.test.FakeMail;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 
 public class SpecialAddressesUtilsTest {
 
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
     private MailAddress postmaster;
     private SpecialAddressesUtils testee;
 
@@ -449,22 +454,28 @@ public class SpecialAddressesUtilsTest {
     }
 
     @Test
-    public void 
getFirstSpecialAddressIfMatchingOrGivenAddressShouldReturnAbsentWhenSenderInitParameterIsNull()
 throws Exception {
-        Optional<MailAddress> sender = 
testee.getFirstSpecialAddressIfMatchingOrGivenAddress(null, 
ImmutableList.of("postmaster", "sender", "unaltered"));
+    public void 
getFirstSpecialAddressIfMatchingOrGivenAddressShouldThrowWhenSenderInitParameterIsNull()
 throws Exception {
+        expectedException.expect(NullPointerException.class);
+        testee.getFirstSpecialAddressIfMatchingOrGivenAddress(null, 
ImmutableList.of("postmaster", "sender", "unaltered"));
+    }
+
+    @Test
+    public void 
getFirstSpecialAddressIfMatchingOrGivenAddressShouldReturnAbsentWhenSenderInitParameterIsAbsent()
 throws Exception {
+        Optional<MailAddress> sender = 
testee.getFirstSpecialAddressIfMatchingOrGivenAddress(Optional.<String> 
absent(), ImmutableList.of("postmaster", "sender", "unaltered"));
 
         assertThat(sender).isAbsent();
     }
 
     @Test
     public void 
getFirstSpecialAddressIfMatchingOrGivenAddressShouldReturnAbsentWhenSenderInitParameterIsEmpty()
 throws Exception {
-        Optional<MailAddress> sender = 
testee.getFirstSpecialAddressIfMatchingOrGivenAddress("", 
ImmutableList.of("postmaster", "sender", "unaltered"));
+        Optional<MailAddress> sender = 
testee.getFirstSpecialAddressIfMatchingOrGivenAddress(Optional.of(""), 
ImmutableList.of("postmaster", "sender", "unaltered"));
 
         assertThat(sender).isAbsent();
     }
 
     @Test
     public void 
getFirstSpecialAddressIfMatchingOrGivenAddressShouldReturnGivenAddressWhenNoSpecialAddressMatches()
 throws Exception {
-        Optional<MailAddress> sender = 
testee.getFirstSpecialAddressIfMatchingOrGivenAddress("[email protected]", 
ImmutableList.of("postmaster", "sender", "unaltered"));
+        Optional<MailAddress> sender = 
testee.getFirstSpecialAddressIfMatchingOrGivenAddress(Optional.of("[email protected]"),
 ImmutableList.of("postmaster", "sender", "unaltered"));
 
         MailAddress expectedMailAddress = new MailAddress("test", "james.org");
         assertThat(sender).contains(expectedMailAddress);
@@ -472,14 +483,14 @@ public class SpecialAddressesUtilsTest {
 
     @Test
     public void 
getFirstSpecialAddressIfMatchingOrGivenAddressShouldReturnFirstSpecialAddressWhenMatching()
 throws Exception {
-        Optional<MailAddress> sender = 
testee.getFirstSpecialAddressIfMatchingOrGivenAddress("postmaster", 
ImmutableList.of("postmaster", "sender", "unaltered"));
+        Optional<MailAddress> sender = 
testee.getFirstSpecialAddressIfMatchingOrGivenAddress(Optional.of("postmaster"),
 ImmutableList.of("postmaster", "sender", "unaltered"));
 
         assertThat(sender).contains(postmaster);
     }
 
     @Test
     public void 
getFirstSpecialAddressIfMatchingOrGivenAddressShouldReturnSecondSpecialAddressWhenMatching()
 throws Exception {
-        Optional<MailAddress> sender = 
testee.getFirstSpecialAddressIfMatchingOrGivenAddress("sender", 
ImmutableList.of("postmaster", "sender", "unaltered"));
+        Optional<MailAddress> sender = 
testee.getFirstSpecialAddressIfMatchingOrGivenAddress(Optional.of("sender"), 
ImmutableList.of("postmaster", "sender", "unaltered"));
 
         MailAddress expectedMailAddress = SpecialAddress.SENDER;
         assertThat(sender).contains(expectedMailAddress);
@@ -487,7 +498,7 @@ public class SpecialAddressesUtilsTest {
 
     @Test
     public void 
getFirstSpecialAddressIfMatchingOrGivenAddressShouldReturnLastSpecialAddressWhenMatching()
 throws Exception {
-        Optional<MailAddress> sender = 
testee.getFirstSpecialAddressIfMatchingOrGivenAddress("unaltered", 
ImmutableList.of("postmaster", "sender", "unaltered"));
+        Optional<MailAddress> sender = 
testee.getFirstSpecialAddressIfMatchingOrGivenAddress(Optional.of("unaltered"), 
ImmutableList.of("postmaster", "sender", "unaltered"));
 
         MailAddress expectedMailAddress = SpecialAddress.UNALTERED;
         assertThat(sender).contains(expectedMailAddress);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to