Search in sources :

Example 11 with IdealBank

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

the class IdealUnitTest method fetchIssuingBanks_postsCallbackToFragment.

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

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[1];
            callback.failure(new IOException());
            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(IOException.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) JSONObject(org.json.JSONObject) List(java.util.List) IOException(java.io.IOException) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with IdealBank

use of com.braintreepayments.api.models.IdealBank 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();
}
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) JSONObject(org.json.JSONObject) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IdealRequest(com.braintreepayments.api.models.IdealRequest) IdealBank(com.braintreepayments.api.models.IdealBank) JSONObject(org.json.JSONObject) List(java.util.List) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with IdealBank

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

the class IdealTest method fetchIssuingBanks_returnsIssuingBanks.

@Test(timeout = 10000)
public void fetchIssuingBanks_returnsIssuingBanks() throws InterruptedException {
    Ideal.fetchIssuingBanks(mBraintreeFragment, new BraintreeResponseListener<List<IdealBank>>() {

        @Override
        public void onResponse(List<IdealBank> idealBanks) {
            assertFalse(idealBanks.isEmpty());
            assertFalse(TextUtils.isEmpty(idealBanks.get(0).getId()));
            assertFalse(TextUtils.isEmpty(idealBanks.get(0).getName()));
            assertFalse(TextUtils.isEmpty(idealBanks.get(0).getImageUri()));
            mCountDownLatch.countDown();
        }
    });
    mBraintreeFragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            fail(error.getMessage());
        }
    });
    mCountDownLatch.await();
}
Also used : IdealBank(com.braintreepayments.api.models.IdealBank) List(java.util.List) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Test(org.junit.Test)

Example 14 with IdealBank

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

the class IdealActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    IdealBank bank = (IdealBank) mIssuingBanksListView.getAdapter().getItem(position);
    IdealRequest builder = new IdealRequest().issuerId(bank.getId()).amount("10").orderId(UUID.randomUUID().toString()).currency("EUR");
    Ideal.startPayment(mBraintreeFragment, builder, new BraintreeResponseListener<IdealResult>() {

        @Override
        public void onResponse(IdealResult idealResult) {
            String idealId = idealResult.getId();
        }
    });
}
Also used : IdealRequest(com.braintreepayments.api.models.IdealRequest) IdealBank(com.braintreepayments.api.models.IdealBank) IdealResult(com.braintreepayments.api.models.IdealResult)

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