use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class IdealUnitTest method fetchIssuingBanks_postsErrorToListenerOnJsonParsingError.
@Test
public void fetchIssuingBanks_postsErrorToListenerOnJsonParsingError() throws InvalidArgumentException {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[1];
callback.success("gibberish");
return null;
}
}).when(mMockApiClient).get(eq("/issuers/ideal"), any(HttpResponseCallback.class));
Ideal.fetchIssuingBanks(mBraintreeFragment, new BraintreeResponseListener<List<IdealBank>>() {
@Override
public void onResponse(List<IdealBank> idealBanks) {
fail("Success listener called");
}
});
verify(mBraintreeFragment).postCallback(any(JSONException.class));
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class IdealUnitTest method startPayment_callsResponseListenerWithPaymentId.
@Test
public void startPayment_callsResponseListenerWithPaymentId() throws InvalidArgumentException, JSONException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2];
callback.success(stringFromFixture("payment_methods/pending_ideal_bank_payment.json"));
return null;
}
}).when(mMockApiClient).post(eq("/ideal-payments"), any(String.class), any(HttpResponseCallback.class));
List<IdealBank> banks = IdealBank.fromJson(mConfiguration, stringFromFixture("payment_methods/ideal_issuing_banks.json"));
IdealRequest builder = new IdealRequest().issuerId(banks.get(0).getId()).amount("1.00").currency("EUR").orderId("abc-123");
Ideal.startPayment(mBraintreeFragment, builder, new BraintreeResponseListener<IdealResult>() {
@Override
public void onResponse(IdealResult idealResult) {
assertEquals("ideal_payment_id", idealResult.getId());
latch.countDown();
}
});
latch.await();
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class IdealUnitTest method fetchIssuingBanks_success_sendsAnalyticsEvent.
@Test
public void fetchIssuingBanks_success_sendsAnalyticsEvent() {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[1];
callback.success(stringFromFixture("payment_methods/ideal_issuing_banks.json"));
return null;
}
}).when(mMockApiClient).get(eq("/issuers/ideal"), any(HttpResponseCallback.class));
Ideal.fetchIssuingBanks(mBraintreeFragment, new BraintreeResponseListener<List<IdealBank>>() {
@Override
public void onResponse(List<IdealBank> idealBanks) {
verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.load.succeeded"));
}
});
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class IdealUnitTest method startPayment_success_sendsAnalyticsEvent.
@Test
public void startPayment_success_sendsAnalyticsEvent() throws JSONException {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2];
callback.success(stringFromFixture("payment_methods/pending_ideal_bank_payment.json"));
return null;
}
}).when(mMockApiClient).post(eq("/ideal-payments"), any(String.class), any(HttpResponseCallback.class));
List<IdealBank> banks = IdealBank.fromJson(mConfiguration, stringFromFixture("payment_methods/ideal_issuing_banks.json"));
IdealRequest builder = new IdealRequest().issuerId(banks.get(0).getId()).amount("1.00").currency("EUR").orderId("abc-123");
Ideal.startPayment(mBraintreeFragment, builder, null);
verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.start-payment.selected"));
verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.webswitch.initiate.succeeded"));
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback 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());
}
Aggregations