james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [39/50] [abbrv] james-project git commit: MAILET-115 Extract arrayToString from GenericMailet
Date Wed, 11 Jan 2017 09:26:27 GMT
MAILET-115 Extract arrayToString from GenericMailet


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

Branch: refs/heads/master
Commit: e59ef3300f3ba131564b662a834fcab0475759b3
Parents: 5a81c0d
Author: Antoine Duprat <aduprat@apache.org>
Authored: Thu Nov 17 15:25:17 2016 +0100
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Jan 11 10:03:31 2017 +0700

----------------------------------------------------------------------
 .../org/apache/mailet/base/GenericMailet.java   | 21 +------
 .../org/apache/mailet/base/StringUtils.java     | 16 +++++
 .../org/apache/mailet/base/StringUtilsTest.java | 61 ++++++++++++++++++++
 .../james/transport/mailets/DSNBounce.java      |  5 +-
 .../mailets/redirect/MailModifier.java          |  3 +-
 .../mailets/redirect/ProcessRedirectNotify.java |  5 +-
 6 files changed, 86 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e59ef330/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 20f8ca1..dabe72a 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
@@ -284,28 +284,9 @@ public abstract class GenericMailet implements Mailet, MailetConfig {
         
         if (bad.size() > 0) {
             throw new MessagingException("Unexpected init parameters found: "
-                    + arrayToString(bad.toArray()));
+                    + org.apache.mailet.base.StringUtils.arrayToString(bad.toArray()));
         }
     }
-    
-    /**
-     * Utility method for obtaining a string representation of an array of Objects.
-     */
-    public final String arrayToString(Object[] array) {
-        if (array == null) {
-            return "null";
-        }
-        StringBuilder sb = new StringBuilder(1024);
-        sb.append("[");
-        for (int i = 0; i < array.length; i++) {
-            if (i > 0) {
-                sb.append(",");
-            }
-            sb.append(array[i]);
-        }
-        sb.append("]");
-        return sb.toString();
-    }
 
 }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/e59ef330/mailet/base/src/main/java/org/apache/mailet/base/StringUtils.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/main/java/org/apache/mailet/base/StringUtils.java b/mailet/base/src/main/java/org/apache/mailet/base/StringUtils.java
index 551e20d..cc0d83e 100644
--- a/mailet/base/src/main/java/org/apache/mailet/base/StringUtils.java
+++ b/mailet/base/src/main/java/org/apache/mailet/base/StringUtils.java
@@ -23,6 +23,8 @@ import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 
+import com.google.common.base.Joiner;
+
 /**
  * Collects useful string utility methods.
  */
@@ -107,4 +109,18 @@ public final class StringUtils {
         }
         return res.toString();
     }
+    
+    /**
+     * Utility method for obtaining a string representation of an array of Objects.
+     */
+    public static String arrayToString(Object[] array) {
+        if (array == null) {
+            return "null";
+        }
+        StringBuilder sb = new StringBuilder(1024);
+        sb.append("[");
+        sb.append(Joiner.on(",").join(array));
+        sb.append("]");
+        return sb.toString();
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/e59ef330/mailet/base/src/test/java/org/apache/mailet/base/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/mailet/base/src/test/java/org/apache/mailet/base/StringUtilsTest.java b/mailet/base/src/test/java/org/apache/mailet/base/StringUtilsTest.java
new file mode 100644
index 0000000..dc0922c
--- /dev/null
+++ b/mailet/base/src/test/java/org/apache/mailet/base/StringUtilsTest.java
@@ -0,0 +1,61 @@
+/****************************************************************
+ * 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.mailet.base;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class StringUtilsTest {
+
+    @Rule
+    public ExpectedException expectedException = ExpectedException.none();
+
+    @Test
+    public void arrayToStringShouldReturnNullWhenArrayIsNull() {
+        String arrayToString = StringUtils.arrayToString(null);
+        assertThat(arrayToString).isEqualTo("null");
+    }
+
+    @Test
+    public void arrayToStringShouldReturnOnlyBracketsWhenArrayIsEmpty() {
+        String arrayToString = StringUtils.arrayToString(new String[] {});
+        assertThat(arrayToString).isEqualTo("[]");
+    }
+
+    @Test
+    public void arrayToStringShouldReturnOneElementWhenArrayContainsOneElement() {
+        String arrayToString = StringUtils.arrayToString(new String[] { "first" });
+        assertThat(arrayToString).isEqualTo("[first]");
+    }
+
+    @Test
+    public void arrayToStringShouldReturnSeparatedElementsWhenArrayContainsMultipleElements()
{
+        String arrayToString = StringUtils.arrayToString(new String[] { "first", "second",
"fourth" });
+        assertThat(arrayToString).isEqualTo("[first,second,fourth]");
+    }
+
+    @Test
+    public void arrayToStringShouldThrowWhenArrayContainsANullElement() {
+        expectedException.expect(NullPointerException.class);
+        StringUtils.arrayToString(new String[] { "first", null, "fourth" });
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/e59ef330/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
index c47645c..33fba54 100755
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
@@ -32,11 +32,11 @@ import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
 
 import org.apache.james.core.MailImpl;
-import org.apache.james.transport.mailets.redirect.RedirectNotify;
 import org.apache.james.transport.mailets.redirect.InitParameters;
 import org.apache.james.transport.mailets.redirect.MailModifier;
 import org.apache.james.transport.mailets.redirect.NotifyMailetInitParameters;
 import org.apache.james.transport.mailets.redirect.NotifyMailetsMessage;
+import org.apache.james.transport.mailets.redirect.RedirectNotify;
 import org.apache.james.transport.mailets.redirect.SpecialAddress;
 import org.apache.james.transport.mailets.redirect.TypeCode;
 import org.apache.james.transport.mailets.utils.MimeMessageModifier;
@@ -51,6 +51,7 @@ import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.DateFormats;
 import org.apache.mailet.base.RFC2822Headers;
+import org.apache.mailet.base.StringUtils;
 import org.apache.mailet.base.mail.MimeMultipartReport;
 
 import com.google.common.base.Optional;
@@ -213,7 +214,7 @@ public class DSNBounce extends RedirectNotify {
             newMail.setRecipients(getSenderAsList(originalMail));
 
             if (getInitParameters().isDebug()) {
-                log("New mail - sender: " + newMail.getSender() + ", recipients: " + arrayToString(newMail.getRecipients().toArray())
+ ", name: " + newMail.getName() + ", remoteHost: " + newMail.getRemoteHost() + ", remoteAddr:
" + newMail.getRemoteAddr() + ", state: " + newMail.getState()
+                log("New mail - sender: " + newMail.getSender() + ", recipients: " + StringUtils.arrayToString(newMail.getRecipients().toArray())
+ ", name: " + newMail.getName() + ", remoteHost: " + newMail.getRemoteHost() + ", remoteAddr:
" + newMail.getRemoteAddr() + ", state: " + newMail.getState()
                         + ", lastUpdated: " + newMail.getLastUpdated() + ", errorMessage:
" + newMail.getErrorMessage());
             }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/e59ef330/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
index 198acfd..010cdce 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/MailModifier.java
@@ -33,6 +33,7 @@ import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.DateFormats;
 import org.apache.mailet.base.RFC2822Headers;
+import org.apache.mailet.base.StringUtils;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
@@ -107,7 +108,7 @@ public class MailModifier {
         if (!recipients.isEmpty()) {
             mail.setRecipients(recipients);
             if (mailet.getInitParameters().isDebug()) {
-                mailet.log("recipients set to: " + mailet.arrayToString(recipients.toArray()));
+                mailet.log("recipients set to: " + StringUtils.arrayToString(recipients.toArray()));
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/e59ef330/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/ProcessRedirectNotify.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/ProcessRedirectNotify.java
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/ProcessRedirectNotify.java
index 12f27bb..df4eba4 100644
--- a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/ProcessRedirectNotify.java
+++ b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/redirect/ProcessRedirectNotify.java
@@ -24,6 +24,7 @@ import javax.mail.internet.MimeMessage;
 
 import org.apache.james.core.MailImpl;
 import org.apache.mailet.Mail;
+import org.apache.mailet.base.StringUtils;
 
 public class ProcessRedirectNotify {
 
@@ -53,8 +54,8 @@ public class ProcessRedirectNotify {
             mailModifier.setRemoteAddr();
             mailModifier.setRemoteHost();
 
-            if (isDebug) {
-                mailet.log("New mail - sender: " + newMail.getSender() + ", recipients: "
+ mailet.arrayToString(newMail.getRecipients().toArray()) + ", name: " + newMail.getName()
+ ", remoteHost: " + newMail.getRemoteHost() + ", remoteAddr: " + newMail.getRemoteAddr()
+ ", state: " + newMail.getState()
+            if (mailet.getInitParameters().isDebug()) {
+                mailet.log("New mail - sender: " + newMail.getSender() + ", recipients: "
+ StringUtils.arrayToString(newMail.getRecipients().toArray()) + ", name: " + newMail.getName()
+ ", remoteHost: " + newMail.getRemoteHost() + ", remoteAddr: " + newMail.getRemoteAddr()
+ ", state: " + newMail.getState()
                         + ", lastUpdated: " + newMail.getLastUpdated() + ", errorMessage:
" + newMail.getErrorMessage());
             }
 


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