james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [16/17] james-project git commit: JAMES-2578 Add tests for AttributeValue.ofSerializable
Date Thu, 01 Nov 2018 04:07:51 GMT
JAMES-2578 Add tests for AttributeValue.ofSerializable


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

Branch: refs/heads/master
Commit: ccd822676a0dda5d286f98d98d2fe6a41e1fe445
Parents: cb91f99
Author: Gautier DI FOLCO <gdifolco@linagora.com>
Authored: Tue Oct 30 17:57:34 2018 +0100
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Nov 1 11:03:43 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/mailet/AttributeValue.java  |  1 +
 .../org/apache/mailet/AttributeValueTest.java   | 51 ++++++++++++++++++++
 2 files changed, 52 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ccd82267/mailet/api/src/main/java/org/apache/mailet/AttributeValue.java
----------------------------------------------------------------------
diff --git a/mailet/api/src/main/java/org/apache/mailet/AttributeValue.java b/mailet/api/src/main/java/org/apache/mailet/AttributeValue.java
index 638dd34..6933bf8 100644
--- a/mailet/api/src/main/java/org/apache/mailet/AttributeValue.java
+++ b/mailet/api/src/main/java/org/apache/mailet/AttributeValue.java
@@ -105,6 +105,7 @@ public class AttributeValue<T> {
     }
 
     public static AttributeValue<Serializable> ofSerializable(Serializable value) {
+        Preconditions.checkNotNull(value, "value should not be null");
         return new AttributeValue<>(value, new Serializer.FSTSerializer());
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/ccd82267/mailet/api/src/test/java/org/apache/mailet/AttributeValueTest.java
----------------------------------------------------------------------
diff --git a/mailet/api/src/test/java/org/apache/mailet/AttributeValueTest.java b/mailet/api/src/test/java/org/apache/mailet/AttributeValueTest.java
index ef92c6b..3ce1d3f 100644
--- a/mailet/api/src/test/java/org/apache/mailet/AttributeValueTest.java
+++ b/mailet/api/src/test/java/org/apache/mailet/AttributeValueTest.java
@@ -547,6 +547,34 @@ class AttributeValueTest {
         }
     }
 
+    @Nested
+    class SerializableSerialization {
+        @Test
+        void filledSerializabletrueShouldBeSerializedAndBack() {
+            AttributeValue<java.io.Serializable> expected = AttributeValue.ofSerializable(new
TestSerializable("me"));
+
+            JsonNode json = expected.toJson();
+            AttributeValue<?> actual = AttributeValue.fromJson(json);
+
+            assertThat(actual).isEqualTo(expected);
+        }
+
+        @Test
+        void nullSerializableShouldThrowAnException() {
+            assertThatNullPointerException().
+                isThrownBy(() -> AttributeValue.ofSerializable((java.io.Serializable)
null));
+        }
+
+        @Test
+        void fromJsonStringShouldReturnBooleanAttributeValueWhenBoolean() throws Exception
{
+            AttributeValue<java.io.Serializable> expected = AttributeValue.ofSerializable(new
TestSerializable("me"));
+
+            AttributeValue<?> actual = AttributeValue.fromJsonString("{\"serializer\":\"FSTSerializer\",\"value\":{\"typ\":\"org.apache.mailet.AttributeValueTest$TestSerializable\",\"obj\":{\"name\":\"me\"}}}");
+
+            assertThat(actual).isEqualTo(expected);
+        }
+    }
+
     @Test
     void fromJsonStringShouldThrowOnUnknownSerializer() {
         assertThatIllegalStateException()
@@ -608,4 +636,27 @@ class AttributeValueTest {
             return Objects.hash(value);
         }
     }
+
+    private static class TestSerializable implements java.io.Serializable {
+        private final String name;
+
+        public TestSerializable(String name) {
+            this.name = name;
+        }
+
+        @Override
+        public final boolean equals(Object o) {
+            if (o instanceof TestSerializable) {
+                TestSerializable that = (TestSerializable) o;
+
+                return Objects.equals(this.name, that.name);
+            }
+            return false;
+        }
+
+        @Override
+        public final int hashCode() {
+            return Objects.hash(name);
+        }
+    }
 }


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