use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class IdealUnitTest method startPayment_startsBrowserWithProperRequestCode.
@Test
public void startPayment_startsBrowserWithProperRequestCode() throws InterruptedException, InvalidArgumentException {
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/ideal_issuing_banks.json"));
return null;
}
}).when(mMockApiClient).get(eq("/issuers/ideal"), any(HttpResponseCallback.class));
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
String requestBody = (String) invocation.getArguments()[1];
JSONObject json = new JSONObject(requestBody);
assertEquals("some-route-id", json.getString("route_id"));
String expectedRedirectUrl = Uri.parse("http://assets.example.com/mobile/ideal-redirect/0.0.0/index.html?redirect_url=" + mBraintreeFragment.getReturnUrlScheme() + "://").toString();
assertEquals(expectedRedirectUrl, json.getString("redirect_url"));
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));
Ideal.fetchIssuingBanks(mBraintreeFragment, new BraintreeResponseListener<List<IdealBank>>() {
@Override
public void onResponse(List<IdealBank> idealBanks) {
IdealBank bank = idealBanks.get(0);
IdealRequest builder = new IdealRequest().issuerId(bank.getId()).amount("1.00").currency("EUR").orderId("abc-123");
Ideal.startPayment(mBraintreeFragment, builder, null);
verify(mBraintreeFragment).browserSwitch(eq(BraintreeRequestCodes.IDEAL), eq("http://approval.example.com/"));
latch.countDown();
}
});
latch.await();
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class ConfigurationManagerUnitTest method getConfiguration_callsErrorListenerWhenHttpFails.
@Test(timeout = 1000)
public void getConfiguration_callsErrorListenerWhenHttpFails() throws InterruptedException {
BraintreeHttpClient fakeClient = new BraintreeHttpClient(mTokenizationKey) {
@Override
public void get(String path, HttpResponseCallback callback) {
if (path.contains(mTokenizationKey.getConfigUrl())) {
callback.failure(new UnexpectedException("Something bad happened"));
}
}
};
when(mBraintreeFragment.getHttpClient()).thenReturn(fakeClient);
ConfigurationManager.getConfiguration(mBraintreeFragment, new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
fail("Success listener should not have been called for bad request");
}
}, new BraintreeResponseListener<Exception>() {
@Override
public void onResponse(Exception e) {
assertTrue(e instanceof UnexpectedException);
assertEquals("Something bad happened", e.getMessage());
mCountDownLatch.countDown();
}
});
mCountDownLatch.await();
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class MockFragmentBuilder method setupGraphQLErrorResponses.
private void setupGraphQLErrorResponses(BraintreeGraphQLHttpClient graphQLHttpClient) {
Answer answer = new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((HttpResponseCallback) invocation.getArguments()[1]).failure(mGraphQLErrorResponse);
return null;
}
};
doAnswer(answer).when(graphQLHttpClient).get(any(String.class), any(HttpResponseCallback.class));
doAnswer(answer).when(graphQLHttpClient).post(anyString(), anyString(), any(HttpResponseCallback.class));
doAnswer(answer).when(graphQLHttpClient).post(anyString(), any(HttpResponseCallback.class));
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class MockFragmentBuilder method setupGraphQLSuccessResponses.
private void setupGraphQLSuccessResponses(BraintreeGraphQLHttpClient graphQLHttpClient) {
Answer answer = new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((HttpResponseCallback) invocation.getArguments()[1]).success(mGraphQLSuccessResponse);
return null;
}
};
doAnswer(answer).when(graphQLHttpClient).get(any(String.class), any(HttpResponseCallback.class));
doAnswer(answer).when(graphQLHttpClient).post(anyString(), anyString(), any(HttpResponseCallback.class));
doAnswer(answer).when(graphQLHttpClient).post(anyString(), any(HttpResponseCallback.class));
}
use of com.braintreepayments.api.interfaces.HttpResponseCallback in project braintree_android by braintree.
the class MockFragmentBuilder method setupErrorResponses.
private void setupErrorResponses(BraintreeHttpClient httpClient) {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((HttpResponseCallback) invocation.getArguments()[1]).failure(mErrorResponse);
return null;
}
}).when(httpClient).get(any(String.class), any(HttpResponseCallback.class));
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
((HttpResponseCallback) invocation.getArguments()[2]).failure(mErrorResponse);
return null;
}
}).when(httpClient).post(anyString(), anyString(), any(HttpResponseCallback.class));
}
Aggregations