JAMES-1704 InMemoryMailboxMapper should validate mapper unit tests
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5a21b6b2 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5a21b6b2 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5a21b6b2 Branch: refs/heads/master Commit: 5a21b6b224d36d0cbbbfa08073d802bc64e9e034 Parents: f1f5056 Author: Benoit Tellier <btell...@linagora.com> Authored: Fri Mar 11 13:46:11 2016 +0700 Committer: Benoit Tellier <btell...@linagora.com> Committed: Thu Mar 24 12:44:21 2016 +0700 ---------------------------------------------------------------------- .../inmemory/mail/InMemoryMailboxMapper.java | 18 ++++++++---- .../mail/InMemoryMailboxMapperTest.java | 30 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/5a21b6b2/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java ---------------------------------------------------------------------- diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java index 7dc9a19..17dd2f4 100644 --- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java +++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java @@ -33,6 +33,8 @@ import org.apache.james.mailbox.store.mail.MailboxMapper; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox; +import com.google.common.base.Objects; + public class InMemoryMailboxMapper implements MailboxMapper<InMemoryId> { private static final int INITIAL_SIZE = 128; @@ -57,7 +59,7 @@ public class InMemoryMailboxMapper implements MailboxMapper<InMemoryId> { /** * @see org.apache.james.mailbox.store.mail.MailboxMapper#findMailboxByPath(org.apache.james.mailbox.model.MailboxPath) */ - public synchronized Mailbox<InMemoryId> findMailboxByPath(MailboxPath path) throws MailboxException, MailboxNotFoundException { + public synchronized Mailbox<InMemoryId> findMailboxByPath(MailboxPath path) throws MailboxException { Mailbox<InMemoryId> result = null; for (Mailbox<InMemoryId> mailbox:mailboxesById.values()) { MailboxPath mp = new MailboxPath(mailbox.getNamespace(), mailbox.getUser(), mailbox.getName()); @@ -88,8 +90,8 @@ public class InMemoryMailboxMapper implements MailboxMapper<InMemoryId> { } private boolean mailboxMatchesRegex(Mailbox<InMemoryId> mailbox, MailboxPath path, String regex) { - return mailbox.getNamespace().equals(path.getNamespace()) - && mailbox.getUser().equals(path.getUser()) + return Objects.equal(mailbox.getNamespace(), path.getNamespace()) + && Objects.equal(mailbox.getUser(), path.getUser()) && mailbox.getName().matches(regex); } @@ -115,17 +117,21 @@ public class InMemoryMailboxMapper implements MailboxMapper<InMemoryId> { /** * @see org.apache.james.mailbox.store.mail.MailboxMapper#hasChildren(org.apache.james.mailbox.store.mail.model.Mailbox, char) */ - public boolean hasChildren(Mailbox<InMemoryId> mailbox, char delimiter) throws MailboxException, - MailboxNotFoundException { + public boolean hasChildren(Mailbox<InMemoryId> mailbox, char delimiter) throws MailboxException { String mailboxName = mailbox.getName() + delimiter; for (Mailbox<InMemoryId> box:mailboxesById.values()) { - if (box.getName().startsWith(mailboxName)) { + if (belongsToSameUser(mailbox, box) && box.getName().startsWith(mailboxName)) { return true; } } return false; } + private boolean belongsToSameUser(Mailbox<InMemoryId> mailbox, Mailbox<InMemoryId> otherMailbox) { + return Objects.equal(mailbox.getNamespace(), otherMailbox.getNamespace()) + && Objects.equal(mailbox.getUser(), otherMailbox.getUser()); + } + /** * @see org.apache.james.mailbox.store.mail.MailboxMapper#list() */ http://git-wip-us.apache.org/repos/asf/james-project/blob/5a21b6b2/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapperTest.java ---------------------------------------------------------------------- diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapperTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapperTest.java new file mode 100644 index 0000000..fc1711d --- /dev/null +++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapperTest.java @@ -0,0 +1,30 @@ +/**************************************************************** + * 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.inmemory.mail; + +import org.apache.james.mailbox.inmemory.InMemoryId; +import org.apache.james.mailbox.store.mail.model.AbstractMailboxMapperTest; + +public class InMemoryMailboxMapperTest extends AbstractMailboxMapperTest<InMemoryId> { + + public InMemoryMailboxMapperTest() { + super(new InMemoryMapperProvider()); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org