MailboxAppender { public ComposedMessageId append(MimeMessage mail, Username user, String folder) throws MessagingException { MailboxSession session = createMailboxSession(user); return append(mail, user, useSlashAsSeparator(folder, session), session) .getId(); } MailboxAppender(MailboxManager mailboxManager); ComposedMessageId append(MimeMessage mail, Username user, String folder); MailboxSession createMailboxSession(Username user);  }
@Test void appendShouldAddMessageToDesiredMailbox() throws Exception { testee.append(mimeMessage, USER, FOLDER); MessageResultIterator messages = mailboxManager.getMailbox(MailboxPath.forUser(USER, FOLDER), session) .getMessages(MessageRange.all(), FetchGroup.FULL_CONTENT, session); assertThat(messages).toIterable() .hasSize(1); }
@Test void appendShouldAddMessageToDesiredMailboxWhenMailboxExists() throws Exception { MailboxPath mailboxPath = MailboxPath.forUser(USER, FOLDER); mailboxManager.createMailbox(mailboxPath, session); testee.append(mimeMessage, USER, FOLDER); MessageResultIterator messages = mailboxManager.getMailbox(mailboxPath, session) .getMessages(MessageRange.all(), FetchGroup.FULL_CONTENT, session); assertThat(messages).toIterable() .hasSize(1); }
@Test void appendShouldNotAppendToEmptyFolder() { assertThatThrownBy(() -> testee.append(mimeMessage, USER, EMPTY_FOLDER)) .isInstanceOf(MessagingException.class); }
@Test void appendShouldRemovePathSeparatorAsFirstChar() throws Exception { testee.append(mimeMessage, USER, "." + FOLDER); MessageResultIterator messages = mailboxManager.getMailbox(MailboxPath.forUser(USER, FOLDER), session) .getMessages(MessageRange.all(), FetchGroup.FULL_CONTENT, session); assertThat(messages).toIterable() .hasSize(1); }
@Test void appendShouldReplaceSlashBySeparator() throws Exception { testee.append(mimeMessage, USER, FOLDER + "/any"); MessageResultIterator messages = mailboxManager.getMailbox(MailboxPath.forUser(USER, FOLDER + ".any"), session) .getMessages(MessageRange.all(), FetchGroup.FULL_CONTENT, session); assertThat(messages).toIterable() .hasSize(1); }