Search in sources :

Example 36 with LocalFolder

use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.

the class MessagingControllerTest method refreshRemoteSynchronous_shouldCreateFoldersFromRemote.

@Test
public void refreshRemoteSynchronous_shouldCreateFoldersFromRemote() throws MessagingException {
    configureRemoteStoreWithFolder();
    LocalFolder newLocalFolder = mock(LocalFolder.class);
    List<Folder> folders = Collections.singletonList(remoteFolder);
    when(remoteStore.getPersonalNamespaces(false)).thenAnswer(createAnswer(folders));
    when(remoteFolder.getName()).thenReturn("NewFolder");
    when(localStore.getFolder("NewFolder")).thenReturn(newLocalFolder);
    controller.refreshRemoteSynchronous(account, listener);
    verify(localStore).createFolders(eq(Collections.singletonList(newLocalFolder)), anyInt());
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder) Test(org.junit.Test)

Example 37 with LocalFolder

use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.

the class MessagingControllerTest method synchronizeMailboxSynchronous_withAccountSetToSyncRemoteDeletions_shouldDeleteLocalCopiesOfDeletedMessages.

@Test
public void synchronizeMailboxSynchronous_withAccountSetToSyncRemoteDeletions_shouldDeleteLocalCopiesOfDeletedMessages() throws Exception {
    messageCountInRemoteFolder(0);
    LocalMessage localCopyOfRemoteDeletedMessage = mock(LocalMessage.class);
    when(account.syncRemoteDeletions()).thenReturn(true);
    when(localFolder.getAllMessagesAndEffectiveDates()).thenReturn(Collections.singletonMap(MESSAGE_UID1, 0L));
    when(localFolder.getMessagesByUids(any(List.class))).thenReturn(Collections.singletonList(localCopyOfRemoteDeletedMessage));
    controller.synchronizeMailboxSynchronous(account, FOLDER_NAME, listener, remoteFolder);
    verify(localFolder).destroyMessages(messageListCaptor.capture());
    assertEquals(localCopyOfRemoteDeletedMessage, messageListCaptor.getValue().get(0));
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 38 with LocalFolder

use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.

the class MessagingControllerTest method refreshRemoteSynchronous_shouldDeleteFoldersNotOnRemote.

@Test
public void refreshRemoteSynchronous_shouldDeleteFoldersNotOnRemote() throws MessagingException {
    configureRemoteStoreWithFolder();
    LocalFolder oldLocalFolder = mock(LocalFolder.class);
    when(oldLocalFolder.getName()).thenReturn("OldLocalFolder");
    when(localStore.getPersonalNamespaces(false)).thenReturn(Collections.singletonList(oldLocalFolder));
    List<Folder> folders = Collections.emptyList();
    when(remoteStore.getPersonalNamespaces(false)).thenAnswer(createAnswer(folders));
    controller.refreshRemoteSynchronous(account, listener);
    verify(oldLocalFolder).delete(false);
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder) Test(org.junit.Test)

Example 39 with LocalFolder

use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.

the class MessagingControllerTest method refreshRemoteSynchronous_shouldNotDeleteSpecialFoldersNotOnRemote.

@Test
public void refreshRemoteSynchronous_shouldNotDeleteSpecialFoldersNotOnRemote() throws MessagingException {
    configureRemoteStoreWithFolder();
    LocalFolder missingSpecialFolder = mock(LocalFolder.class);
    when(account.isSpecialFolder("Outbox")).thenReturn(true);
    when(missingSpecialFolder.getName()).thenReturn("Outbox");
    when(localStore.getPersonalNamespaces(false)).thenReturn(Collections.singletonList(missingSpecialFolder));
    List<Folder> folders = Collections.emptyList();
    when(remoteStore.getPersonalNamespaces(false)).thenAnswer(createAnswer(folders));
    controller.refreshRemoteSynchronous(account, listener);
    verify(missingSpecialFolder, never()).delete(false);
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder) Test(org.junit.Test)

Example 40 with LocalFolder

use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.

the class MessagingControllerTest method searchLocalMessagesSynchronous_shouldNotifyWhenStoreFinishesRetrievingAMessage.

@Test
public void searchLocalMessagesSynchronous_shouldNotifyWhenStoreFinishesRetrievingAMessage() throws Exception {
    setAccountsInPreferences(Collections.singletonMap("1", account));
    LocalMessage localMessage = mock(LocalMessage.class);
    when(localMessage.getFolder()).thenReturn(localFolder);
    when(search.getAccountUuids()).thenReturn(new String[] { "allAccounts" });
    when(localStore.searchForMessages(any(MessageRetrievalListener.class), eq(search))).thenThrow(new MessagingException("Test"));
    controller.searchLocalMessagesSynchronous(search, listener);
    verify(localStore).searchForMessages(messageRetrievalListenerCaptor.capture(), eq(search));
    messageRetrievalListenerCaptor.getValue().messageFinished(localMessage, 1, 1);
    verify(listener).listLocalMessagesAddMessages(eq(account), eq((String) null), eq(Collections.singletonList(localMessage)));
}
Also used : LocalMessage(com.fsck.k9.mailstore.LocalMessage) MessagingException(com.fsck.k9.mail.MessagingException) Matchers.anyString(org.mockito.Matchers.anyString) MessageRetrievalListener(com.fsck.k9.mail.MessageRetrievalListener) Test(org.junit.Test)

Aggregations

LocalFolder (com.fsck.k9.mailstore.LocalFolder)41 MessagingException (com.fsck.k9.mail.MessagingException)31 LocalMessage (com.fsck.k9.mailstore.LocalMessage)30 LocalStore (com.fsck.k9.mailstore.LocalStore)28 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)22 Folder (com.fsck.k9.mail.Folder)20 Message (com.fsck.k9.mail.Message)20 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)13 FetchProfile (com.fsck.k9.mail.FetchProfile)12 Store (com.fsck.k9.mail.Store)12 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)12 IOException (java.io.IOException)11 SuppressLint (android.annotation.SuppressLint)10 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)10 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)10 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 Test (org.junit.Test)9 VisibleForTesting (android.support.annotation.VisibleForTesting)5 HashMap (java.util.HashMap)5