Repository: james-project
Updated Branches:
  refs/heads/master 0d019f46f -> 13989f999


JAMES-2610 MailetPipelineLogging should always log a non empty mailet info


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

Branch: refs/heads/master
Commit: 3caaf70c6ca1cd4229e65a8c6ed16671caffbfe1
Parents: edac184
Author: Antoine Duprat <adup...@linagora.com>
Authored: Tue Nov 27 11:04:05 2018 +0100
Committer: Antoine Duprat <adup...@linagora.com>
Committed: Tue Nov 27 11:04:05 2018 +0100

----------------------------------------------------------------------
 .../mailet/base/MailetPipelineLogging.java      | 16 ++++-
 .../mailet/base/MailetPipelineLoggingTest.java  | 67 ++++++++++++++++++++
 2 files changed, 81 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/3caaf70c/mailet/base/src/main/java/org/apache/mailet/base/MailetPipelineLogging.java
----------------------------------------------------------------------
diff --git 
a/mailet/base/src/main/java/org/apache/mailet/base/MailetPipelineLogging.java 
b/mailet/base/src/main/java/org/apache/mailet/base/MailetPipelineLogging.java
index ec8d0ec..f6f1919 100644
--- 
a/mailet/base/src/main/java/org/apache/mailet/base/MailetPipelineLogging.java
+++ 
b/mailet/base/src/main/java/org/apache/mailet/base/MailetPipelineLogging.java
@@ -19,19 +19,31 @@
 
 package org.apache.mailet.base;
 
+import java.util.Optional;
+
 import org.apache.mailet.Mail;
 import org.apache.mailet.Mailet;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Strings;
+
 public class MailetPipelineLogging {
     private static final Logger LOGGER = 
LoggerFactory.getLogger(MailetPipelineLogging.class);
 
     public static void logBeginOfMailetProcess(Mailet mailet, Mail mail) {
-        LOGGER.debug("Mail: {} Entering mailet: {}", mail.getState(), 
mailet.getMailetInfo());
+        LOGGER.debug("Mail: {} Entering mailet: {}", mail.getState(), 
getMailetInfo(mailet));
     }
 
+
     public static void logEndOfMailetProcess(Mailet mailet, Mail mail) {
-        LOGGER.debug("Mail: {} End of mailet: {}", mail.getState(), 
mailet.getMailetInfo());
+        LOGGER.debug("Mail: {} End of mailet: {}", mail.getState(), 
getMailetInfo(mailet));
+    }
+
+    @VisibleForTesting
+    static String getMailetInfo(Mailet mailet) {
+        return Optional.ofNullable(Strings.emptyToNull(mailet.getMailetInfo()))
+                    .orElse(mailet.getClass().getSimpleName());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/3caaf70c/mailet/base/src/test/java/org/apache/mailet/base/MailetPipelineLoggingTest.java
----------------------------------------------------------------------
diff --git 
a/mailet/base/src/test/java/org/apache/mailet/base/MailetPipelineLoggingTest.java
 
b/mailet/base/src/test/java/org/apache/mailet/base/MailetPipelineLoggingTest.java
new file mode 100644
index 0000000..1115979
--- /dev/null
+++ 
b/mailet/base/src/test/java/org/apache/mailet/base/MailetPipelineLoggingTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.apache.mailet.Mail;
+import org.junit.Before;
+import org.junit.Test;
+
+public class MailetPipelineLoggingTest {
+
+    MailetPipelineLogging testee;
+
+    @Before
+    public void setup() {
+        testee = new MailetPipelineLogging();
+    }
+
+    @Test
+    public void getMailetInfoShouldReturnMailetInfoWhenGiven() {
+        assertThat(testee.getMailetInfo(new MailetWithMailetInfo()))
+            .isEqualTo("this is my info");
+    }
+
+    private static class MailetWithMailetInfo extends GenericMailet {
+
+        @Override
+        public String getMailetInfo() {
+            return "this is my info";
+        }
+
+        @Override
+        public void service(Mail mail) {
+        }
+    }
+
+    @Test
+    public void 
getMailetInfoShouldReturnSimpleClassNameWhenMailetInfoIsEmpty() {
+        assertThat(testee.getMailetInfo(new MailetWithoutMailetInfo()))
+            .isEqualTo("MailetWithoutMailetInfo");
+    }
+
+    private static class MailetWithoutMailetInfo extends GenericMailet {
+
+        @Override
+        public void service(Mail mail) {
+        }
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to