You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2020/12/28 07:43:36 UTC
[james-project] 04/16: JAMES-3469 Add EmailChange POJO
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit bf6aa0c7a9d95fe7fe357d839bb30979c88ce58d
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Dec 21 11:05:22 2020 +0700
JAMES-3469 Add EmailChange POJO
---
.../apache/james/jmap/api/change/EmailChange.java | 195 +++++++++++++++++++++
.../james/jmap/api/change/EmailChangeTest.java | 75 ++++++++
2 files changed, 270 insertions(+)
diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/change/EmailChange.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/change/EmailChange.java
new file mode 100644
index 0000000..238b898
--- /dev/null
+++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/change/EmailChange.java
@@ -0,0 +1,195 @@
+/****************************************************************
+ * 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.jmap.api.change;
+
+import java.time.ZonedDateTime;
+import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.james.jmap.api.model.AccountId;
+import org.apache.james.mailbox.model.MessageId;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+public class EmailChange {
+ public static class Builder {
+ @FunctionalInterface
+ public interface RequireAccountId {
+ RequireState accountId(AccountId accountId);
+ }
+
+ @FunctionalInterface
+ public interface RequireState {
+ RequireDate state(State state);
+ }
+
+ @FunctionalInterface
+ public interface RequireDate {
+ RequireIsDelegated date(ZonedDateTime date);
+ }
+
+ @FunctionalInterface
+ public interface RequireIsDelegated {
+ Builder isDelegated(boolean isDelegated);
+ }
+
+ private final AccountId accountId;
+ private final State state;
+ private final ZonedDateTime date;
+ private final boolean isDelegated;
+ private final ImmutableList.Builder<MessageId> created;
+ private final ImmutableList.Builder<MessageId> updated;
+ private final ImmutableList.Builder<MessageId> destroyed;
+
+ private Builder(AccountId accountId, State state, ZonedDateTime date, boolean isDelegated) {
+ Preconditions.checkNotNull(accountId, "'accountId' should not be null");
+ Preconditions.checkNotNull(state, "'state' should not be null");
+ Preconditions.checkNotNull(date, "'date' should not be null");
+
+ this.accountId = accountId;
+ this.state = state;
+ this.date = date;
+ this.isDelegated = isDelegated;
+ this.destroyed = ImmutableList.builder();
+ this.updated = ImmutableList.builder();
+ this.created = ImmutableList.builder();
+ }
+
+ public Builder updated(MessageId... messageId) {
+ updated.add(messageId);
+ return this;
+ }
+
+ public Builder destroyed(MessageId... messageId) {
+ destroyed.add(messageId);
+ return this;
+ }
+
+ public Builder created(MessageId... messageId) {
+ created.add(messageId);
+ return this;
+ }
+
+ public Builder created(Collection<MessageId> messageIds) {
+ created.addAll(messageIds);
+ return this;
+ }
+
+ public Builder destroyed(Collection<MessageId> messageIds) {
+ destroyed.addAll(messageIds);
+ return this;
+ }
+
+ public Builder updated(Collection<MessageId> messageIds) {
+ updated.addAll(messageIds);
+ return this;
+ }
+
+ public EmailChange build() {
+ return new EmailChange(accountId, state, date, isDelegated, created.build(), updated.build(), destroyed.build());
+ }
+ }
+
+ public static Builder.RequireAccountId builder() {
+ return accountId -> state -> date -> isDelegated -> new Builder(accountId, state, date, isDelegated);
+ }
+
+ private final AccountId accountId;
+ private final State state;
+ private final ZonedDateTime date;
+ private final boolean isDelegated;
+ private final ImmutableList<MessageId> created;
+ private final ImmutableList<MessageId> updated;
+ private final ImmutableList<MessageId> destroyed;
+
+ private EmailChange(AccountId accountId, State state, ZonedDateTime date, boolean isDelegated, ImmutableList<MessageId> created, ImmutableList<MessageId> updated, ImmutableList<MessageId> destroyed) {
+ this.accountId = accountId;
+ this.state = state;
+ this.date = date;
+ this.isDelegated = isDelegated;
+ this.created = created;
+ this.updated = updated;
+ this.destroyed = destroyed;
+ }
+
+ public AccountId getAccountId() {
+ return accountId;
+ }
+
+ public State getState() {
+ return state;
+ }
+
+ public ZonedDateTime getDate() {
+ return date;
+ }
+
+ public List<MessageId> getCreated() {
+ return created;
+ }
+
+ public List<MessageId> getUpdated() {
+ return updated;
+ }
+
+ public List<MessageId> getDestroyed() {
+ return destroyed;
+ }
+
+ public boolean isDelegated() {
+ return isDelegated;
+ }
+
+ @Override
+ public final boolean equals(Object o) {
+ if (o instanceof EmailChange) {
+ EmailChange that = (EmailChange) o;
+ return Objects.equals(accountId, that.accountId)
+ && Objects.equals(state, that.state)
+ && Objects.equals(date, that.date)
+ && Objects.equals(isDelegated, that.isDelegated)
+ && Objects.equals(created, that.created)
+ && Objects.equals(updated, that.updated)
+ && Objects.equals(destroyed, that.destroyed);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hash(accountId, state, date, isDelegated, created, updated, destroyed);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("accountId", accountId)
+ .add("state", state)
+ .add("date", date)
+ .add("isDelegated", isDelegated)
+ .add("created", created)
+ .add("updated", updated)
+ .add("destroyed", destroyed)
+ .toString();
+ }
+}
diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/change/EmailChangeTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/change/EmailChangeTest.java
new file mode 100644
index 0000000..9f77771
--- /dev/null
+++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/change/EmailChangeTest.java
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.jmap.api.change;
+
+import static org.apache.james.mailbox.fixture.MailboxFixture.BOB;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.time.ZonedDateTime;
+import java.util.UUID;
+
+import org.apache.james.jmap.api.model.AccountId;
+import org.junit.jupiter.api.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class EmailChangeTest {
+ AccountId ACCOUNT_ID = AccountId.fromUsername(BOB);
+ ZonedDateTime DATE = ZonedDateTime.now();
+
+ @Test
+ void shouldMatchBeanContract() {
+ EqualsVerifier.forClass(EmailChange.class)
+ .verify();
+ }
+
+ @Test
+ void shouldThrowOnNullAccountId() {
+ assertThatThrownBy(() ->
+ EmailChange.builder()
+ .accountId(null)
+ .state(State.of(UUID.randomUUID()))
+ .date(DATE.minusHours(2))
+ .isDelegated(false))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ void shouldThrowOnNullState() {
+ assertThatThrownBy(() ->
+ EmailChange.builder()
+ .accountId(ACCOUNT_ID)
+ .state(null)
+ .date(DATE.minusHours(2))
+ .isDelegated(false))
+ .isInstanceOf(NullPointerException.class);;
+ }
+
+ @Test
+ void shouldThrowOnNullDate() {
+ assertThatThrownBy(() ->
+ EmailChange.builder()
+ .accountId(ACCOUNT_ID)
+ .state(State.of(UUID.randomUUID()))
+ .date(null)
+ .isDelegated(false))
+ .isInstanceOf(NullPointerException.class);;
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org