Repository: james-project Updated Branches: refs/heads/master dc4e2016f -> 4b1552dd8
JAMES-2173 Add mailbox namespace object Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5f458dfc Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5f458dfc Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5f458dfc Branch: refs/heads/master Commit: 5f458dfc35386dadafd43366bc1fbf840efa36bf Parents: dc4e201 Author: quynhn <[email protected]> Authored: Thu Oct 5 11:45:25 2017 +0700 Committer: Matthieu Baechler <[email protected]> Committed: Thu Oct 5 20:12:19 2017 +0200 ---------------------------------------------------------------------- .../jmap/model/mailbox/MailboxNamespace.java | 91 ++++++++++++++++++++ .../model/mailbox/MailboxNamespaceTest.java | 72 ++++++++++++++++ 2 files changed, 163 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/5f458dfc/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxNamespace.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxNamespace.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxNamespace.java new file mode 100644 index 0000000..51eb756 --- /dev/null +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/mailbox/MailboxNamespace.java @@ -0,0 +1,91 @@ +/**************************************************************** + * 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.model.mailbox; + +import java.util.Objects; +import java.util.Optional; + +import org.apache.commons.lang.StringUtils; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; + +public class MailboxNamespace { + public enum Type { + Delegated("Delegated"), + Personal("Personal"); + + private final String type; + + Type(String type) { + this.type = type; + } + } + public static MailboxNamespace delegated(String owner) { + Preconditions.checkArgument(!StringUtils.isBlank(owner)); + return new MailboxNamespace(Type.Delegated, Optional.of(owner)); + } + + public static MailboxNamespace personal() { + return new MailboxNamespace(Type.Personal, Optional.empty()); + } + + private final Type type; + private final Optional<String> owner; + + private MailboxNamespace(Type type, Optional<String> owner) { + this.type = type; + this.owner = owner; + } + + public Type getType() { + return type; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + public Optional<String> getOwner() { + return owner; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof MailboxNamespace) { + MailboxNamespace that = (MailboxNamespace) o; + + return Objects.equals(this.type, that.type) && + Objects.equals(this.owner, that.owner); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(type, owner); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("type", type) + .add("owner", owner) + .toString(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/5f458dfc/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxNamespaceTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxNamespaceTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxNamespaceTest.java new file mode 100644 index 0000000..1836b1a --- /dev/null +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/mailbox/MailboxNamespaceTest.java @@ -0,0 +1,72 @@ +/**************************************************************** + * 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.model.mailbox; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +public class MailboxNamespaceTest { + @Test + public void shouldRespectJavaBeanContract() throws Exception { + EqualsVerifier.forClass(MailboxNamespace.class) + .allFieldsShouldBeUsed() + .verify(); + } + + @Test + public void delegatedShouldThrowWhenNullOwner() throws Exception { + assertThatThrownBy(() -> MailboxNamespace.delegated(null)) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + public void delegatedShouldThrowWhenEmptyOwner() throws Exception { + assertThatThrownBy(() -> MailboxNamespace.delegated("")) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + public void delegatedShouldThrowWhenBlankOwner() throws Exception { + assertThatThrownBy(() -> MailboxNamespace.delegated(" ")) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + public void delegatedShouldReturnDelegatedNamespace() throws Exception { + String owner = "[email protected]"; + MailboxNamespace actualNamespace = MailboxNamespace.delegated(owner); + + assertThat(actualNamespace.getType()).isEqualTo(MailboxNamespace.Type.Delegated); + assertThat(actualNamespace.getOwner().get()).isEqualTo(owner); + } + + @Test + public void personalShouldReturnPersonalNamespace() throws Exception { + MailboxNamespace actualNamespace = MailboxNamespace.personal(); + + assertThat(actualNamespace.getOwner()).isEmpty(); + assertThat(actualNamespace.getType()).isEqualTo(MailboxNamespace.Type.Personal); + } + +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
