use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class MessagePreviewCreatorTest method createPreview_withEmptyTextPart.
@Test
public void createPreview_withEmptyTextPart() throws Exception {
Message message = createDummyMessage();
Part textPart = createEmptyPart("text/plain");
when(encryptionDetector.isEncrypted(message)).thenReturn(false);
when(textPartFinder.findFirstTextPart(message)).thenReturn(textPart);
PreviewResult result = previewCreator.createPreview(message);
assertFalse(result.isPreviewTextAvailable());
assertEquals(PreviewType.NONE, result.getPreviewType());
verifyNoMoreInteractions(previewTextExtractor);
}
use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class MessagePreviewCreatorTest method createPreview_withPreviewTextExtractorThrowing.
@Test
public void createPreview_withPreviewTextExtractorThrowing() throws Exception {
Message message = createDummyMessage();
Part textPart = createTextPart("text/plain");
when(encryptionDetector.isEncrypted(message)).thenReturn(false);
when(textPartFinder.findFirstTextPart(message)).thenReturn(textPart);
when(previewTextExtractor.extractPreview(textPart)).thenThrow(new PreviewExtractionException(""));
PreviewResult result = previewCreator.createPreview(message);
assertFalse(result.isPreviewTextAvailable());
assertEquals(PreviewType.ERROR, result.getPreviewType());
}
use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class NewMailNotificationsTest method testRemoveNewMailNotification.
@Test
public void testRemoveNewMailNotification() throws Exception {
enablePrivacyMode();
MessageReference messageReference = createMessageReference(1);
int notificationIndex = 0;
int notificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);
LocalMessage message = createLocalMessage();
NotificationContent content = createNotificationContent();
NotificationHolder holder = createNotificationHolder(content, notificationIndex);
addToNotificationContentCreator(message, content);
whenAddingContentReturn(content, AddNotificationResult.newNotification(holder));
Notification summaryNotification = createNotification();
addToDeviceNotifications(summaryNotification);
newMailNotifications.addNewMailNotification(account, message, 23);
whenRemovingContentReturn(messageReference, RemoveNotificationResult.cancelNotification(notificationId));
newMailNotifications.removeNewMailNotification(account, messageReference);
int summaryNotificationId = NotificationIds.getNewMailSummaryNotificationId(account);
verify(notificationManager).cancel(notificationId);
verify(notificationManager, times(2)).notify(summaryNotificationId, summaryNotification);
}
use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class NewMailNotificationsTest method testAddNewMailNotificationWithCancelingExistingNotification.
@Test
public void testAddNewMailNotificationWithCancelingExistingNotification() throws Exception {
int notificationIndex = 0;
LocalMessage message = createLocalMessage();
NotificationContent content = createNotificationContent();
NotificationHolder holder = createNotificationHolder(content, notificationIndex);
addToNotificationContentCreator(message, content);
whenAddingContentReturn(content, AddNotificationResult.replaceNotification(holder));
Notification wearNotification = createNotification();
Notification summaryNotification = createNotification();
addToWearNotifications(holder, wearNotification);
addToDeviceNotifications(summaryNotification);
newMailNotifications.addNewMailNotification(account, message, 42);
int wearNotificationId = NotificationIds.getNewMailStackedNotificationId(account, notificationIndex);
int summaryNotificationId = NotificationIds.getNewMailSummaryNotificationId(account);
verify(notificationManager).notify(wearNotificationId, wearNotification);
verify(notificationManager).cancel(wearNotificationId);
verify(notificationManager).notify(summaryNotificationId, summaryNotification);
}
use of com.fsck.k9.mail.Message in project k-9 by k9mail.
the class NotificationContentCreatorTest method createFakeLocalMessage.
private LocalMessage createFakeLocalMessage(MessageReference messageReference) throws Exception {
LocalMessage message = mock(LocalMessage.class);
when(message.makeMessageReference()).thenReturn(messageReference);
when(message.getPreviewType()).thenReturn(PreviewType.TEXT);
when(message.getPreview()).thenReturn(PREVIEW);
when(message.getSubject()).thenReturn(SUBJECT);
when(message.getFrom()).thenReturn(new Address[] { new Address(SENDER_ADDRESS, SENDER_NAME) });
when(message.getRecipients(RecipientType.TO)).thenReturn(new Address[] { new Address(RECIPIENT_ADDRESS, RECIPIENT_NAME) });
return message;
}
Aggregations