james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [08/10] james-project git commit: JAMES-1818 Introduce MailboxFactory to simplify MailboxUtils
Date Mon, 05 Sep 2016 12:44:04 GMT
JAMES-1818 Introduce MailboxFactory to simplify MailboxUtils


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7ecb7ef5
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7ecb7ef5
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7ecb7ef5

Branch: refs/heads/master
Commit: 7ecb7ef5804d8115ee64b1f2e734f87b99609939
Parents: 268f001
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Wed Aug 31 17:06:19 2016 +0200
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Mon Sep 5 14:42:01 2016 +0200

----------------------------------------------------------------------
 .../org/apache/james/jmap/JMAPCommonModule.java |   2 +
 .../james/jmap/methods/GetMailboxesMethod.java  |  10 +-
 .../methods/SetMailboxesCreationProcessor.java  |  10 +-
 .../SetMailboxesDestructionProcessor.java       |   7 +-
 .../methods/SetMailboxesUpdateProcessor.java    |   7 +-
 .../apache/james/jmap/model/MailboxFactory.java | 112 +++++++++++++
 .../apache/james/jmap/utils/MailboxUtils.java   |  85 +---------
 .../jmap/methods/GetMailboxesMethodTest.java    |  10 +-
 .../SetMailboxesCreationProcessorTest.java      |   7 +-
 .../SetMailboxesUpdateProcessorTest.java        |   7 +-
 .../james/jmap/model/MailboxFactoryTest.java    | 165 +++++++++++++++++++
 .../james/jmap/utils/MailboxUtilsTest.java      | 109 ------------
 12 files changed, 317 insertions(+), 214 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7ecb7ef5/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
index e9d5c6f..c6bd8a3 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
@@ -30,6 +30,7 @@ import org.apache.james.jmap.crypto.JamesSignatureHandler;
 import org.apache.james.jmap.crypto.SignatureHandler;
 import org.apache.james.jmap.crypto.SignedTokenFactory;
 import org.apache.james.jmap.crypto.SignedTokenManager;
+import org.apache.james.jmap.model.MailboxFactory;
 import org.apache.james.jmap.model.MessageContentExtractor;
 import org.apache.james.jmap.model.MessageFactory;
 import org.apache.james.jmap.model.MessagePreviewGenerator;
@@ -62,6 +63,7 @@ public class JMAPCommonModule extends AbstractModule {
         bind(MailSpool.class).in(Scopes.SINGLETON);
         bind(MailFactory.class).in(Scopes.SINGLETON);
         bind(AutomaticallySentMailDetectorImpl.class).in(Scopes.SINGLETON);
+        bind(MailboxFactory.class).in(Scopes.SINGLETON);
         bind(MessageFactory.class).in(Scopes.SINGLETON);
         bind(MessagePreviewGenerator.class).in(Scopes.SINGLETON);
         bind(MessageContentExtractor.class).in(Scopes.SINGLETON);

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ecb7ef5/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
index 3e739ed..446336f 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java
@@ -30,9 +30,9 @@ import javax.inject.Inject;
 import org.apache.james.jmap.model.ClientId;
 import org.apache.james.jmap.model.GetMailboxesRequest;
 import org.apache.james.jmap.model.GetMailboxesResponse;
+import org.apache.james.jmap.model.MailboxFactory;
 import org.apache.james.jmap.model.MailboxProperty;
 import org.apache.james.jmap.model.mailbox.Mailbox;
-import org.apache.james.jmap.utils.MailboxUtils;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
@@ -53,12 +53,12 @@ public class GetMailboxesMethod implements Method {
     private static final Method.Response.Name RESPONSE_NAME = Method.Response.name("mailboxes");
 
     private final MailboxManager mailboxManager; 
-    private final MailboxUtils mailboxUtils;
+    private final MailboxFactory mailboxFactory;
 
     @Inject
-    @VisibleForTesting public GetMailboxesMethod(MailboxManager mailboxManager, MailboxUtils
mailboxUtils) {
+    @VisibleForTesting public GetMailboxesMethod(MailboxManager mailboxManager, MailboxFactory
mailboxFactory) {
         this.mailboxManager = mailboxManager;
-        this.mailboxUtils = mailboxUtils;
+        this.mailboxFactory = mailboxFactory;
     }
 
     @Override
@@ -92,7 +92,7 @@ public class GetMailboxesMethod implements Method {
             retrieveUserMailboxes(mailboxSession)
                 .stream()
                 .map(MailboxMetaData::getPath)
-                .map(mailboxPath -> mailboxUtils.mailboxFromMailboxPath(mailboxPath, mailboxSession))
+                .map(mailboxPath -> mailboxFactory.fromMailboxPath(mailboxPath, mailboxSession))
                 .filter(Optional::isPresent)
                 .map(Optional::get)
                 .filter(filterMailboxesById(mailboxesRequest.getIds()))

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ecb7ef5/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
index 01dc2d7..28e36f6 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessor.java
@@ -28,13 +28,13 @@ import javax.inject.Inject;
 import org.apache.james.jmap.exceptions.MailboxNameException;
 import org.apache.james.jmap.exceptions.MailboxParentNotFoundException;
 import org.apache.james.jmap.model.MailboxCreationId;
+import org.apache.james.jmap.model.MailboxFactory;
 import org.apache.james.jmap.model.SetError;
 import org.apache.james.jmap.model.SetMailboxesRequest;
 import org.apache.james.jmap.model.SetMailboxesResponse;
 import org.apache.james.jmap.model.mailbox.Mailbox;
 import org.apache.james.jmap.model.mailbox.MailboxCreateRequest;
 import org.apache.james.jmap.utils.DependencyGraph.CycleDetectedException;
-import org.apache.james.jmap.utils.MailboxUtils;
 import org.apache.james.jmap.utils.SortingHierarchicalCollections;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
@@ -57,18 +57,18 @@ public class SetMailboxesCreationProcessor implements SetMailboxesProcessor
{
 
     private final MailboxManager mailboxManager;
     private final SortingHierarchicalCollections<Map.Entry<MailboxCreationId, MailboxCreateRequest>,
MailboxCreationId> sortingHierarchicalCollections;
-    private final MailboxUtils mailboxUtils;
+    private final MailboxFactory mailboxFactory;
     private final Factory mailboxIdFactory;
 
     @Inject
     @VisibleForTesting
-    SetMailboxesCreationProcessor(MailboxManager mailboxManager, MailboxUtils mailboxUtils,
MailboxId.Factory mailboxIdFactory) {
+    SetMailboxesCreationProcessor(MailboxManager mailboxManager, MailboxFactory mailboxFactory,
MailboxId.Factory mailboxIdFactory) {
         this.mailboxManager = mailboxManager;
         this.sortingHierarchicalCollections =
             new SortingHierarchicalCollections<Map.Entry<MailboxCreationId, MailboxCreateRequest>,
MailboxCreationId>(
                 x -> x.getKey(),
                 x -> x.getValue().getParentId());
-        this.mailboxUtils = mailboxUtils;
+        this.mailboxFactory = mailboxFactory;
         this.mailboxIdFactory = mailboxIdFactory;
     }
 
@@ -101,7 +101,7 @@ public class SetMailboxesCreationProcessor implements SetMailboxesProcessor
{
             ensureValidMailboxName(mailboxRequest, mailboxSession);
             MailboxPath mailboxPath = getMailboxPath(mailboxRequest, creationIdsToCreatedMailboxId,
mailboxSession);
             mailboxManager.createMailbox(mailboxPath, mailboxSession);
-            Optional<Mailbox> mailbox = mailboxUtils.mailboxFromMailboxPath(mailboxPath,
mailboxSession);
+            Optional<Mailbox> mailbox = mailboxFactory.fromMailboxPath(mailboxPath,
mailboxSession);
             if (mailbox.isPresent()) {
                 builder.created(mailboxCreationId, mailbox.get());
                 creationIdsToCreatedMailboxId.put(mailboxCreationId, mailbox.get().getId());

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ecb7ef5/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
index a777c44..ea06438 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesDestructionProcessor.java
@@ -27,6 +27,7 @@ import javax.inject.Inject;
 
 import org.apache.james.jmap.exceptions.MailboxHasChildException;
 import org.apache.james.jmap.exceptions.SystemMailboxNotUpdatableException;
+import org.apache.james.jmap.model.MailboxFactory;
 import org.apache.james.jmap.model.SetError;
 import org.apache.james.jmap.model.SetMailboxesRequest;
 import org.apache.james.jmap.model.SetMailboxesResponse;
@@ -53,16 +54,18 @@ public class SetMailboxesDestructionProcessor implements SetMailboxesProcessor
{
     private final MailboxManager mailboxManager;
     private final SortingHierarchicalCollections<Map.Entry<MailboxId, Mailbox>,
MailboxId> sortingHierarchicalCollections;
     private final MailboxUtils mailboxUtils;
+    private final MailboxFactory mailboxFactory;
 
     @Inject
     @VisibleForTesting
-    SetMailboxesDestructionProcessor(MailboxManager mailboxManager, MailboxUtils mailboxUtils)
{
+    SetMailboxesDestructionProcessor(MailboxManager mailboxManager, MailboxUtils mailboxUtils,
MailboxFactory mailboxFactory) {
         this.mailboxManager = mailboxManager;
         this.sortingHierarchicalCollections =
             new SortingHierarchicalCollections<>(
                     Entry::getKey,
                     x -> x.getValue().getParentId());
         this.mailboxUtils = mailboxUtils;
+        this.mailboxFactory = mailboxFactory;
     }
 
     public SetMailboxesResponse process(SetMailboxesRequest request, MailboxSession mailboxSession)
{
@@ -79,7 +82,7 @@ public class SetMailboxesDestructionProcessor implements SetMailboxesProcessor
{
     private ImmutableMap<MailboxId, Mailbox> mapDestroyRequests(SetMailboxesRequest
request, MailboxSession mailboxSession) {
         ImmutableMap.Builder<MailboxId, Mailbox> idToMailboxBuilder = ImmutableMap.builder();

         request.getDestroy().stream()
-            .map(id -> mailboxUtils.mailboxFromMailboxId(id, mailboxSession))
+            .map(id -> mailboxFactory.fromMailboxId(id, mailboxSession))
             .filter(Optional::isPresent)
             .map(Optional::get)
             .forEach(mailbox -> idToMailboxBuilder.put(mailbox.getId(), mailbox));

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ecb7ef5/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
index 438e101..0f52829 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
@@ -27,6 +27,7 @@ import org.apache.james.jmap.exceptions.MailboxHasChildException;
 import org.apache.james.jmap.exceptions.MailboxNameException;
 import org.apache.james.jmap.exceptions.MailboxParentNotFoundException;
 import org.apache.james.jmap.exceptions.SystemMailboxNotUpdatableException;
+import org.apache.james.jmap.model.MailboxFactory;
 import org.apache.james.jmap.model.SetError;
 import org.apache.james.jmap.model.SetMailboxesRequest;
 import org.apache.james.jmap.model.SetMailboxesResponse;
@@ -53,12 +54,14 @@ public class SetMailboxesUpdateProcessor implements SetMailboxesProcessor
{
 
     private final MailboxUtils mailboxUtils;
     private final MailboxManager mailboxManager;
+    private final MailboxFactory mailboxFactory;
 
     @Inject
     @VisibleForTesting
-    SetMailboxesUpdateProcessor(MailboxUtils mailboxUtils, MailboxManager mailboxManager)
{
+    SetMailboxesUpdateProcessor(MailboxUtils mailboxUtils, MailboxManager mailboxManager,
MailboxFactory mailboxFactory) {
         this.mailboxUtils = mailboxUtils;
         this.mailboxManager = mailboxManager;
+        this.mailboxFactory = mailboxFactory;
     }
 
     @Override
@@ -126,7 +129,7 @@ public class SetMailboxesUpdateProcessor implements SetMailboxesProcessor
{
     }
 
     private Mailbox getMailbox(MailboxId mailboxId, MailboxSession mailboxSession) throws
MailboxNotFoundException {
-        return mailboxUtils.mailboxFromMailboxId(mailboxId, mailboxSession)
+        return mailboxFactory.fromMailboxId(mailboxId, mailboxSession)
                 .orElseThrow(() -> new MailboxNotFoundException(mailboxId.serialize()));
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ecb7ef5/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
new file mode 100644
index 0000000..7ac9e42
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
@@ -0,0 +1,112 @@
+/****************************************************************
+ * 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;
+
+import java.util.List;
+import java.util.Optional;
+
+import javax.inject.Inject;
+
+import org.apache.james.jmap.model.mailbox.Mailbox;
+import org.apache.james.jmap.model.mailbox.Role;
+import org.apache.james.jmap.model.mailbox.SortOrder;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Splitter;
+
+public class MailboxFactory {
+    private static final boolean DONT_RESET_RECENT = false;
+    private static final Logger LOGGER = LoggerFactory.getLogger(MailboxFactory.class);
+
+    private final MailboxManager mailboxManager;
+
+    @Inject
+    public MailboxFactory(MailboxManager mailboxManager) {
+        this.mailboxManager = mailboxManager;
+    }
+    
+    public Optional<Mailbox> fromMailboxPath(MailboxPath mailboxPath, MailboxSession
mailboxSession) {
+        try {
+            MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, mailboxSession);
+            return fromMessageManager(mailbox, mailboxSession);
+        } catch (MailboxException e) {
+            LOGGER.warn("Cannot find mailbox for: " + mailboxPath.getName(), e);
+            return Optional.empty();
+        }
+    }
+
+    public Optional<Mailbox> fromMailboxId(MailboxId mailboxId, MailboxSession mailboxSession)
{
+        try {
+            MessageManager mailbox = mailboxManager.getMailbox(mailboxId, mailboxSession);
+            return fromMessageManager(mailbox, mailboxSession);
+        } catch (MailboxException e) {
+            return Optional.empty();
+        }
+    }
+
+    private Optional<Mailbox> fromMessageManager(MessageManager messageManager, MailboxSession
mailboxSession) throws MailboxException {
+        MailboxPath mailboxPath = messageManager.getMailboxPath();
+        Optional<Role> role = Role.from(mailboxPath.getName());
+        MessageManager.MetaData mailboxMetaData = getMailboxMetaData(messageManager, mailboxSession);
+        return Optional.ofNullable(Mailbox.builder()
+                .id(messageManager.getId())
+                .name(getName(mailboxPath, mailboxSession))
+                .parentId(getParentIdFromMailboxPath(mailboxPath, mailboxSession).orElse(null))
+                .role(role)
+                .unreadMessages(mailboxMetaData.getUnseenCount())
+                .totalMessages(mailboxMetaData.getMessageCount())
+                .sortOrder(SortOrder.getSortOrder(role))
+                .build());
+    }
+
+    private MessageManager.MetaData getMailboxMetaData(MessageManager messageManager, MailboxSession
mailboxSession) throws MailboxException {
+        return messageManager.getMetaData(DONT_RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.UNSEEN_COUNT);
+    }
+
+    @VisibleForTesting String getName(MailboxPath mailboxPath, MailboxSession mailboxSession)
{
+        String name = mailboxPath.getName();
+        if (name.contains(String.valueOf(mailboxSession.getPathDelimiter()))) {
+            List<String> levels = Splitter.on(mailboxSession.getPathDelimiter()).splitToList(name);
+            return levels.get(levels.size() - 1);
+        }
+        return name;
+    }
+
+    @VisibleForTesting Optional<MailboxId> getParentIdFromMailboxPath(MailboxPath mailboxPath,
MailboxSession mailboxSession) throws MailboxException {
+        List<MailboxPath> levels = mailboxPath.getHierarchyLevels(mailboxSession.getPathDelimiter());
+        if (levels.size() <= 1) {
+            return Optional.empty();
+        }
+        MailboxPath parent = levels.get(levels.size() - 2);
+        return Optional.of(getMailboxId(parent, mailboxSession));
+    }
+
+    private MailboxId getMailboxId(MailboxPath mailboxPath, MailboxSession mailboxSession)
throws MailboxException {
+        return mailboxManager.getMailbox(mailboxPath, mailboxSession)
+                .getId();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ecb7ef5/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
index 666b149..e94fd58 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
@@ -19,34 +19,21 @@ O * Licensed to the Apache Software Foundation (ASF) under one   *
 
 package org.apache.james.jmap.utils;
 
-import java.util.List;
 import java.util.Optional;
 
 import javax.inject.Inject;
 
-import org.apache.james.jmap.model.mailbox.Mailbox;
-import org.apache.james.jmap.model.mailbox.Role;
-import org.apache.james.jmap.model.mailbox.SortOrder;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.github.fge.lambdas.Throwing;
-import com.github.fge.lambdas.functions.ThrowingFunction;
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Splitter;
 
 public class MailboxUtils {
-
-    private static final boolean DONT_RESET_RECENT = false;
-    private static final Logger LOGGER = LoggerFactory.getLogger(MailboxUtils.class);
-
     private final MailboxManager mailboxManager;
 
     @Inject
@@ -55,47 +42,11 @@ public class MailboxUtils {
         this.mailboxManager = mailboxManager;
     }
 
-    public Optional<Mailbox> mailboxFromMailboxPath(MailboxPath mailboxPath, MailboxSession
mailboxSession) {
-        try {
-            MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, mailboxSession);
-            return mailboxFromMessageManager(mailbox, mailboxSession);
-        } catch (MailboxException e) {
-            LOGGER.warn("Cannot find mailbox for: " + mailboxPath.getName(), e);
-            return Optional.empty();
-        }
-    }
-
-    private Optional<Mailbox> mailboxFromMessageManager(MessageManager messageManager,
MailboxSession mailboxSession) throws MailboxException {
-        MailboxPath mailboxPath = messageManager.getMailboxPath();
-        Optional<Role> role = Role.from(mailboxPath.getName());
-        MessageManager.MetaData mailboxMetaData = getMailboxMetaData(messageManager, mailboxSession);
-        return Optional.ofNullable(Mailbox.builder()
-                .id(messageManager.getId())
-                .name(getName(mailboxPath, mailboxSession))
-                .parentId(getParentIdFromMailboxPath(mailboxPath, mailboxSession).orElse(null))
-                .role(role)
-                .unreadMessages(mailboxMetaData.getUnseenCount())
-                .totalMessages(mailboxMetaData.getMessageCount())
-                .sortOrder(SortOrder.getSortOrder(role))
-                .build());
-    }
-
-    private MessageManager.MetaData getMailboxMetaData(MessageManager messageManager, MailboxSession
mailboxSession) throws MailboxException {
-        return messageManager.getMetaData(DONT_RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.UNSEEN_COUNT);
-    }
-
-    private MailboxId getMailboxId(MailboxPath mailboxPath, MailboxSession mailboxSession)
throws MailboxException {
-        return mailboxManager.getMailbox(mailboxPath, mailboxSession)
-                .getId();
-    }
-
-    @VisibleForTesting String getName(MailboxPath mailboxPath, MailboxSession mailboxSession)
{
-        String name = mailboxPath.getName();
-        if (name.contains(String.valueOf(mailboxSession.getPathDelimiter()))) {
-            List<String> levels = Splitter.on(mailboxSession.getPathDelimiter()).splitToList(name);
-            return levels.get(levels.size() - 1);
-        }
-        return name;
+    public boolean hasChildren(MailboxId mailboxId, MailboxSession mailboxSession) throws
MailboxException {
+        return getMailboxFromId(mailboxId, mailboxSession)
+                .map(Throwing.function(MessageManager::getMailboxPath).sneakyThrow())
+                .map(Throwing.function(path -> mailboxManager.hasChildren(path, mailboxSession)))
+                .orElse(false);
     }
 
     private Optional<MessageManager> getMailboxFromId(MailboxId mailboxId, MailboxSession
mailboxSession) throws MailboxException {
@@ -105,30 +56,4 @@ public class MailboxUtils {
             return Optional.empty();
         }
     }
-
-    @VisibleForTesting Optional<MailboxId> getParentIdFromMailboxPath(MailboxPath mailboxPath,
MailboxSession mailboxSession) throws MailboxException {
-        List<MailboxPath> levels = mailboxPath.getHierarchyLevels(mailboxSession.getPathDelimiter());
-        if (levels.size() <= 1) {
-            return Optional.empty();
-        }
-        MailboxPath parent = levels.get(levels.size() - 2);
-        return Optional.of(getMailboxId(parent, mailboxSession));
-    }
-
-    public Optional<Mailbox> mailboxFromMailboxId(MailboxId mailboxId, MailboxSession
mailboxSession) {
-        ThrowingFunction<MessageManager, Optional<Mailbox>> toMailbox = path
-> mailboxFromMessageManager(path, mailboxSession);
-        try {
-            return getMailboxFromId(mailboxId, mailboxSession)
-                .flatMap(Throwing.function(toMailbox).sneakyThrow());
-        } catch (MailboxException e) {
-            return Optional.empty();
-        }
-    }
-
-    public boolean hasChildren(MailboxId mailboxId, MailboxSession mailboxSession) throws
MailboxException {
-        return getMailboxFromId(mailboxId, mailboxSession)
-                .map(Throwing.function(MessageManager::getMailboxPath).sneakyThrow())
-                .map(Throwing.function(path -> mailboxManager.hasChildren(path, mailboxSession)))
-                .orElse(false);
-    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ecb7ef5/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
index e3461d4..be20137 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
@@ -34,10 +34,10 @@ import javax.mail.Flags;
 import org.apache.james.jmap.model.ClientId;
 import org.apache.james.jmap.model.GetMailboxesRequest;
 import org.apache.james.jmap.model.GetMailboxesResponse;
+import org.apache.james.jmap.model.MailboxFactory;
 import org.apache.james.jmap.model.mailbox.Mailbox;
 import org.apache.james.jmap.model.mailbox.Role;
 import org.apache.james.jmap.model.mailbox.SortOrder;
-import org.apache.james.jmap.utils.MailboxUtils;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
@@ -71,7 +71,7 @@ public class GetMailboxesMethodTest {
     private GetMailboxesMethod getMailboxesMethod;
     private ClientId clientId;
     private InMemoryMailboxSessionMapperFactory mailboxMapperFactory;
-    private MailboxUtils mailboxUtils;
+    private MailboxFactory mailboxFactory;
 
     @Before
     public void setup() throws Exception {
@@ -82,9 +82,9 @@ public class GetMailboxesMethodTest {
         MessageParser messageParser = new MessageParser();
         mailboxManager = new StoreMailboxManager(mailboxMapperFactory, new MockAuthenticator(),
aclResolver, groupMembershipResolver, messageParser);
         mailboxManager.init();
-        mailboxUtils = new MailboxUtils(mailboxManager);
+        mailboxFactory = new MailboxFactory(mailboxManager);
 
-        getMailboxesMethod = new GetMailboxesMethod(mailboxManager, mailboxUtils);
+        getMailboxesMethod = new GetMailboxesMethod(mailboxManager, mailboxFactory);
     }
 
     @Test
@@ -112,7 +112,7 @@ public class GetMailboxesMethodTest {
             .thenReturn(ImmutableList.of(new MailboxPath("namespace", "user", "name")));
         when(mockedMailboxManager.getMailbox(any(MailboxPath.class), any()))
             .thenThrow(new MailboxException());
-        GetMailboxesMethod testee = new GetMailboxesMethod(mockedMailboxManager, mailboxUtils);
+        GetMailboxesMethod testee = new GetMailboxesMethod(mockedMailboxManager, mailboxFactory);
         
         GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
                 .build();

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ecb7ef5/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
index fdf8f31..c16aa4e 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesCreationProcessorTest.java
@@ -24,11 +24,11 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import org.apache.james.jmap.model.MailboxCreationId;
+import org.apache.james.jmap.model.MailboxFactory;
 import org.apache.james.jmap.model.SetError;
 import org.apache.james.jmap.model.SetMailboxesRequest;
 import org.apache.james.jmap.model.SetMailboxesResponse;
 import org.apache.james.jmap.model.mailbox.MailboxCreateRequest;
-import org.apache.james.jmap.utils.MailboxUtils;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
@@ -40,17 +40,16 @@ import org.junit.Test;
 
 public class SetMailboxesCreationProcessorTest {
 
-    private MailboxUtils mailboxUtils;
     private Factory mailboxIdFactory;
+    private MailboxFactory mailboxFactory;
     private SetMailboxesCreationProcessor sut;
     private MailboxManager mailboxManager;
 
     @Before
     public void setup() {
-        mailboxUtils = mock(MailboxUtils.class);
         mailboxManager = mock(MailboxManager.class);
         mailboxIdFactory = new InMemoryId.Factory();
-        sut = new SetMailboxesCreationProcessor(mailboxManager, mailboxUtils, mailboxIdFactory);
+        sut = new SetMailboxesCreationProcessor(mailboxManager, mailboxFactory, mailboxIdFactory);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ecb7ef5/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
index 377681c..ec1cc15 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessorTest.java
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.when;
 
 import java.util.Optional;
 
+import org.apache.james.jmap.model.MailboxFactory;
 import org.apache.james.jmap.model.SetError;
 import org.apache.james.jmap.model.SetMailboxesRequest;
 import org.apache.james.jmap.model.SetMailboxesResponse;
@@ -43,6 +44,7 @@ public class SetMailboxesUpdateProcessorTest {
 
     private MailboxManager mockedMailboxManager;
     private MailboxUtils mockedMailboxUtils;
+    private MailboxFactory mockedMailboxFactory;
     private MailboxSession mockedMailboxSession;
     private SetMailboxesUpdateProcessor sut;
 
@@ -50,8 +52,9 @@ public class SetMailboxesUpdateProcessorTest {
     public void setup() {
         mockedMailboxManager = mock(MailboxManager.class);
         mockedMailboxUtils = mock(MailboxUtils.class);
+        mockedMailboxFactory = mock(MailboxFactory.class);
         mockedMailboxSession = mock(MailboxSession.class);
-        sut = new SetMailboxesUpdateProcessor(mockedMailboxUtils, mockedMailboxManager);
+        sut = new SetMailboxesUpdateProcessor(mockedMailboxUtils, mockedMailboxManager, mockedMailboxFactory);
     }
 
     @Test
@@ -63,7 +66,7 @@ public class SetMailboxesUpdateProcessorTest {
                 .update(mailboxId, MailboxUpdateRequest.builder().parentId(newParentId).build())
                 .build();
         Mailbox mailbox = Mailbox.builder().id(mailboxId).name("name").role(Optional.empty()).build();
-        when(mockedMailboxUtils.mailboxFromMailboxId(mailboxId, mockedMailboxSession))
+        when(mockedMailboxFactory.fromMailboxId(mailboxId, mockedMailboxSession))
             .thenReturn(Optional.of(mailbox));
         when(mockedMailboxManager.getMailbox(newParentId, mockedMailboxSession))
             .thenReturn(mock(MessageManager.class));

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ecb7ef5/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
new file mode 100644
index 0000000..e404b70
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxFactoryTest.java
@@ -0,0 +1,165 @@
+/****************************************************************
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Optional;
+
+import org.apache.james.jmap.model.mailbox.Mailbox;
+import org.apache.james.jmap.utils.MailboxUtilsTest;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.inmemory.InMemoryId;
+import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
+import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MailboxFactoryTest {
+    private static final Logger LOGGER = LoggerFactory.getLogger(MailboxUtilsTest.class);
+
+    private MailboxManager mailboxManager;
+    private MailboxMapperFactory mailboxMapperFactory;
+    private MailboxSession mailboxSession;
+    private String user;
+    private MailboxFactory sut;
+
+    @Before
+    public void setup() throws Exception {
+        InMemoryIntegrationResources inMemoryIntegrationResources = new InMemoryIntegrationResources();
+        mailboxManager = inMemoryIntegrationResources.createMailboxManager(inMemoryIntegrationResources.createGroupMembershipResolver());
+        mailboxMapperFactory = new InMemoryMailboxSessionMapperFactory();
+        user = "user@domain.org";
+        mailboxSession = mailboxManager.login(user, "pass", LOGGER);
+        sut = new MailboxFactory(mailboxManager);
+    }
+
+
+    @Test
+    public void mailboxFromMailboxIdShouldReturnAbsentWhenDoesntExist() throws Exception
{
+        Optional<Mailbox> mailbox = sut.fromMailboxId(InMemoryId.of(123), mailboxSession);
+        assertThat(mailbox).isEmpty();
+    }
+
+    @Test
+    public void mailboxFromMailboxIdShouldReturnPresentWhenExists() throws Exception {
+        MailboxPath mailboxPath = new MailboxPath("#private", user, "myBox");
+        mailboxManager.createMailbox(mailboxPath, mailboxSession);
+        MailboxId mailboxId = mailboxMapperFactory.getMailboxMapper(mailboxSession)
+                .findMailboxByPath(mailboxPath)
+                .getMailboxId();
+
+        Optional<Mailbox> mailbox = sut.fromMailboxId(mailboxId, mailboxSession);
+        assertThat(mailbox).isPresent();
+        assertThat(mailbox.get().getId()).isEqualTo(mailboxId);
+    }
+
+    @Test
+    public void mailboxFromMailboxPathShouldReturnNotEmptyWhenMailboxExists() throws Exception
{
+        MailboxPath mailboxPath = new MailboxPath("#private", user, "mailbox");
+        mailboxManager.createMailbox(mailboxPath, mailboxSession);
+
+        Optional<Mailbox> optionalMailbox = sut.fromMailboxPath(mailboxPath, mailboxSession);
+        assertThat(optionalMailbox).isPresent();
+    }
+
+    @Test
+    public void mailboxFromMailboxPathShouldReturnEmptyWhenMailboxDoesntExist() throws Exception
{
+        MailboxPath mailboxPath = new MailboxPath("#private", user, "mailbox");
+
+        Optional<Mailbox> optionalMailbox = sut.fromMailboxPath(mailboxPath, mailboxSession);
+        assertThat(optionalMailbox).isEmpty();
+    }
+
+
+    @Test
+    public void getNameShouldReturnMailboxNameWhenRootMailbox() throws Exception {
+        String expected = "mailbox";
+        MailboxPath mailboxPath = new MailboxPath("#private", user, expected);
+
+        String name = sut.getName(mailboxPath, mailboxSession);
+        assertThat(name).isEqualTo(expected);
+    }
+
+    @Test
+    public void getNameShouldReturnMailboxNameWhenChildMailbox() throws Exception {
+        String expected = "mailbox";
+        MailboxPath mailboxPath = new MailboxPath("#private", user, "inbox." + expected);
+
+        String name = sut.getName(mailboxPath, mailboxSession);
+        assertThat(name).isEqualTo(expected);
+    }
+
+    @Test
+    public void getNameShouldReturnMailboxNameWhenChildOfChildMailbox() throws Exception
{
+        String expected = "mailbox";
+        MailboxPath mailboxPath = new MailboxPath("#private", user, "inbox.children." + expected);
+
+        String name = sut.getName(mailboxPath, mailboxSession);
+        assertThat(name).isEqualTo(expected);
+    }
+
+    @Test
+    public void getParentIdFromMailboxPathShouldReturNullWhenRootMailbox() throws Exception
{
+        MailboxPath mailboxPath = new MailboxPath("#private", user, "mailbox");
+        mailboxManager.createMailbox(mailboxPath, mailboxSession);
+
+        Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
+        assertThat(id).isEmpty();
+    }
+
+    @Test
+    public void getParentIdFromMailboxPathShouldReturnParentIdWhenChildMailbox() throws Exception
{
+        MailboxPath parentMailboxPath = new MailboxPath("#private", user, "inbox");
+        mailboxManager.createMailbox(parentMailboxPath, mailboxSession);
+        MailboxId parentId = mailboxMapperFactory.getMailboxMapper(mailboxSession)
+                .findMailboxByPath(parentMailboxPath)
+                .getMailboxId();
+
+        MailboxPath mailboxPath = new MailboxPath("#private", user, "inbox.mailbox");
+        mailboxManager.createMailbox(mailboxPath, mailboxSession);
+
+        Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
+        assertThat(id).contains(parentId);
+    }
+
+    @Test
+    public void getParentIdFromMailboxPathShouldReturnParentIdWhenChildOfChildMailbox() throws
Exception {
+        MailboxPath mailboxPath = new MailboxPath("#private", user, "inbox.children.mailbox");
+        mailboxManager.createMailbox(new MailboxPath("#private", user, "inbox"), mailboxSession);
+
+        MailboxPath parentMailboxPath = new MailboxPath("#private", user, "inbox.children");
+        mailboxManager.createMailbox(parentMailboxPath, mailboxSession);
+        MailboxId parentId = mailboxMapperFactory.getMailboxMapper(mailboxSession)
+                .findMailboxByPath(parentMailboxPath)
+                .getMailboxId();
+
+        mailboxManager.createMailbox(mailboxPath, mailboxSession);
+
+        Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
+        assertThat(id).contains(parentId);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ecb7ef5/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
index f374a04..dc85e3e 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
@@ -21,12 +21,8 @@ package org.apache.james.jmap.utils;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.util.Optional;
-
-import org.apache.james.jmap.model.mailbox.Mailbox;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
 import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
 import org.apache.james.mailbox.model.MailboxId;
@@ -56,111 +52,6 @@ public class MailboxUtilsTest {
         mailboxSession = mailboxManager.login(user, "pass", LOGGER);
         sut = new MailboxUtils(mailboxManager);
     }
-
-    @Test
-    public void mailboxFromMailboxPathShouldReturnNotEmptyWhenMailboxExists() throws Exception
{
-        MailboxPath mailboxPath = new MailboxPath("#private", user, "mailbox");
-        mailboxManager.createMailbox(mailboxPath, mailboxSession);
-
-        Optional<Mailbox> optionalMailbox = sut.mailboxFromMailboxPath(mailboxPath,
mailboxSession);
-        assertThat(optionalMailbox).isPresent();
-    }
-
-    @Test
-    public void mailboxFromMailboxPathShouldReturnEmptyWhenMailboxDoesntExist() throws Exception
{
-        MailboxPath mailboxPath = new MailboxPath("#private", user, "mailbox");
-
-        Optional<Mailbox> optionalMailbox = sut.mailboxFromMailboxPath(mailboxPath,
mailboxSession);
-        assertThat(optionalMailbox).isEmpty();
-    }
-
-    @Test
-    public void getNameShouldReturnMailboxNameWhenRootMailbox() throws Exception {
-        String expected = "mailbox";
-        MailboxPath mailboxPath = new MailboxPath("#private", user, expected);
-
-        String name = sut.getName(mailboxPath, mailboxSession);
-        assertThat(name).isEqualTo(expected);
-    }
-
-    @Test
-    public void getNameShouldReturnMailboxNameWhenChildMailbox() throws Exception {
-        String expected = "mailbox";
-        MailboxPath mailboxPath = new MailboxPath("#private", user, "inbox." + expected);
-
-        String name = sut.getName(mailboxPath, mailboxSession);
-        assertThat(name).isEqualTo(expected);
-    }
-
-    @Test
-    public void getNameShouldReturnMailboxNameWhenChildOfChildMailbox() throws Exception
{
-        String expected = "mailbox";
-        MailboxPath mailboxPath = new MailboxPath("#private", user, "inbox.children." + expected);
-
-        String name = sut.getName(mailboxPath, mailboxSession);
-        assertThat(name).isEqualTo(expected);
-    }
-
-    @Test
-    public void getParentIdFromMailboxPathShouldReturNullWhenRootMailbox() throws Exception
{
-        MailboxPath mailboxPath = new MailboxPath("#private", user, "mailbox");
-        mailboxManager.createMailbox(mailboxPath, mailboxSession);
-
-        Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
-        assertThat(id).isEmpty();
-    }
-
-    @Test
-    public void getParentIdFromMailboxPathShouldReturnParentIdWhenChildMailbox() throws Exception
{
-        MailboxPath parentMailboxPath = new MailboxPath("#private", user, "inbox");
-        mailboxManager.createMailbox(parentMailboxPath, mailboxSession);
-        MailboxId parentId = mailboxMapperFactory.getMailboxMapper(mailboxSession)
-                .findMailboxByPath(parentMailboxPath)
-                .getMailboxId();
-
-        MailboxPath mailboxPath = new MailboxPath("#private", user, "inbox.mailbox");
-        mailboxManager.createMailbox(mailboxPath, mailboxSession);
-
-        Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
-        assertThat(id).contains(parentId);
-    }
-
-    @Test
-    public void getParentIdFromMailboxPathShouldReturnParentIdWhenChildOfChildMailbox() throws
Exception {
-        MailboxPath mailboxPath = new MailboxPath("#private", user, "inbox.children.mailbox");
-        mailboxManager.createMailbox(new MailboxPath("#private", user, "inbox"), mailboxSession);
-
-        MailboxPath parentMailboxPath = new MailboxPath("#private", user, "inbox.children");
-        mailboxManager.createMailbox(parentMailboxPath, mailboxSession);
-        MailboxId parentId = mailboxMapperFactory.getMailboxMapper(mailboxSession)
-                .findMailboxByPath(parentMailboxPath)
-                .getMailboxId();
-
-        mailboxManager.createMailbox(mailboxPath, mailboxSession);
-
-        Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
-        assertThat(id).contains(parentId);
-    }
-
-    @Test
-    public void mailboxFromMailboxIdShouldReturnPresentWhenExists() throws Exception {
-        MailboxPath mailboxPath = new MailboxPath("#private", user, "myBox");
-        mailboxManager.createMailbox(mailboxPath, mailboxSession);
-        MailboxId mailboxId = mailboxMapperFactory.getMailboxMapper(mailboxSession)
-                .findMailboxByPath(mailboxPath)
-                .getMailboxId();
-
-        Optional<Mailbox> mailbox = sut.mailboxFromMailboxId(mailboxId, mailboxSession);
-        assertThat(mailbox).isPresent();
-        assertThat(mailbox.get().getId()).isEqualTo(mailboxId);
-    }
-
-    @Test
-    public void mailboxFromMailboxIdShouldReturnAbsentWhenDoesntExist() throws Exception
{
-        Optional<Mailbox> mailbox = sut.mailboxFromMailboxId(InMemoryId.of(123), mailboxSession);
-        assertThat(mailbox).isEmpty();
-    }
-
     @Test
     public void hasChildrenShouldReturnFalseWhenNoChild() throws Exception {
         MailboxPath mailboxPath = new MailboxPath("#private", user, "myBox");


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message