Search in sources :

Example 56 with FetchProfile

use of com.fsck.k9.mail.FetchProfile in project k-9 by k9mail.

the class WebDavFolderTest method folder_can_fetch_more_than_20_flags.

@Test
public void folder_can_fetch_more_than_20_flags() throws MessagingException {
    when(mockStore.processRequest(anyString(), anyString(), anyString(), anyMap())).thenReturn(mockDataSet);
    List<WebDavMessage> messages = new ArrayList<>();
    for (int i = 0; i < 25; i++) {
        WebDavMessage mockMessage = createWebDavMessage(i);
        messages.add(mockMessage);
    }
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.FLAGS);
    folder.fetch(messages, profile, listener, MAX_DOWNLOAD_SIZE);
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 57 with FetchProfile

use of com.fsck.k9.mail.FetchProfile in project k-9 by k9mail.

the class WebDavFolderTest method folder_can_fetch_sensible_body_data_and_notifies_listener.

@Test
public void folder_can_fetch_sensible_body_data_and_notifies_listener() throws MessagingException, IOException, URISyntaxException {
    setupStoreForMessageFetching();
    List<WebDavMessage> messages = setup25MessagesToFetch();
    when(mockHttpClient.executeOverride(any(HttpUriRequest.class), nullable(HttpContext.class))).thenAnswer(new Answer<HttpResponse>() {

        @Override
        public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
            HttpResponse httpResponse = mock(HttpResponse.class);
            StatusLine statusLine = mock(StatusLine.class);
            when(httpResponse.getStatusLine()).thenReturn(statusLine);
            when(statusLine.getStatusCode()).thenReturn(200);
            BasicHttpEntity httpEntity = new BasicHttpEntity();
            String body = "";
            httpEntity.setContent(new ByteArrayInputStream(body.getBytes("UTF-8")));
            when(httpResponse.getEntity()).thenReturn(httpEntity);
            return httpResponse;
        }
    });
    FetchProfile profile = new FetchProfile();
    profile.add(FetchProfile.Item.BODY_SANE);
    folder.fetch(messages, profile, listener, MAX_DOWNLOAD_SIZE);
    verify(listener, times(25)).messageStarted(any(String.class), anyInt(), eq(25));
    verify(listener, times(25)).messageFinished(any(WebDavMessage.class), anyInt(), eq(25));
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) FetchProfile(com.fsck.k9.mail.FetchProfile) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StatusLine(org.apache.http.StatusLine) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Aggregations

FetchProfile (com.fsck.k9.mail.FetchProfile)49 Test (org.junit.Test)27 LocalMessage (com.fsck.k9.mailstore.LocalMessage)15 MessagingException (com.fsck.k9.mail.MessagingException)12 ArrayList (java.util.ArrayList)10 LocalFolder (com.fsck.k9.mailstore.LocalFolder)9 LocalStore (com.fsck.k9.mailstore.LocalStore)9 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)8 Date (java.util.Date)8 Message (com.fsck.k9.mail.Message)7 SuppressLint (android.annotation.SuppressLint)6 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)6 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)5 Multipart (com.fsck.k9.mail.Multipart)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 WebDavMessage (com.fsck.k9.mail.store.webdav.WebDavMessage)4 LinkedList (java.util.LinkedList)4 HttpResponse (org.apache.http.HttpResponse)4 StatusLine (org.apache.http.StatusLine)4