@Test public void getParentIdFromMailboxPathShouldReturnParentIdWhenChildMailbox() throws Exception { MailboxPath parentMailboxPath = MailboxPath.inbox(user); mailboxManager.createMailbox(parentMailboxPath, mailboxSession); MailboxId parentId = mailboxManager.getMailbox(parentMailboxPath, mailboxSession).getId(); MailboxPath mailboxPath = parentMailboxPath.child("mailbox", '.'); mailboxManager.createMailbox(mailboxPath, mailboxSession); Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, Optional.empty(), mailboxSession); assertThat(id).contains(parentId); }
@VisibleForTesting Optional<MailboxId> getParentIdFromMailboxPath(MailboxPath mailboxPath, Optional<List<MailboxMetaData>> userMailboxesMetadata, 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 userMailboxesMetadata.map(list -> retrieveParentFromMetadata(parent, list)) .orElseGet(Throwing.supplier(() -> retrieveParentFromBackend(mailboxSession, parent)).sneakyThrow()); }
MailboxFactory { @VisibleForTesting Optional<MailboxId> getParentIdFromMailboxPath(MailboxPath mailboxPath, Optional<List<MailboxMetaData>> userMailboxesMetadata, 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 userMailboxesMetadata.map(list -> retrieveParentFromMetadata(parent, list)) .orElseGet(Throwing.supplier(() -> retrieveParentFromBackend(mailboxSession, parent)).sneakyThrow()); } }
MailboxFactory { @VisibleForTesting Optional<MailboxId> getParentIdFromMailboxPath(MailboxPath mailboxPath, Optional<List<MailboxMetaData>> userMailboxesMetadata, 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 userMailboxesMetadata.map(list -> retrieveParentFromMetadata(parent, list)) .orElseGet(Throwing.supplier(() -> retrieveParentFromBackend(mailboxSession, parent)).sneakyThrow()); } @Inject  MailboxFactory(MailboxManager mailboxManager, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver); }
MailboxFactory { @VisibleForTesting Optional<MailboxId> getParentIdFromMailboxPath(MailboxPath mailboxPath, Optional<List<MailboxMetaData>> userMailboxesMetadata, 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 userMailboxesMetadata.map(list -> retrieveParentFromMetadata(parent, list)) .orElseGet(Throwing.supplier(() -> retrieveParentFromBackend(mailboxSession, parent)).sneakyThrow()); } @Inject  MailboxFactory(MailboxManager mailboxManager, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver); MailboxBuilder builder(); }
MailboxFactory { @VisibleForTesting Optional<MailboxId> getParentIdFromMailboxPath(MailboxPath mailboxPath, Optional<List<MailboxMetaData>> userMailboxesMetadata, 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 userMailboxesMetadata.map(list -> retrieveParentFromMetadata(parent, list)) .orElseGet(Throwing.supplier(() -> retrieveParentFromBackend(mailboxSession, parent)).sneakyThrow()); } @Inject  MailboxFactory(MailboxManager mailboxManager, QuotaManager quotaManager, QuotaRootResolver quotaRootResolver); MailboxBuilder builder();  }