use of com.braintreepayments.api.exceptions.InvalidArgumentException 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.exceptions.InvalidArgumentException 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.exceptions.InvalidArgumentException 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.InvalidArgumentException 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.exceptions.InvalidArgumentException in project braintree_android by braintree.
the class ConfigurationManagerUnitTest method getConfiguration_takesClientTokenIntoAccountForCache.
@Test(timeout = 1000)
public void getConfiguration_takesClientTokenIntoAccountForCache() throws InvalidArgumentException, InterruptedException {
ClientToken clientToken = (ClientToken) Authorization.fromString(stringFromFixture("client_token_with_authorization_fingerprint_options.json"));
when(mBraintreeFragment.getAuthorization()).thenReturn(clientToken);
writeMockConfiguration(RuntimeEnvironment.application, clientToken.getConfigUrl(), clientToken.getAuthorizationFingerprint(), stringFromFixture("configuration/configuration.json"), System.currentTimeMillis());
ConfigurationManager.getConfiguration(mBraintreeFragment, new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
assertEquals(stringFromFixture("configuration/configuration.json"), configuration.toJson());
mCountDownLatch.countDown();
}
}, new BraintreeResponseListener<Exception>() {
@Override
public void onResponse(Exception e) {
fail(e.getMessage());
}
});
mCountDownLatch.await();
}
Aggregations