use of com.braintreepayments.api.exceptions.ErrorWithResponse in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method postCallback_ErrorWithResponseIsPostedToListeners.
@Test
public void postCallback_ErrorWithResponseIsPostedToListeners() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertTrue(error instanceof ErrorWithResponse);
assertEquals(422, ((ErrorWithResponse) error).getStatusCode());
mCalled.set(true);
}
});
fragment.postCallback(new ErrorWithResponse(422, ""));
assertTrue(mCalled.get());
}
use of com.braintreepayments.api.exceptions.ErrorWithResponse in project braintree_android by braintree.
the class UnionPayUnitTest method mockFailureCallback.
private void mockFailureCallback() {
mockStatic(TokenizationClient.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((PaymentMethodNonceCallback) invocation.getArguments()[2]).failure(new ErrorWithResponse(422, ""));
return null;
}
}).when(TokenizationClient.class);
TokenizationClient.tokenize(any(BraintreeFragment.class), any(UnionPayCardBuilder.class), any(PaymentMethodNonceCallback.class));
}
use of com.braintreepayments.api.exceptions.ErrorWithResponse in project braintree_android by braintree.
the class ThreeDSecureAuthenticationResponseUnitTest method getErrors_returnsErrorString.
@Test
public void getErrors_returnsErrorString() {
ThreeDSecureAuthenticationResponse authResponse = ThreeDSecureAuthenticationResponse.fromJson(stringFromFixture("three_d_secure/authentication_response_with_error.json"));
ErrorWithResponse errors = new ErrorWithResponse(0, authResponse.getErrors());
assertNull(authResponse.getCardNonce());
assertFalse(authResponse.isSuccess());
assertEquals("Failed to authenticate, please try a different form of payment", errors.getMessage());
}
use of com.braintreepayments.api.exceptions.ErrorWithResponse in project braintree_android by braintree.
the class CardTest method tokenize_callsErrorCallbackForInvalidPostalCode.
@Test(timeout = 10000)
public void tokenize_callsErrorCallbackForInvalidPostalCode() throws Exception {
CardBuilder cardBuilder = new CardBuilder().cardNumber(VISA).expirationDate("08/20").postalCode("20000");
final CountDownLatch countDownLatch = new CountDownLatch(1);
BraintreeFragment fragment = setupBraintreeFragment(new TestClientTokenBuilder().withPostalCodeVerification().build());
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertEquals("Postal code verification failed", ((ErrorWithResponse) error).errorFor("creditCard").errorFor("billingAddress").getFieldErrors().get(0).getMessage());
countDownLatch.countDown();
}
});
Card.tokenize(fragment, cardBuilder);
countDownLatch.await();
}
use of com.braintreepayments.api.exceptions.ErrorWithResponse in project braintree_android by braintree.
the class BraintreeGraphQLHttpClientTest method parseResponseFailsWithUserErrors.
@Test
public void parseResponseFailsWithUserErrors() throws Exception {
String baseUrl = "http://example.com/graphql";
HttpClient httpClient = new BraintreeGraphQLHttpClient(baseUrl, TOKENIZATION_KEY);
httpClient = HttpClientTestUtils.stubResponse(httpClient, 200, FixturesHelper.stringFromFixture("errors/graphql/credit_card_error.json"));
HttpURLConnection connection = httpClient.init(baseUrl);
try {
httpClient.parseResponse(connection);
fail("No exception was thrown");
} catch (ErrorWithResponse e) {
assertEquals("Input is invalid.", e.getMessage());
assertNotNull(e.errorFor("creditCard"));
}
}
Aggregations