JAMES-1874 Adding tests for MailboxPath::getLevels
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/1fa1cd82 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/1fa1cd82 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/1fa1cd82 Branch: refs/heads/master Commit: 1fa1cd824036e20c603741e2ddb1e299bed25abf Parents: bdc76d1 Author: Benoit Tellier <btell...@linagora.com> Authored: Mon Feb 13 09:29:26 2017 +0700 Committer: Benoit Tellier <btell...@linagora.com> Committed: Mon Feb 20 16:05:39 2017 +0700 ---------------------------------------------------------------------- .../apache/james/mailbox/model/MailboxPath.java | 5 ++ .../james/mailbox/model/MailboxPathTest.java | 62 ++++++++++++++++++++ 2 files changed, 67 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/1fa1cd82/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java index e4f132b..06a87b2 100644 --- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java +++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxPath.java @@ -24,6 +24,8 @@ import java.util.List; import org.apache.james.mailbox.MailboxSession; +import com.google.common.collect.ImmutableList; + /** * The path to a mailbox. */ @@ -116,6 +118,9 @@ public class MailboxPath { * @return list of hierarchy levels */ public List<MailboxPath> getHierarchyLevels(char delimiter) { + if (name == null) { + return ImmutableList.of(this); + } ArrayList<MailboxPath> levels = new ArrayList<MailboxPath>(); int index = name.indexOf(delimiter); while (index >= 0) { http://git-wip-us.apache.org/repos/asf/james-project/blob/1fa1cd82/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java ---------------------------------------------------------------------- diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java new file mode 100644 index 0000000..b474aac --- /dev/null +++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxPathTest.java @@ -0,0 +1,62 @@ +/* + * 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.model; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +public class MailboxPathTest { + + @Test + public void getHierarchyLevelsShouldBeOrdered() { + assertThat(new MailboxPath("#private", "user", "inbox.folder.subfolder") + .getHierarchyLevels('.')) + .containsExactly( + new MailboxPath("#private", "user", "inbox"), + new MailboxPath("#private", "user", "inbox.folder"), + new MailboxPath("#private", "user", "inbox.folder.subfolder")); + } + + @Test + public void getHierarchyLevelsShouldReturnPathWhenOneLevel() { + assertThat(new MailboxPath("#private", "user", "inbox") + .getHierarchyLevels('.')) + .containsExactly( + new MailboxPath("#private", "user", "inbox")); + } + + @Test + public void getHierarchyLevelsShouldReturnPathWhenEmptyName() { + assertThat(new MailboxPath("#private", "user", "") + .getHierarchyLevels('.')) + .containsExactly( + new MailboxPath("#private", "user", "")); + } + + @Test + public void getHierarchyLevelsShouldReturnPathWhenNullName() { + assertThat(new MailboxPath("#private", "user", null) + .getHierarchyLevels('.')) + .containsExactly( + new MailboxPath("#private", "user", null)); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org