-
Notifications
You must be signed in to change notification settings - Fork 9
HW-51321: Get paypal account #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fmattos-hw
merged 6 commits into
feature/HW-51227-paypal-account
from
feature/HW-51321_Get_paypal_account
May 3, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c719430
HW-51321: Get paypal account
vshcherbyna-epam f0c5799
test optimization
vshcherbyna-epam 5dd0ef1
Adding required properties to pom file
fmattos-hw 0275ec0
Version update and exempt maven local publish task from signing
fmattos-hw afca671
HW-51321: Get paypal account
vshcherbyna-epam 97dd003
revert unneeded changes
vshcherbyna-epam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
core/src/test/java/com/hyperwallet/android/transfermethod/HyperwalletGetPayPalTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| package com.hyperwallet.android.transfermethod; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.hamcrest.CoreMatchers.notNullValue; | ||
| import static org.hamcrest.CoreMatchers.nullValue; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.hasSize; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| import static com.hyperwallet.android.model.HyperwalletStatusTransition.StatusDefinition.ACTIVATED; | ||
| import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.CREATED_ON; | ||
| import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.EMAIL; | ||
| import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.STATUS; | ||
| import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TOKEN; | ||
| import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_COUNTRY; | ||
| import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_CURRENCY; | ||
| import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.TYPE; | ||
| import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT; | ||
|
|
||
| import com.hyperwallet.android.Hyperwallet; | ||
| import com.hyperwallet.android.exception.HyperwalletException; | ||
| import com.hyperwallet.android.listener.HyperwalletListener; | ||
| import com.hyperwallet.android.model.HyperwalletError; | ||
| import com.hyperwallet.android.model.HyperwalletErrors; | ||
| import com.hyperwallet.android.model.PayPalAccount; | ||
| import com.hyperwallet.android.rule.HyperwalletExternalResourceManager; | ||
| import com.hyperwallet.android.rule.HyperwalletMockWebServer; | ||
| import com.hyperwallet.android.rule.HyperwalletSdkMock; | ||
|
|
||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.mockito.Captor; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.MockitoJUnit; | ||
| import org.mockito.junit.MockitoRule; | ||
| import org.robolectric.RobolectricTestRunner; | ||
|
|
||
| import java.net.HttpURLConnection; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import okhttp3.mockwebserver.RecordedRequest; | ||
|
|
||
| @RunWith(RobolectricTestRunner.class) | ||
| public class HyperwalletGetPayPalTest { | ||
| @Rule | ||
| public HyperwalletMockWebServer mServer = new HyperwalletMockWebServer(); | ||
| @Rule | ||
| public HyperwalletSdkMock mSdkMock = new HyperwalletSdkMock(mServer); | ||
| @Rule | ||
| public HyperwalletExternalResourceManager mExternalResourceManager = new HyperwalletExternalResourceManager(); | ||
| @Rule | ||
| public MockitoRule mMockito = MockitoJUnit.rule(); | ||
|
|
||
| @Mock | ||
| private HyperwalletListener<PayPalAccount> mListener; | ||
| @Captor | ||
| private ArgumentCaptor<PayPalAccount> mPayPalAccountArgumentCaptor; | ||
| @Captor | ||
| private ArgumentCaptor<HyperwalletException> mExceptionCaptor; | ||
|
|
||
| private final CountDownLatch mAwait = new CountDownLatch(1); | ||
| private static final long COUNTDOWN_TIMEOUT_MILLIS = 100L; | ||
|
|
||
| @Test | ||
| public void testGetGetPayPalAccount_returnsAccount() throws InterruptedException { | ||
|
|
||
| String responseBody = mExternalResourceManager.getResourceContent("paypal_account_response.json"); | ||
| mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_OK).withBody(responseBody).mock(); | ||
|
|
||
| Hyperwallet.getDefault().getPayPalAccount("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b", mListener); | ||
| mAwait.await(COUNTDOWN_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); | ||
|
|
||
| RecordedRequest recordedRequest = mServer.getRequest(); | ||
| assertThat(recordedRequest.getPath(), | ||
| is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-ac5727ac-8fe7-42fb" | ||
| + "-b69d-977ebdd7b48b")); | ||
|
|
||
| verify(mListener).onSuccess(mPayPalAccountArgumentCaptor.capture()); | ||
| verify(mListener, never()).onFailure(any(HyperwalletException.class)); | ||
|
|
||
| PayPalAccount payPalAccountResponse = mPayPalAccountArgumentCaptor.getValue(); | ||
| assertThat(payPalAccountResponse, is(notNullValue())); | ||
| assertThat(payPalAccountResponse.getField(TYPE), is(PAYPAL_ACCOUNT)); | ||
| assertThat(payPalAccountResponse.getField(TOKEN), is("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b")); | ||
| assertThat(payPalAccountResponse.getField(STATUS), is(ACTIVATED)); | ||
|
|
||
| assertThat(payPalAccountResponse.getField(CREATED_ON), is("2019-01-09T22:50:14")); | ||
| assertThat(payPalAccountResponse.getField(TRANSFER_METHOD_COUNTRY), is("US")); | ||
| assertThat(payPalAccountResponse.getField(TRANSFER_METHOD_CURRENCY), is("USD")); | ||
| assertThat(payPalAccountResponse.getField(EMAIL), is("jsmith@paypal.com")); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void testGetGetPayPalAccount_returnsNoAccount() throws InterruptedException { | ||
|
|
||
| String responseBody = ""; | ||
| mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_NO_CONTENT).withBody(responseBody).mock(); | ||
|
|
||
| Hyperwallet.getDefault().getPayPalAccount("trm-ac5727ac-8fe7-42fb-b69d-977ebdd7b48b", mListener); | ||
| mAwait.await(COUNTDOWN_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); | ||
|
|
||
| RecordedRequest recordedRequest = mServer.getRequest(); | ||
| assertThat(recordedRequest.getPath(), | ||
| is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-ac5727ac-8fe7-42fb" | ||
| + "-b69d-977ebdd7b48b")); | ||
|
|
||
| verify(mListener).onSuccess(mPayPalAccountArgumentCaptor.capture()); | ||
| verify(mListener, never()).onFailure(any(HyperwalletException.class)); | ||
|
|
||
| PayPalAccount payPalAccount = mPayPalAccountArgumentCaptor.getValue(); | ||
| assertThat(payPalAccount, is(nullValue())); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetGetPayPalAccount_returnsError() throws InterruptedException { | ||
|
|
||
| String responseBody = mExternalResourceManager.getResourceContentError("system_error_response.json"); | ||
| mServer.mockResponse().withHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST).withBody(responseBody).mock(); | ||
|
|
||
| Hyperwallet.getDefault().getPayPalAccount("trm-854c4ec1-9161-49d6-92e2-b8d15aa4bf56", mListener); | ||
| mAwait.await(COUNTDOWN_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); | ||
|
|
||
| RecordedRequest recordedRequest = mServer.getRequest(); | ||
| assertThat(recordedRequest.getPath(), | ||
| is("/rest/v3/users/usr-fbfd5848-60d0-43c5-8462-099c959b49c7/paypal-accounts/trm-854c4ec1-9161-49d6-92e2" | ||
| + "-b8d15aa4bf56")); | ||
|
|
||
| verify(mListener, never()).onSuccess(any(PayPalAccount.class)); | ||
| verify(mListener).onFailure(mExceptionCaptor.capture()); | ||
|
|
||
| HyperwalletException exception = mExceptionCaptor.getValue(); | ||
| assertThat(exception, is(notNullValue())); | ||
| HyperwalletErrors errors = exception.getHyperwalletErrors(); | ||
| assertThat(errors, is(notNullValue())); | ||
| assertThat(errors.getErrors(), hasSize(1)); | ||
|
|
||
| HyperwalletError error = errors.getErrors().get(0); | ||
| assertThat(error.getCode(), is("SYSTEM_ERROR")); | ||
| assertThat(error.getMessage(), | ||
| is("A system error has occurred. Please try again. If you continue to receive this error, please " | ||
| + "contact customer support for assistance (Ref ID: 99b4ad5c-4aac-4cc2-aa9b-4b4f4844ac9b).")); | ||
|
|
||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.