Search in sources :

Example 1 with ConvertAmountAsyncTask

use of com.globalcollect.gateway.sdk.client.android.sdk.asynctask.ConvertAmountAsyncTask in project connect-sdk-client-android by Ingenico-ePayments.

the class GcSession method convertAmount.

/**
 * Converts a given amount in cents from the given source currency to the given target currency
 *
 * @param amount,   the amount in cents to be converted
 * @param source,   source currency
 * @param target,   target currency
 * @param context,  needed for reading metadata
 * @param listener, listener which will be called by the AsyncTask
 */
public void convertAmount(Long amount, String source, String target, Context context, OnAmountConvertedListener listener) {
    if (amount == null) {
        throw new InvalidParameterException("Error converting amount, amount may not be null");
    }
    if (source == null) {
        throw new InvalidParameterException("Error converting amount, source may not be null");
    }
    if (target == null) {
        throw new InvalidParameterException("Error converting amount, target may not be null");
    }
    if (context == null) {
        throw new InvalidParameterException("Error converting amount, context may not be null");
    }
    if (listener == null) {
        throw new InvalidParameterException("Error converting amount, listener may not be null");
    }
    ConvertAmountAsyncTask task = new ConvertAmountAsyncTask(amount, source, target, context, communicator, listener);
    task.execute();
}
Also used : InvalidParameterException(java.security.InvalidParameterException) ConvertAmountAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.ConvertAmountAsyncTask)

Example 2 with ConvertAmountAsyncTask

use of com.globalcollect.gateway.sdk.client.android.sdk.asynctask.ConvertAmountAsyncTask in project connect-sdk-client-android by Ingenico-ePayments.

the class ConvertAmountAsyncTaskTest method testConvertAmountAsyncTaskWithInvalidRequest.

@Test
public void testConvertAmountAsyncTaskWithInvalidRequest() throws InterruptedException {
    initializeInValidMocksAndSession();
    CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
    // Set up the AsyncTask and begin the test by calling execute
    Listener listener = new Listener(waitForAsyncCallBack);
    ConvertAmountAsyncTask convertAmountAsyncTask = new ConvertAmountAsyncTask(1000L, "USD", "EUR", getContext(), getCommunicator(), listener);
    convertAmountAsyncTask.execute();
    // Test that the response is received within 'ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC' seconds
    assertTrue(waitForAsyncCallBack.await(ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
    // Retrieve the response from the listener and test that it is not null
    assertNull(listener.getConvertedAmount());
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ConvertAmountAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.ConvertAmountAsyncTask) Test(org.junit.Test)

Example 3 with ConvertAmountAsyncTask

use of com.globalcollect.gateway.sdk.client.android.sdk.asynctask.ConvertAmountAsyncTask in project connect-sdk-client-android by Ingenico-ePayments.

the class ConvertAmountAsyncTaskTest method testConvertAmountAsyncTaskWithValidRequest.

@Test
public void testConvertAmountAsyncTaskWithValidRequest() throws InterruptedException, CommunicationException {
    initializeValidMocksAndSession();
    CountDownLatch waitForAsyncCallBack = new CountDownLatch(1);
    // Set up the AsyncTask and begin the test by calling execute
    Listener listener = new Listener(waitForAsyncCallBack);
    ConvertAmountAsyncTask convertAmountAsyncTask = new ConvertAmountAsyncTask(1000L, "USD", "EUR", getContext(), getCommunicator(), listener);
    convertAmountAsyncTask.execute();
    // Test that the response is received within 'ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC' seconds
    assertTrue(waitForAsyncCallBack.await(ASYNCTASK_CALLBACK_TEST_TIMEOUT_SEC, TimeUnit.SECONDS));
    // Retrieve the response from the listener and test that it is not null
    assertNotNull(listener.getConvertedAmount());
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) ConvertAmountAsyncTask(com.globalcollect.gateway.sdk.client.android.sdk.asynctask.ConvertAmountAsyncTask) Test(org.junit.Test)

Aggregations

ConvertAmountAsyncTask (com.globalcollect.gateway.sdk.client.android.sdk.asynctask.ConvertAmountAsyncTask)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Test (org.junit.Test)2 InvalidParameterException (java.security.InvalidParameterException)1