james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [6/7] james-project git commit: JAMES-1664 transform MessageProperty to an enum
Date Mon, 01 Feb 2016 12:25:27 GMT
JAMES-1664 transform MessageProperty to an enum


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

Branch: refs/heads/master
Commit: 8c1920809cdfefc240e19eeb4930ca587e99b864
Parents: 7dfe3e5
Author: Matthieu Baechler <matthieu.baechler@gmail.com>
Authored: Tue Jan 26 16:49:08 2016 +0100
Committer: Antoine Duprat <antduprat@gmail.com>
Committed: Mon Feb 1 13:21:05 2016 +0100

----------------------------------------------------------------------
 server/pom.xml                                  |  2 +-
 .../james/jmap/model/MessageProperty.java       | 80 ++++++++------------
 .../james/jmap/model/MessagePropertyTest.java   | 26 +++----
 3 files changed, 41 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/8c192080/server/pom.xml
----------------------------------------------------------------------
diff --git a/server/pom.xml b/server/pom.xml
index a00c9f5..19dfa16 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -192,7 +192,7 @@
         <jetty.version>9.3.5.v20151012</jetty.version>
         <cassandra-unit.version>2.1.9.2</cassandra-unit.version>
         <assertj-1.version>1.7.1</assertj-1.version>
-        <assertj-3.version>3.2.0</assertj-3.version>
+        <assertj-3.version>3.3.0</assertj-3.version>
     </properties>
 
     <dependencyManagement>

http://git-wip-us.apache.org/repos/asf/james-project/blob/8c192080/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageProperty.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageProperty.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageProperty.java
index df898eb..0e230d4 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageProperty.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageProperty.java
@@ -18,37 +18,38 @@
  ****************************************************************/
 package org.apache.james.jmap.model;
 
-import java.util.Objects;
+import java.util.Arrays;
+import java.util.stream.Stream;
 
 import com.google.common.base.Preconditions;
 
-public class MessageProperty implements Property {
+public enum MessageProperty implements Property {
 
-    public static MessageProperty id = valueOf("id");
-    public static MessageProperty blobId = valueOf("blobId");
-    public static MessageProperty threadId = valueOf("threadId");
-    public static MessageProperty mailboxIds = valueOf("mailboxIds");
-    public static MessageProperty inReplyToMessageId = valueOf("inReplyToMessageId");
-    public static MessageProperty isUnread = valueOf("isUnread");
-    public static MessageProperty isFlagged = valueOf("isFlagged");
-    public static MessageProperty isAnswered = valueOf("isAnswered");
-    public static MessageProperty isDraft = valueOf("isDraft");
-    public static MessageProperty hasAttachment = valueOf("hasAttachment");
-    public static MessageProperty headers = valueOf("headers");
-    public static MessageProperty from = valueOf("from");
-    public static MessageProperty to = valueOf("to");
-    public static MessageProperty cc = valueOf("cc");
-    public static MessageProperty bcc = valueOf("bcc");
-    public static MessageProperty replyTo = valueOf("replyTo");
-    public static MessageProperty subject = valueOf("subject");
-    public static MessageProperty date = valueOf("date");
-    public static MessageProperty size = valueOf("size");
-    public static MessageProperty preview = valueOf("preview");
-    public static MessageProperty textBody = valueOf("textBody");
-    public static MessageProperty htmlBody = valueOf("htmlBody");
-    public static MessageProperty attachments = valueOf("attachments");
-    public static MessageProperty attachedMessages = valueOf("attachedMessages");
-    public static MessageProperty body = valueOf("body");
+    id("id"),
+    blobId("blobId"),
+    threadId("threadId"),
+    mailboxIds("mailboxIds"),
+    inReplyToMessageId("inReplyToMessageId"),
+    isUnread("isUnread"),
+    isFlagged("isFlagged"),
+    isAnswered("isAnswered"),
+    isDraft("isDraft"),
+    hasAttachment("hasAttachment"),
+    headers("headers"),
+    from("from"),
+    to("to"),
+    cc("cc"),
+    bcc("bcc"),
+    replyTo("replyTo"),
+    subject("subject"),
+    date("date"),
+    size("size"),
+    preview("preview"),
+    textBody("textBody"),
+    htmlBody("htmlBody"),
+    attachments("attachments"),
+    attachedMessages("attachedMessages"),
+    body("body");
 
     private final String property;
 
@@ -56,32 +57,13 @@ public class MessageProperty implements Property {
         this.property = property;
     }
 
-    public static MessageProperty valueOf(String property) {
-        Preconditions.checkNotNull(property);
-        return new MessageProperty(property);
-    }
-
     @Override
     public String asFieldName() {
         return property;
     }
 
-    @Override
-    public boolean equals(Object obj) {
-        if (obj instanceof MessageProperty) {
-            MessageProperty other = (MessageProperty) obj;
-            return Objects.equals(this.property, other.property);
-        }
-        return false;
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(property);
-    }
-
-    @Override
-    public String toString() {
-        return Objects.toString(property);
+    public static Stream<MessageProperty> find(String property) {
+        Preconditions.checkNotNull(property);
+        return Arrays.stream(values()).filter(entry -> entry.property.equals(property));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/8c192080/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessagePropertyTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessagePropertyTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessagePropertyTest.java
index 37a874e..f9157f4 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessagePropertyTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessagePropertyTest.java
@@ -18,34 +18,26 @@
  ****************************************************************/
 package org.apache.james.jmap.model;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import org.junit.Test;
 
 public class MessagePropertyTest {
     
-    @Test(expected=NullPointerException.class)
-    public void valueOfShouldThrowWhenNull() {
-        MessageProperty.valueOf(null);
-    }
-    
-    @Test
-    public void valueOfThenAsFieldNameShouldReturnMatchingCaseProperty() {
-        assertThat(MessageProperty.valueOf("ProP").asFieldName()).isEqualTo("ProP");
-    }
-    
     @Test
-    public void equalsShouldBeTrueWhenIdenticalProperties() {
-        assertThat(MessageProperty.valueOf("prop")).isEqualTo(MessageProperty.valueOf("prop"));
+    public void findShouldThrowWhenNull() {
+        assertThatThrownBy(() -> MessageProperty.find(null)).isInstanceOf(NullPointerException.class);
     }
 
+    
     @Test
-    public void equalsShouldBeFalseWhenDifferentProperties() {
-        assertThat(MessageProperty.valueOf("prop")).isNotEqualTo(MessageProperty.valueOf("other"));
+    public void findShouldReturnEmptyWhenNotFound() {
+        assertThat(MessageProperty.find("not found")).isEmpty();
     }
-
+    
     @Test
-    public void equalsShouldBeFalseWhenDifferentCaseProperties() {
-        assertThat(MessageProperty.valueOf("prOP")).isNotEqualTo(MessageProperty.valueOf("PRop"));
+    public void findShouldReturnEnumEntryWhenFound() {
+        assertThat(MessageProperty.find("subject")).containsExactly(MessageProperty.subject);
     }
 }


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