You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/01/22 02:20:44 UTC

[5/8] james-project git commit: MAILBOX-369 Add EventBusId POJOs

MAILBOX-369 Add EventBusId POJOs


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

Branch: refs/heads/master
Commit: 89781fe3c40b01cabc05e7a05a826ede231fbf62
Parents: cf996f1
Author: datph <dp...@linagora.com>
Authored: Thu Dec 27 17:29:36 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 22 09:20:12 2019 +0700

----------------------------------------------------------------------
 mailbox/event/event-rabbitmq/pom.xml            |  5 ++
 .../apache/james/mailbox/events/EventBusId.java | 74 ++++++++++++++++++++
 .../james/mailbox/events/EventBusIdTest.java    | 50 +++++++++++++
 3 files changed, 129 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/89781fe3/mailbox/event/event-rabbitmq/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/event/event-rabbitmq/pom.xml b/mailbox/event/event-rabbitmq/pom.xml
index 0085059..383172c 100644
--- a/mailbox/event/event-rabbitmq/pom.xml
+++ b/mailbox/event/event-rabbitmq/pom.xml
@@ -76,6 +76,11 @@
             <version>1.0.0.RELEASE</version>
         </dependency>
         <dependency>
+            <groupId>nl.jqno.equalsverifier</groupId>
+            <artifactId>equalsverifier</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.assertj</groupId>
             <artifactId>assertj-core</artifactId>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/89781fe3/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/EventBusId.java
----------------------------------------------------------------------
diff --git a/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/EventBusId.java b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/EventBusId.java
new file mode 100644
index 0000000..65ff8a7
--- /dev/null
+++ b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/EventBusId.java
@@ -0,0 +1,74 @@
+/****************************************************************
+ * 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.james.mailbox.events;
+
+import java.util.Objects;
+import java.util.UUID;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+public class EventBusId {
+
+    public static EventBusId of(UUID uuid) {
+        return new EventBusId(uuid);
+    }
+
+    public static EventBusId random() {
+        return new EventBusId(UUID.randomUUID());
+    }
+
+    public static EventBusId of(String serialized) {
+        return new EventBusId(UUID.fromString(serialized));
+    }
+
+    private final UUID id;
+
+    private EventBusId(UUID id) {
+        Preconditions.checkNotNull(id);
+        this.id = id;
+    }
+
+    public UUID getId() {
+        return id;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof EventBusId) {
+            EventBusId eventBusId = (EventBusId) o;
+            return Objects.equals(this.id, eventBusId.id);
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(id);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+            .add("id", id)
+            .toString();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/89781fe3/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/EventBusIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/EventBusIdTest.java b/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/EventBusIdTest.java
new file mode 100644
index 0000000..b8718df
--- /dev/null
+++ b/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/EventBusIdTest.java
@@ -0,0 +1,50 @@
+/****************************************************************
+ * 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.james.mailbox.events;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.UUID;
+
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class EventBusIdTest {
+
+    private static final UUID UUID_1 = UUID.fromString("6e0dd59d-660e-4d9b-b22f-0354479f47b4");
+
+    @Test
+    void eventBusIdShouldMatchBeanContract() {
+        EqualsVerifier.forClass(EventBusId.class);
+    }
+
+    @Test
+    void ofShouldDeserializeUUIDs() {
+        assertThat(EventBusId.of(UUID_1.toString()))
+            .isEqualTo(EventBusId.of(UUID_1));
+    }
+
+    @Test
+    void asStringShouldReturnWrappedValue() {
+        assertThat(EventBusId.of(UUID_1).asString())
+            .isEqualTo("6e0dd59d-660e-4d9b-b22f-0354479f47b4");
+    }
+}


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