use of com.braintreepayments.api.interfaces.BraintreeErrorListener in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method removeListener_noErrorCallbacksReceived.
@Test
public void removeListener_noErrorCallbacksReceived() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
BraintreeErrorListener listener = new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
fail("Listener was called");
}
};
fragment.addListener(listener);
fragment.removeListener(listener);
fragment.postCallback(new Exception());
fragment.postCallback(new ErrorWithResponse(400, ""));
}
use of com.braintreepayments.api.interfaces.BraintreeErrorListener in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method postCallback_exceptionIsPostedToListeners.
@Test
public void postCallback_exceptionIsPostedToListeners() throws InvalidArgumentException {
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertEquals("Error!", error.getMessage());
mCalled.set(true);
}
});
fragment.postCallback(new Exception("Error!"));
assertTrue(mCalled.get());
}
use of com.braintreepayments.api.interfaces.BraintreeErrorListener 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.interfaces.BraintreeErrorListener in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method postsAnErrorWhenFetchingConfigurationFails.
@Test
public void postsAnErrorWhenFetchingConfigurationFails() throws InvalidArgumentException {
mockConfigurationManager(new Exception("Configuration error"));
BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
final AtomicInteger calls = new AtomicInteger(0);
fragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertEquals("Request for configuration has failed: Configuration error. Future requests will retry up to 3 times", error.getMessage());
calls.getAndIncrement();
}
});
fragment.setConfigurationErrorListener(new BraintreeResponseListener<Exception>() {
@Override
public void onResponse(Exception error) {
assertEquals("Request for configuration has failed: Configuration error. Future requests will retry up to 3 times", error.getMessage());
calls.getAndIncrement();
}
});
assertEquals(2, calls.get());
}
use of com.braintreepayments.api.interfaces.BraintreeErrorListener 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();
}
Aggregations