JAMES-1877 Provide tests for SFEHelperTest

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

Branch: refs/heads/master
Commit: d584c13e5fbe8e5f554a352593f85ddba0d2f6ec
Parents: 4221b35
Author: Benoit Tellier <[email protected]>
Authored: Thu Dec 8 15:20:17 2016 +0700
Committer: Benoit Tellier <[email protected]>
Committed: Tue Jan 10 18:14:32 2017 +0700

----------------------------------------------------------------------
 ...ddressesArrayToMailAddressListConverter.java | 66 ++++++++++++++++++++
 .../mailets/remoteDelivery/MailDelivrer.java    |  4 +-
 .../mailets/remoteDelivery/SFEHelper.java       | 66 --------------------
 ...ssesArrayToMailAddressListConverterTest.java | 59 +++++++++++++++++
 4 files changed, 127 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d584c13e/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/AddressesArrayToMailAddressListConverter.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/AddressesArrayToMailAddressListConverter.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/AddressesArrayToMailAddressListConverter.java
new file mode 100644
index 0000000..d468947
--- /dev/null
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/AddressesArrayToMailAddressListConverter.java
@@ -0,0 +1,66 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.transport.mailets.remoteDelivery;
+
+import java.util.Arrays;
+import java.util.List;
+
+import javax.mail.Address;
+import javax.mail.internet.AddressException;
+
+import org.apache.mailet.MailAddress;
+import org.slf4j.Logger;
+
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableList;
+
+public class AddressesArrayToMailAddressListConverter {
+
+    public static List<MailAddress> getAddressesAsMailAddress(Address[] 
addresses, final Logger logger) {
+        if (addresses == null) {
+            return ImmutableList.of();
+        }
+        return FluentIterable.from(Arrays.asList(addresses)).transform(new 
Function<Address, Optional<MailAddress>>() {
+            @Override
+            public Optional<MailAddress> apply(Address input) {
+                try {
+                    return Optional.of(new MailAddress(input.toString()));
+                } catch (AddressException e) {
+                    logger.debug("Can't parse unsent address: " + 
e.getMessage());
+                    return Optional.absent();
+                }
+            }
+        }).filter(new Predicate<Optional<MailAddress>>() {
+            @Override
+            public boolean apply(Optional<MailAddress> input) {
+                return input.isPresent();
+            }
+        }).transform(new Function<Optional<MailAddress>, MailAddress>() {
+            @Override
+            public MailAddress apply(Optional<MailAddress> input) {
+                return input.get();
+            }
+        }).toList();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/d584c13e/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/MailDelivrer.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/MailDelivrer.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/MailDelivrer.java
index 1036734..df38243 100644
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/MailDelivrer.java
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/MailDelivrer.java
@@ -168,8 +168,8 @@ public class MailDelivrer {
     ExecutionResult handleSenderFailedException(Mail mail, SendFailedException 
sfe) {
         logSendFailedException(sfe);
         EnhancedMessagingException enhancedMessagingException = new 
EnhancedMessagingException(sfe);
-        List<MailAddress> invalidAddresses = 
SFEHelper.getAddressesAsMailAddress(sfe.getInvalidAddresses(), logger);
-        List<MailAddress> validUnsentAddresses = 
SFEHelper.getAddressesAsMailAddress(sfe.getValidUnsentAddresses(), logger);
+        List<MailAddress> invalidAddresses = 
AddressesArrayToMailAddressListConverter.getAddressesAsMailAddress(sfe.getInvalidAddresses(),
 logger);
+        List<MailAddress> validUnsentAddresses = 
AddressesArrayToMailAddressListConverter.getAddressesAsMailAddress(sfe.getValidUnsentAddresses(),
 logger);
         if (configuration.isDebug()) {
             logger.debug("Mail {} has initially recipients: {}", 
mail.getName(), mail.getRecipients());
             if (!invalidAddresses.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/d584c13e/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/SFEHelper.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/SFEHelper.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/SFEHelper.java
deleted file mode 100644
index a9650d3..0000000
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/remoteDelivery/SFEHelper.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.transport.mailets.remoteDelivery;
-
-import java.util.Arrays;
-import java.util.List;
-
-import javax.mail.Address;
-import javax.mail.internet.AddressException;
-
-import org.apache.mailet.MailAddress;
-import org.slf4j.Logger;
-
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-
-public class SFEHelper {
-
-    public static List<MailAddress> getAddressesAsMailAddress(Address[] 
addresses, final Logger logger) {
-        if (addresses == null) {
-            return ImmutableList.of();
-        }
-        return FluentIterable.from(Arrays.asList(addresses)).transform(new 
Function<Address, Optional<MailAddress>>() {
-            @Override
-            public Optional<MailAddress> apply(Address input) {
-                try {
-                    return Optional.of(new MailAddress(input.toString()));
-                } catch (AddressException e) {
-                    logger.debug("Can't parse unsent address: " + 
e.getMessage());
-                    return Optional.absent();
-                }
-            }
-        }).filter(new Predicate<Optional<MailAddress>>() {
-            @Override
-            public boolean apply(Optional<MailAddress> input) {
-                return input.isPresent();
-            }
-        }).transform(new Function<Optional<MailAddress>, MailAddress>() {
-            @Override
-            public MailAddress apply(Optional<MailAddress> input) {
-                return input.get();
-            }
-        }).toList();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/d584c13e/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/AddressesArrayToMailAddressListConverterTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/AddressesArrayToMailAddressListConverterTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/AddressesArrayToMailAddressListConverterTest.java
new file mode 100644
index 0000000..dd05c7c
--- /dev/null
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/remoteDelivery/AddressesArrayToMailAddressListConverterTest.java
@@ -0,0 +1,59 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.transport.mailets.remoteDelivery;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import javax.mail.Address;
+import javax.mail.internet.InternetAddress;
+
+import org.apache.mailet.base.MailAddressFixture;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AddressesArrayToMailAddressListConverterTest {
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(AddressesArrayToMailAddressListConverterTest.class);
+
+    @Test
+    public void getAddressesAsMailAddressShouldReturnEmptyOnNull() {
+        
assertThat(AddressesArrayToMailAddressListConverter.getAddressesAsMailAddress(null,
 LOGGER)).isEmpty();
+    }
+
+    @Test
+    public void getAddressesAsMailAddressShouldReturnEmptyOnEmpty() {
+        
assertThat(AddressesArrayToMailAddressListConverter.getAddressesAsMailAddress(new
 Address[]{}, LOGGER)).isEmpty();
+    }
+
+    @Test
+    public void getAddressesAsMailAddressShouldWorkWithSingleValue() throws 
Exception {
+        
assertThat(AddressesArrayToMailAddressListConverter.getAddressesAsMailAddress(new
 Address[]{
+            new InternetAddress(MailAddressFixture.ANY_AT_JAMES.toString())}, 
LOGGER))
+            .containsOnly(MailAddressFixture.ANY_AT_JAMES);
+    }
+
+    @Test
+    public void getAddressesAsMailAddressShouldWorkWithTwoValues() throws 
Exception {
+        
assertThat(AddressesArrayToMailAddressListConverter.getAddressesAsMailAddress(new
 Address[]{
+            new InternetAddress(MailAddressFixture.ANY_AT_JAMES.toString()),
+            new 
InternetAddress(MailAddressFixture.OTHER_AT_JAMES.toString())}, LOGGER))
+            .containsOnly(MailAddressFixture.ANY_AT_JAMES, 
MailAddressFixture.OTHER_AT_JAMES);
+    }
+}


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

Reply via email to