use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class IdealUnitTest method fetchIssuingBanks_failure_sendsAnalyticsEvent.
@Test
public void fetchIssuingBanks_failure_sendsAnalyticsEvent() {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[1];
callback.failure(new IOException());
return null;
}
}).when(mMockApiClient).get(eq("/issuers/ideal"), any(HttpResponseCallback.class));
Ideal.fetchIssuingBanks(mBraintreeFragment, null);
verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.load.failed"));
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class IdealUnitTest method startPayment_persistsIdealResultId.
@Test
public void startPayment_persistsIdealResultId() throws InvalidArgumentException, 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);
String idealResultId = getResultIdFromPrefs();
assertEquals("ideal_payment_id", idealResultId);
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class IdealUnitTest method onActivityResult_returnsResultToFragment.
@Test
public void onActivityResult_returnsResultToFragment() throws InvalidArgumentException, JSONException, InterruptedException {
putResultIdInPrefs("ideal_payment_id");
final CountDownLatch latch = new CountDownLatch(1);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[1];
callback.success(stringFromFixture("payment_methods/completed_ideal_bank_payment.json"));
latch.countDown();
return null;
}
}).when(mMockApiClient).get(eq("/ideal-payments/ideal_payment_id/status"), any(HttpResponseCallback.class));
Ideal.onActivityResult(mBraintreeFragment, Activity.RESULT_OK);
latch.await();
ArgumentCaptor<IdealResult> captor = ArgumentCaptor.forClass(IdealResult.class);
verify(mBraintreeFragment).postCallback(captor.capture());
IdealResult capturedResult = captor.getValue();
assertEquals("ideal_payment_id", capturedResult.getId());
assertEquals("short_id", capturedResult.getShortId());
assertEquals("COMPLETE", capturedResult.getStatus());
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class IdealUnitTest method startPayment_callsExceptionListenerOnJsonParsingError.
@Test
public void startPayment_callsExceptionListenerOnJsonParsingError() throws InvalidArgumentException, JSONException, InterruptedException {
putResultIdInPrefs("ideal_payment_id");
final CountDownLatch latch = new CountDownLatch(1);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[1];
callback.success("gibberish");
latch.countDown();
return null;
}
}).when(mMockApiClient).get(eq("/ideal-payments/ideal_payment_id/status"), any(HttpResponseCallback.class));
Ideal.onActivityResult(mBraintreeFragment, Activity.RESULT_OK);
latch.await();
verify(mBraintreeFragment).postCallback(any(JSONException.class));
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class IdealUnitTest method startPayment_callsExceptionListenerOnHttpError.
@Test
public void startPayment_callsExceptionListenerOnHttpError() throws InvalidArgumentException, JSONException {
final Exception expectedException = new Exception();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2];
callback.failure(expectedException);
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).postCallback(eq(expectedException));
}
Aggregations