This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit dc9d793c5302dd837e673db10afc4fdeecc0bd50 Author: datph <[email protected]> AuthorDate: Wed Mar 13 11:04:25 2019 +0700 MAILBOX-373 Introduce InsertionId for EventDeadLetter --- .../james/mailbox/events/EventDeadLetters.java | 54 ++++++++++++++++++++++ .../james/mailbox/events/InsertionIdTest.java} | 38 ++++++++++----- 2 files changed, 81 insertions(+), 11 deletions(-) diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/events/EventDeadLetters.java b/mailbox/api/src/main/java/org/apache/james/mailbox/events/EventDeadLetters.java index c505918..38ac4ae 100644 --- a/mailbox/api/src/main/java/org/apache/james/mailbox/events/EventDeadLetters.java +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/events/EventDeadLetters.java @@ -19,11 +19,65 @@ 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; + import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; public interface EventDeadLetters { + class InsertionId { + public static InsertionId of(UUID uuid) { + return new InsertionId(uuid); + } + + public static InsertionId random() { + return new InsertionId(UUID.randomUUID()); + } + + public static InsertionId of(String serialized) { + return of(UUID.fromString(serialized)); + } + + private final UUID id; + + private InsertionId(UUID id) { + Preconditions.checkNotNull(id); + this.id = id; + } + + public UUID getId() { + return id; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof InsertionId) { + InsertionId insertionId = (InsertionId) o; + + return Objects.equals(this.id, insertionId.id); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(id); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("id", id) + .toString(); + } + } + + String REGISTERED_GROUP_CANNOT_BE_NULL = "registeredGroup cannot be null"; String FAIL_DELIVERED_EVENT_CANNOT_BE_NULL = "failDeliveredEvent cannot be null"; String FAIL_DELIVERED_ID_EVENT_CANNOT_BE_NULL = "failDeliveredEventId cannot be null"; diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/events/EventDeadLetters.java b/mailbox/api/src/test/java/org/apache/james/mailbox/events/InsertionIdTest.java similarity index 53% copy from mailbox/api/src/main/java/org/apache/james/mailbox/events/EventDeadLetters.java copy to mailbox/api/src/test/java/org/apache/james/mailbox/events/InsertionIdTest.java index c505918..f8a1e0e 100644 --- a/mailbox/api/src/main/java/org/apache/james/mailbox/events/EventDeadLetters.java +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/events/InsertionIdTest.java @@ -19,22 +19,38 @@ package org.apache.james.mailbox.events; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; -public interface EventDeadLetters { +import java.util.UUID; - String REGISTERED_GROUP_CANNOT_BE_NULL = "registeredGroup cannot be null"; - String FAIL_DELIVERED_EVENT_CANNOT_BE_NULL = "failDeliveredEvent cannot be null"; - String FAIL_DELIVERED_ID_EVENT_CANNOT_BE_NULL = "failDeliveredEventId cannot be null"; +import org.junit.jupiter.api.Test; - Mono<Void> store(Group registeredGroup, Event failDeliveredEvent); +import nl.jqno.equalsverifier.EqualsVerifier; - Mono<Void> remove(Group registeredGroup, Event.EventId failDeliveredEventId); +class InsertionIdTest { + private static final UUID UUID_1 = UUID.fromString("6e0dd59d-660e-4d9b-b22f-0354479f47b4"); - Mono<Event> failedEvent(Group registeredGroup, Event.EventId failDeliveredEventId); + @Test + void eventIdShouldMatchBeanContract() { + EqualsVerifier.forClass(EventDeadLetters.InsertionId.class).verify(); + } - Flux<Event.EventId> failedEventIds(Group registeredGroup); + @Test + void ofShouldDeserializeUUIDs() { + assertThat(EventDeadLetters.InsertionId.of(UUID_1.toString())) + .isEqualTo(EventDeadLetters.InsertionId.of(UUID_1)); + } - Flux<Group> groupsWithFailedEvents(); + @Test + void ofStringShouldThrowOnNullValue() { + assertThatThrownBy(() -> EventDeadLetters.InsertionId.of((String) null)) + .isInstanceOf(NullPointerException.class); + } + + @Test + void ofUuidShouldThrowOnNullValue() { + assertThatThrownBy(() -> EventDeadLetters.InsertionId.of((UUID) null)) + .isInstanceOf(NullPointerException.class); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
