MailboxUtils { 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); } @Inject @VisibleForTesting  MailboxUtils(MailboxManager mailboxManager); boolean hasChildren(MailboxId mailboxId, MailboxSession mailboxSession);  }
@Test public void hasChildrenShouldReturnFalseWhenNoChild() throws Exception { MailboxPath mailboxPath = MailboxPath.forUser(user, "myBox"); mailboxManager.createMailbox(mailboxPath, mailboxSession); MailboxId mailboxId = mailboxManager.getMailbox(mailboxPath, mailboxSession).getId(); assertThat(sut.hasChildren(mailboxId, mailboxSession)).isFalse(); }
@Test public void hasChildrenShouldReturnTrueWhenHasAChild() throws Exception { MailboxPath parentMailboxPath = MailboxPath.forUser(user, MailboxConstants.INBOX); mailboxManager.createMailbox(parentMailboxPath, mailboxSession); MailboxId parentId = mailboxManager.getMailbox(parentMailboxPath, mailboxSession).getId(); MailboxPath mailboxPath = MailboxPath.forUser(user, "INBOX.myBox"); mailboxManager.createMailbox(mailboxPath, mailboxSession); assertThat(sut.hasChildren(parentId, mailboxSession)).isTrue(); }