Search in sources :

Example 1 with MessageBuilder

use of com.fsck.k9.message.MessageBuilder in project k-9 by k9mail.

the class MessageBuilderTest method build_withMessageAttachment_shouldAttachAsApplicationOctetStream.

@Test
public void build_withMessageAttachment_shouldAttachAsApplicationOctetStream() throws Exception {
    MessageBuilder messageBuilder = createSimpleMessageBuilder();
    Attachment attachment = createAttachmentWithContent("message/rfc822", "attach.txt", TEST_ATTACHMENT_TEXT);
    messageBuilder.setAttachments(Collections.singletonList(attachment));
    messageBuilder.buildAsync(callback);
    MimeMessage message = getMessageFromCallback();
    assertEquals(MESSAGE_HEADERS + MESSAGE_CONTENT_WITH_MESSAGE_ATTACH, getMessageContents(message));
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Attachment(com.fsck.k9.activity.misc.Attachment) Test(org.junit.Test)

Example 2 with MessageBuilder

use of com.fsck.k9.message.MessageBuilder in project k-9 by k9mail.

the class MessageBuilderTest method buildWithException_shouldThrow.

@Test
public void buildWithException_shouldThrow() throws MessagingException {
    MessageBuilder messageBuilder = new SimpleMessageBuilder(context, messageIdGenerator, boundaryGenerator) {

        @Override
        protected void buildMessageInternal() {
            queueMessageBuildException(new MessagingException("expected error"));
        }
    };
    messageBuilder.buildAsync(callback);
    verify(callback).onMessageBuildException(any(MessagingException.class));
    verifyNoMoreInteractions(callback);
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) Test(org.junit.Test)

Example 3 with MessageBuilder

use of com.fsck.k9.message.MessageBuilder in project k-9 by k9mail.

the class MessageBuilderTest method build_shouldSucceed.

@Test
public void build_shouldSucceed() throws Exception {
    MessageBuilder messageBuilder = createSimpleMessageBuilder();
    messageBuilder.buildAsync(callback);
    MimeMessage message = getMessageFromCallback();
    assertEquals("text/plain", message.getMimeType());
    assertEquals(TEST_SUBJECT, message.getSubject());
    assertEquals(TEST_IDENTITY_ADDRESS, message.getFrom()[0]);
    assertArrayEquals(TEST_TO, message.getRecipients(RecipientType.TO));
    assertArrayEquals(TEST_CC, message.getRecipients(RecipientType.CC));
    assertArrayEquals(TEST_BCC, message.getRecipients(RecipientType.BCC));
    assertEquals(MESSAGE_HEADERS + MESSAGE_CONTENT, getMessageContents(message));
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Test(org.junit.Test)

Example 4 with MessageBuilder

use of com.fsck.k9.message.MessageBuilder in project k-9 by k9mail.

the class MessageBuilderTest method build_detachAndReattach_shouldSucceed.

@Test
public void build_detachAndReattach_shouldSucceed() throws MessagingException {
    MessageBuilder messageBuilder = createSimpleMessageBuilder();
    Callback anotherCallback = mock(Callback.class);
    Robolectric.getBackgroundThreadScheduler().pause();
    messageBuilder.buildAsync(callback);
    messageBuilder.detachCallback();
    Robolectric.getBackgroundThreadScheduler().unPause();
    messageBuilder.reattachCallback(anotherCallback);
    verifyNoMoreInteractions(callback);
    verify(anotherCallback).onMessageBuildSuccess(any(MimeMessage.class), eq(false));
    verifyNoMoreInteractions(anotherCallback);
}
Also used : Callback(com.fsck.k9.message.MessageBuilder.Callback) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Test(org.junit.Test)

Example 5 with MessageBuilder

use of com.fsck.k9.message.MessageBuilder in project k-9 by k9mail.

the class MessageBuilderTest method buildWithException_detachAndReattach_shouldThrow.

@Test
public void buildWithException_detachAndReattach_shouldThrow() throws MessagingException {
    Callback anotherCallback = mock(Callback.class);
    MessageBuilder messageBuilder = new SimpleMessageBuilder(context, messageIdGenerator, boundaryGenerator) {

        @Override
        protected void buildMessageInternal() {
            queueMessageBuildException(new MessagingException("expected error"));
        }
    };
    Robolectric.getBackgroundThreadScheduler().pause();
    messageBuilder.buildAsync(callback);
    messageBuilder.detachCallback();
    Robolectric.getBackgroundThreadScheduler().unPause();
    messageBuilder.reattachCallback(anotherCallback);
    verifyNoMoreInteractions(callback);
    verify(anotherCallback).onMessageBuildException(any(MessagingException.class));
    verifyNoMoreInteractions(anotherCallback);
}
Also used : Callback(com.fsck.k9.message.MessageBuilder.Callback) MessagingException(com.fsck.k9.mail.MessagingException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)5 Attachment (com.fsck.k9.activity.misc.Attachment)2 MessagingException (com.fsck.k9.mail.MessagingException)2 Callback (com.fsck.k9.message.MessageBuilder.Callback)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Parcelable (android.os.Parcelable)1 Nullable (android.support.annotation.Nullable)1 TextWatcher (android.text.TextWatcher)1 TypedValue (android.util.TypedValue)1 ContextThemeWrapper (android.view.ContextThemeWrapper)1 View (android.view.View)1 TextView (android.widget.TextView)1 AttachmentPresenter (com.fsck.k9.activity.compose.AttachmentPresenter)1 AttachmentMvpView (com.fsck.k9.activity.compose.AttachmentPresenter.AttachmentMvpView)1 ComposeCryptoStatus (com.fsck.k9.activity.compose.ComposeCryptoStatus)1 SendErrorState (com.fsck.k9.activity.compose.ComposeCryptoStatus.SendErrorState)1 RecipientMvpView (com.fsck.k9.activity.compose.RecipientMvpView)1