@Test public void assertIsUserOwnerOfMailboxesShouldThrowWhenUserIsNotTheOwnerOfTheMailbox() throws Exception { InMemoryId mailboxId = InMemoryId.of(6789); MessageManager mailbox = mock(MessageManager.class); when(mockedMailboxManager.getMailbox(mailboxId, session)) .thenReturn(mailbox); when(mockedMailboxIdFactory.fromString(mailboxId.serialize())) .thenReturn(mailboxId); when(mailbox.getMailboxPath()) .thenReturn(MailboxPath.forUser("otheruser@example.com", mailboxId.serialize())); assertThatThrownBy(() -> sut.assertIsUserOwnerOfMailboxes(ImmutableList.of(mailboxId), session)) .isInstanceOf(MailboxNotOwnedException.class); }
@Test public void assertIsUserOwnerOfMailboxesShouldNotThrowWhenUserIsTheOwnerOfTheMailbox() throws Exception { InMemoryId mailboxId = InMemoryId.of(6789); MessageManager mailbox = mock(MessageManager.class); when(mockedMailboxManager.getMailbox(mailboxId, session)) .thenReturn(mailbox); when(mockedMailboxIdFactory.fromString(mailboxId.serialize())) .thenReturn(mailboxId); when(mailbox.getMailboxPath()) .thenReturn(MailboxPath.forUser(USER, mailboxId.serialize())); sut.assertIsUserOwnerOfMailboxes(ImmutableList.of(mailboxId), session); }
@Test public void assertIsUserOwnerOfMailboxesShouldThrowWhenRetrievingMailboxPathFails() throws Exception { InMemoryId mailboxId = InMemoryId.of(6789); MessageManager mailbox = mock(MessageManager.class); when(mockedMailboxManager.getMailbox(mailboxId, session)) .thenReturn(mailbox); when(mockedMailboxIdFactory.fromString(mailboxId.serialize())) .thenReturn(mailboxId); when(mailbox.getMailboxPath()) .thenThrow(new MailboxException()); assertThatThrownBy(() -> sut.assertIsUserOwnerOfMailboxes(ImmutableList.of(mailboxId), session)); }
@Test public void validateIsUserOwnerOfMailboxesShouldThrowWhenMailboxIdDoesntExist() throws Exception { InMemoryId mailboxId = InMemoryId.of(6789); when(mockedMailboxManager.getMailbox(mailboxId, session)) .thenThrow(new MailboxNotFoundException(mailboxId)); when(mockedMailboxIdFactory.fromString(mailboxId.serialize())) .thenReturn(mailboxId); assertThatThrownBy(() -> sut.assertIsUserOwnerOfMailboxes(ImmutableList.of(mailboxId), session)); }
@Test public void processShouldNotSendWhenSavingToDrafts() throws Exception { // When CreationMessageId creationMessageId = CreationMessageId.of("anything-really"); SetMessagesRequest createMessageInDrafts = SetMessagesRequest.builder() .create( creationMessageId, creationMessageBuilder.mailboxId(DRAFTS_ID.serialize()).build()) .build(); when(mockedMailboxManager.getMailbox(any(MailboxId.class), any())) .thenReturn(drafts); when(mockedMailboxIdFactory.fromString(anyString())).thenReturn(DRAFTS_ID); sut.process(createMessageInDrafts, session); // Then verify(mockedMailSpool, never()).send(any(Mail.class), any(MailMetadata.class)); }
when(mockedMailboxIdFactory.fromString(OUTBOX_ID.serialize())) .thenReturn(OUTBOX_ID); when(mockedMailboxManager.getMailbox(OUTBOX_ID, session))
@Test public void processShouldCreateWhenKeywords() { SetMessagesRequest createMessageWithKeywords = SetMessagesRequest.builder() .create( creationMessageId, creationMessageBuilder .mailboxId(OUTBOX_ID.serialize()) .keywords(ImmutableMap.of("$Answered", true)) .build()) .build(); SetMessagesResponse result = sut.process(createMessageWithKeywords, session); assertThat(result.getCreated()).isNotEmpty(); assertThat(result.getNotCreated()).isEmpty(); }
@Test public void processShouldCreateWhenIsFlag() { SetMessagesRequest createMessageWithKeywords = SetMessagesRequest.builder() .create( creationMessageId, creationMessageBuilder .mailboxId(OUTBOX_ID.serialize()) .isAnswered(Optional.of(true)) .build()) .build(); SetMessagesResponse result = sut.process(createMessageWithKeywords, session); assertThat(result.getCreated()).isNotEmpty(); assertThat(result.getNotCreated()).isEmpty(); }
@Test public void processShouldThrowWhenBothIsFlagAndKeywords() { expectedException.expect(IllegalArgumentException.class); SetMessagesRequest createMessageWithError = SetMessagesRequest.builder() .create( creationMessageId, creationMessageBuilder .mailboxId(OUTBOX_ID.serialize()) .isAnswered(Optional.of(true)) .keywords(ImmutableMap.of("$Answered", true)) .build()) .build(); sut.process(createMessageWithError, session); }