Search in sources :

Example 1 with IdealBank

use of com.braintreepayments.api.models.IdealBank 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);
}
Also used : Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IdealRequest(com.braintreepayments.api.models.IdealRequest) IdealBank(com.braintreepayments.api.models.IdealBank) JSONObject(org.json.JSONObject) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with IdealBank

use of com.braintreepayments.api.models.IdealBank in project braintree_android by braintree.

the class IdealUnitTest method fetchIssuingBanks_postsConfigurationExceptionWhenBraintreeApiNotEnabled.

@Test
public void fetchIssuingBanks_postsConfigurationExceptionWhenBraintreeApiNotEnabled() throws InvalidArgumentException, InterruptedException {
    Configuration configuration = new TestConfigurationBuilder().ideal(new TestIdealConfigurationBuilder().routeId("some-route-id")).buildConfiguration();
    BraintreeFragment fragment = getMockFragment(stringFromFixture("client_token.json"), configuration);
    Ideal.fetchIssuingBanks(fragment, new BraintreeResponseListener<List<IdealBank>>() {

        @Override
        public void onResponse(List<IdealBank> idealBanks) {
            fail("Success listener called");
        }
    });
    ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
    verify(fragment).postCallback(captor.capture());
    Exception e = captor.getValue();
    assertEquals("Your access is restricted and cannot use this part of the Braintree API.", e.getMessage());
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) TestIdealConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder) IdealBank(com.braintreepayments.api.models.IdealBank) List(java.util.List) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) JSONException(org.json.JSONException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with IdealBank

use of com.braintreepayments.api.models.IdealBank 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));
}
Also used : Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IdealRequest(com.braintreepayments.api.models.IdealRequest) IdealBank(com.braintreepayments.api.models.IdealBank) JSONObject(org.json.JSONObject) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) JSONException(org.json.JSONException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with IdealBank

use of com.braintreepayments.api.models.IdealBank in project braintree_android by braintree.

the class IdealUnitTest method fetchIssuingBanks_postsErrorToListenerOnJsonParsingError.

@Test
public void fetchIssuingBanks_postsErrorToListenerOnJsonParsingError() throws InvalidArgumentException {
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[1];
            callback.success("gibberish");
            return null;
        }
    }).when(mMockApiClient).get(eq("/issuers/ideal"), any(HttpResponseCallback.class));
    Ideal.fetchIssuingBanks(mBraintreeFragment, new BraintreeResponseListener<List<IdealBank>>() {

        @Override
        public void onResponse(List<IdealBank> idealBanks) {
            fail("Success listener called");
        }
    });
    verify(mBraintreeFragment).postCallback(any(JSONException.class));
}
Also used : Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IdealBank(com.braintreepayments.api.models.IdealBank) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) List(java.util.List) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with IdealBank

use of com.braintreepayments.api.models.IdealBank in project braintree_android by braintree.

the class IdealUnitTest method startPayment_callsResponseListenerWithPaymentId.

@Test
public void startPayment_callsResponseListenerWithPaymentId() throws InvalidArgumentException, JSONException, InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    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, new BraintreeResponseListener<IdealResult>() {

        @Override
        public void onResponse(IdealResult idealResult) {
            assertEquals("ideal_payment_id", idealResult.getId());
            latch.countDown();
        }
    });
    latch.await();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IdealRequest(com.braintreepayments.api.models.IdealRequest) IdealBank(com.braintreepayments.api.models.IdealBank) JSONObject(org.json.JSONObject) IdealResult(com.braintreepayments.api.models.IdealResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

IdealBank (com.braintreepayments.api.models.IdealBank)14 Test (org.junit.Test)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)9 List (java.util.List)8 JSONObject (org.json.JSONObject)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8 Answer (org.mockito.stubbing.Answer)8 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)8 IdealRequest (com.braintreepayments.api.models.IdealRequest)7 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)5 JSONException (org.json.JSONException)5 IOException (java.io.IOException)4 Configuration (com.braintreepayments.api.models.Configuration)3 IdealResult (com.braintreepayments.api.models.IdealResult)3 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AlertDialog (android.app.AlertDialog)1 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1