Search in sources :

Example 1 with ServerException

use of com.braintreepayments.api.exceptions.ServerException in project braintree_android by braintree.

the class AnalyticsSenderUnitTest method doesNothingOnAsynchronousErrorResponse.

@Test
public void doesNothingOnAsynchronousErrorResponse() throws Exception {
    AnalyticsEvent one = new AnalyticsEvent(RuntimeEnvironment.application, "sessionId", "custom", "started");
    AnalyticsEvent two = new AnalyticsEvent(RuntimeEnvironment.application, "sessionId", "custom", "finished");
    AnalyticsDatabase database = AnalyticsDatabase.getInstance(RuntimeEnvironment.application);
    database.addEvent(one);
    database.addEvent(two);
    awaitTasksFinished(database);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            ((HttpResponseCallback) invocation.getArguments()[2]).failure(new ServerException(""));
            return null;
        }
    }).when(mHttpClient).post(anyString(), anyString(), any(HttpResponseCallback.class));
    AnalyticsSender.send(RuntimeEnvironment.application, mAuthorization, mHttpClient, "", false);
    List<List<AnalyticsEvent>> pendingEvents = database.getPendingRequests();
    assertEquals(1, pendingEvents.size());
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ServerException(com.braintreepayments.api.exceptions.ServerException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JSONObject(org.json.JSONObject) List(java.util.List) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) Test(org.junit.Test)

Aggregations

ServerException (com.braintreepayments.api.exceptions.ServerException)1 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)1 List (java.util.List)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1