james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [5/9] james-project git commit: JAMES-2578 Add a convenience Attribute::convertToAttribute method
Date Mon, 05 Nov 2018 14:26:52 GMT
JAMES-2578 Add a convenience Attribute::convertToAttribute method


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

Branch: refs/heads/master
Commit: f1517bd34fc0ba9317153ae0a7b9d67428583555
Parents: c68e430
Author: Benoit Tellier <btellier@linagora.com>
Authored: Fri Nov 2 16:07:20 2018 +0700
Committer: Antoine Duprat <aduprat@linagora.com>
Committed: Mon Nov 5 11:58:06 2018 +0100

----------------------------------------------------------------------
 mailet/api/src/main/java/org/apache/mailet/Attribute.java   | 7 +++++++
 .../api/src/test/java/org/apache/mailet/AttributeTest.java  | 9 +++++++++
 2 files changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f1517bd3/mailet/api/src/main/java/org/apache/mailet/Attribute.java
----------------------------------------------------------------------
diff --git a/mailet/api/src/main/java/org/apache/mailet/Attribute.java b/mailet/api/src/main/java/org/apache/mailet/Attribute.java
index a4d5d7c..92c6164 100644
--- a/mailet/api/src/main/java/org/apache/mailet/Attribute.java
+++ b/mailet/api/src/main/java/org/apache/mailet/Attribute.java
@@ -32,6 +32,13 @@ import com.google.common.base.Preconditions;
  * @since Mailet API v3.2
  */
 public class Attribute {
+    public static Attribute convertToAttribute(String name, Object value) {
+        AttributeName attributeName = AttributeName.of(name);
+        AttributeValue<?> attributeValue = AttributeValue.ofAny(value);
+
+        return new Attribute(attributeName, attributeValue);
+    }
+
     private final AttributeName name;
     private final AttributeValue<?> value;
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f1517bd3/mailet/api/src/test/java/org/apache/mailet/AttributeTest.java
----------------------------------------------------------------------
diff --git a/mailet/api/src/test/java/org/apache/mailet/AttributeTest.java b/mailet/api/src/test/java/org/apache/mailet/AttributeTest.java
index 053f745..6b3bfa5 100644
--- a/mailet/api/src/test/java/org/apache/mailet/AttributeTest.java
+++ b/mailet/api/src/test/java/org/apache/mailet/AttributeTest.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.mailet;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatNullPointerException;
 
 import org.junit.jupiter.api.Test;
@@ -43,4 +44,12 @@ class AttributeTest {
             .isThrownBy(() -> new Attribute(AttributeName.of("name"), null));
     }
 
+    @Test
+    void convertToAttributeShouldReturnCorrespondingAttribute() {
+        assertThat(Attribute.convertToAttribute("name", "value"))
+            .isEqualTo(new Attribute(
+                AttributeName.of("name"),
+                AttributeValue.of("value")));
+    }
+
 }


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