From 169175c344bdd573cc695474063e3d9156bd3a13 Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Fri, 3 May 2019 15:00:00 +0300 Subject: [PATCH 01/24] HW-52030 Added User Repository --- .../android/ui/repository/UserRepository.java | 35 ++++ .../ui/repository/UserRepositoryImpl.java | 42 +++++ .../ui/repository/UserRepositoryImplTest.java | 175 ++++++++++++++++++ 3 files changed, 252 insertions(+) create mode 100644 ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java create mode 100644 ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java create mode 100644 ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java new file mode 100644 index 000000000..ace444050 --- /dev/null +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java @@ -0,0 +1,35 @@ +package com.hyperwallet.android.ui.repository; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.hyperwallet.android.model.HyperwalletErrors; +import com.hyperwallet.android.model.HyperwalletUser; + +/** + * User Repository Contract + */ +public interface UserRepository { + /** + * Load user information + * + * @param callback @see {@link UserRepository.LoadUserCallback} + */ + void loadUser(@NonNull final LoadUserCallback callback); + + /** + * Callback interface that responses to action when invoked to + * Load User information + *

+ * When User is properly loaded + * {@link UserRepository.LoadUserCallback#onUserLoaded(HyperwalletUser)} + * is invoked otherwise {@link UserRepository.LoadUserCallback#onError(HyperwalletErrors)} + * is called to further log or show error information + */ + interface LoadUserCallback { + + void onUserLoaded(@Nullable final HyperwalletUser user); + + void onError(@NonNull final HyperwalletErrors errors); + } +} diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java new file mode 100644 index 000000000..1ab9ed466 --- /dev/null +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java @@ -0,0 +1,42 @@ +package com.hyperwallet.android.ui.repository; + +import android.os.Handler; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; + +import com.hyperwallet.android.Hyperwallet; +import com.hyperwallet.android.exception.HyperwalletException; +import com.hyperwallet.android.listener.HyperwalletListener; +import com.hyperwallet.android.model.HyperwalletUser; + +public class UserRepositoryImpl implements UserRepository { + + private Handler mHandler = new Handler(); + + @VisibleForTesting + Hyperwallet getHyperwallet() { + return Hyperwallet.getDefault(); + } + + @Override + public void loadUser(@NonNull final LoadUserCallback callback) { + getHyperwallet().getUser(new HyperwalletListener() { + @Override + public void onSuccess(@Nullable HyperwalletUser result) { + callback.onUserLoaded(result); + } + + @Override + public void onFailure(HyperwalletException exception) { + callback.onError(exception.getHyperwalletErrors()); + } + + @Override + public Handler getHandler() { + return mHandler; + } + }); + } +} diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java new file mode 100644 index 000000000..e17ac2858 --- /dev/null +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -0,0 +1,175 @@ +package com.hyperwallet.android.ui.repository; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.nullValue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import static com.hyperwallet.android.model.HyperwalletUser.ProfileTypes.INDIVIDUAL; +import static com.hyperwallet.android.model.HyperwalletUser.UserFields.CLIENT_USER_ID; +import static com.hyperwallet.android.model.HyperwalletUser.UserFields.CREATED_ON; +import static com.hyperwallet.android.model.HyperwalletUser.UserFields.PROFILE_TYPE; +import static com.hyperwallet.android.model.HyperwalletUser.UserFields.STATUS; +import static com.hyperwallet.android.model.HyperwalletUser.UserFields.TOKEN; +import static com.hyperwallet.android.model.HyperwalletUser.UserFields.VERIFICATION_STATUS; +import static com.hyperwallet.android.model.HyperwalletUser.UserStatuses.PRE_ACTIVATED; +import static com.hyperwallet.android.model.HyperwalletUser.VerificationStatuses.NOT_REQUIRED; + +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.HyperwalletUser; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.ArgumentMatchers; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.mockito.stubbing.Answer; +import org.robolectric.RobolectricTestRunner; + +import java.util.ArrayList; +import java.util.List; + +@RunWith(RobolectricTestRunner.class) +public class UserRepositoryImplTest { + @Mock + private Hyperwallet mHyperwallet; + @Captor + private ArgumentCaptor mErrorCaptor; + @Captor + private ArgumentCaptor mUserCaptor; + @Rule + public MockitoRule mMockito = MockitoJUnit.rule(); + @Spy + UserRepositoryImpl mUserRepository; + + @Before + public void setup() { + doReturn(mHyperwallet).when(mUserRepository).getHyperwallet(); + } + + @Test + public void testLoadUser_returnValidData() { + HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); + final HyperwalletUser user = builder + .token("usr-f9154016-94e8-4686-a840-075688ac07b5") + .status(PRE_ACTIVATED) + .verificationStatus(NOT_REQUIRED) + .createdOn("2017-10-30T22:15:45") + .clientUserId("CSK7b8Ffch") + .profileType(INDIVIDUAL) + .firstName("Some") + .lastName("Guy") + .dateOfBirth("1991-01-01") + .email("testUser@hyperwallet.com") + .addressLine1("575 Market Street") + .city("San Francisco") + .stateProvince("CA") + .country("US") + .postalCode("94105") + .language("en") + .programToken("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c") + .build(); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[0]; + listener.onSuccess(user); + return listener; + } + }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); + UserRepository.LoadUserCallback mockCallback = mock(UserRepository.LoadUserCallback.class); + + mUserRepository.loadUser(mockCallback); + + verify(mockCallback).onUserLoaded(mUserCaptor.capture()); + verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); + + HyperwalletUser resultUser = mUserCaptor.getValue(); + assertThat(user.getField(TOKEN), is("usr-f9154016-94e8-4686-a840-075688ac07b5")); + assertThat(user.getField(STATUS), is(PRE_ACTIVATED)); + assertThat(user.getField(VERIFICATION_STATUS), is(NOT_REQUIRED)); + assertThat(user.getField(CREATED_ON), is("2017-10-30T22:15:45")); + assertThat(user.getField(CLIENT_USER_ID), is("CSK7b8Ffch")); + assertThat(user.getField(PROFILE_TYPE), is(INDIVIDUAL)); + assertThat(user.getField(HyperwalletUser.UserFields.FIRST_NAME), is("Some")); + assertThat(user.getField(HyperwalletUser.UserFields.LAST_NAME), is("Guy")); + assertThat(user.getField(HyperwalletUser.UserFields.DATE_OF_BIRTH), is("1991-01-01")); + assertThat(user.getField(HyperwalletUser.UserFields.EMAIL), is("testUser@hyperwallet.com")); + assertThat(user.getField(HyperwalletUser.UserFields.ADDRESS_LINE_1), is("575 Market Street")); + assertThat(user.getField(HyperwalletUser.UserFields.CITY), is("San Francisco")); + assertThat(user.getField(HyperwalletUser.UserFields.STATE_PROVINCE), is("CA")); + assertThat(user.getField(HyperwalletUser.UserFields.COUNTRY), is("US")); + assertThat(user.getField(HyperwalletUser.UserFields.POSTAL_CODE), is("94105")); + assertThat(user.getField(HyperwalletUser.UserFields.LANGUAGE), is("en")); + assertThat(user.getField(HyperwalletUser.UserFields.PROGRAM_TOKEN), + is("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c")); + } + + @Test + public void testLoadUser_returnEmptyUserData() { + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[0]; + listener.onSuccess(null); + return listener; + } + }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); + UserRepository.LoadUserCallback mockCallback = mock(UserRepository.LoadUserCallback.class); + + mUserRepository.loadUser(mockCallback); + + verify(mockCallback).onUserLoaded(mUserCaptor.capture()); + verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); + + HyperwalletUser user = mUserCaptor.getValue(); + assertThat(user, is(nullValue())); + } + + + @Test + public void testLoadUser_returnErrors() { + + final HyperwalletError error = new HyperwalletError("test message", "TEST_CODE"); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[0]; + List errorList = new ArrayList<>(); + errorList.add(error); + HyperwalletErrors errors = new HyperwalletErrors(errorList); + listener.onFailure(new HyperwalletException(errors)); + return listener; + } + }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); + UserRepository.LoadUserCallback mockCallback = mock( + UserRepository.LoadUserCallback.class); + + mUserRepository.loadUser(mockCallback); + + verify(mockCallback, never()).onUserLoaded(ArgumentMatchers.any()); + verify(mockCallback).onError(mErrorCaptor.capture()); + + assertThat(mErrorCaptor.getValue().getErrors(), hasItem(error)); + } +} From 23f6c25d77dc51f1c784fe83b04e30f4e3023eff Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Mon, 6 May 2019 10:47:10 +0300 Subject: [PATCH 02/24] HW-52030. Added User member --- .../ui/repository/RepositoryFactory.java | 6 +++ .../ui/repository/UserRepositoryImpl.java | 38 +++++++++++-------- .../ui/repository/UserRepositoryImplTest.java | 34 ++++++++--------- 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/RepositoryFactory.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/RepositoryFactory.java index ee5b44ea3..ec2a3a935 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/RepositoryFactory.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/RepositoryFactory.java @@ -31,10 +31,12 @@ public class RepositoryFactory { private static RepositoryFactory sInstance; private TransferMethodConfigurationRepository mTransferMethodConfigurationRepository; private TransferMethodRepository mTransferMethodRepository; + private UserRepository mUserRepository; private RepositoryFactory() { mTransferMethodConfigurationRepository = new TransferMethodConfigurationRepositoryImpl(); mTransferMethodRepository = new TransferMethodRepositoryImpl(); + mUserRepository = new UserRepositoryImpl(); } public static synchronized RepositoryFactory getInstance() { @@ -52,6 +54,10 @@ public TransferMethodRepository getTransferMethodRepository() { return mTransferMethodRepository; } + public UserRepository getUserRepository() { + return mUserRepository; + } + public static void clearInstance() { sInstance = null; } diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java index 1ab9ed466..99eef282b 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java @@ -14,6 +14,7 @@ public class UserRepositoryImpl implements UserRepository { private Handler mHandler = new Handler(); + private HyperwalletUser mUser; @VisibleForTesting Hyperwallet getHyperwallet() { @@ -22,21 +23,26 @@ Hyperwallet getHyperwallet() { @Override public void loadUser(@NonNull final LoadUserCallback callback) { - getHyperwallet().getUser(new HyperwalletListener() { - @Override - public void onSuccess(@Nullable HyperwalletUser result) { - callback.onUserLoaded(result); - } - - @Override - public void onFailure(HyperwalletException exception) { - callback.onError(exception.getHyperwalletErrors()); - } - - @Override - public Handler getHandler() { - return mHandler; - } - }); + if (mUser == null) { + getHyperwallet().getUser(new HyperwalletListener() { + @Override + public void onSuccess(@Nullable HyperwalletUser result) { + mUser = result; + callback.onUserLoaded(mUser); + } + + @Override + public void onFailure(HyperwalletException exception) { + callback.onError(exception.getHyperwalletErrors()); + } + + @Override + public Handler getHandler() { + return mHandler; + } + }); + } else { + callback.onUserLoaded(mUser); + } } } diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java index e17ac2858..7110593b5 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -103,23 +103,23 @@ public Object answer(InvocationOnMock invocation) { verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); HyperwalletUser resultUser = mUserCaptor.getValue(); - assertThat(user.getField(TOKEN), is("usr-f9154016-94e8-4686-a840-075688ac07b5")); - assertThat(user.getField(STATUS), is(PRE_ACTIVATED)); - assertThat(user.getField(VERIFICATION_STATUS), is(NOT_REQUIRED)); - assertThat(user.getField(CREATED_ON), is("2017-10-30T22:15:45")); - assertThat(user.getField(CLIENT_USER_ID), is("CSK7b8Ffch")); - assertThat(user.getField(PROFILE_TYPE), is(INDIVIDUAL)); - assertThat(user.getField(HyperwalletUser.UserFields.FIRST_NAME), is("Some")); - assertThat(user.getField(HyperwalletUser.UserFields.LAST_NAME), is("Guy")); - assertThat(user.getField(HyperwalletUser.UserFields.DATE_OF_BIRTH), is("1991-01-01")); - assertThat(user.getField(HyperwalletUser.UserFields.EMAIL), is("testUser@hyperwallet.com")); - assertThat(user.getField(HyperwalletUser.UserFields.ADDRESS_LINE_1), is("575 Market Street")); - assertThat(user.getField(HyperwalletUser.UserFields.CITY), is("San Francisco")); - assertThat(user.getField(HyperwalletUser.UserFields.STATE_PROVINCE), is("CA")); - assertThat(user.getField(HyperwalletUser.UserFields.COUNTRY), is("US")); - assertThat(user.getField(HyperwalletUser.UserFields.POSTAL_CODE), is("94105")); - assertThat(user.getField(HyperwalletUser.UserFields.LANGUAGE), is("en")); - assertThat(user.getField(HyperwalletUser.UserFields.PROGRAM_TOKEN), + assertThat(resultUser.getField(TOKEN), is("usr-f9154016-94e8-4686-a840-075688ac07b5")); + assertThat(resultUser.getField(STATUS), is(PRE_ACTIVATED)); + assertThat(resultUser.getField(VERIFICATION_STATUS), is(NOT_REQUIRED)); + assertThat(resultUser.getField(CREATED_ON), is("2017-10-30T22:15:45")); + assertThat(resultUser.getField(CLIENT_USER_ID), is("CSK7b8Ffch")); + assertThat(resultUser.getField(PROFILE_TYPE), is(INDIVIDUAL)); + assertThat(resultUser.getField(HyperwalletUser.UserFields.FIRST_NAME), is("Some")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.LAST_NAME), is("Guy")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.DATE_OF_BIRTH), is("1991-01-01")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.EMAIL), is("testUser@hyperwallet.com")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.ADDRESS_LINE_1), is("575 Market Street")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.CITY), is("San Francisco")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.STATE_PROVINCE), is("CA")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.COUNTRY), is("US")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.POSTAL_CODE), is("94105")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.LANGUAGE), is("en")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.PROGRAM_TOKEN), is("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c")); } From bc20273debc4b9634d8fa2920dfdb67a5ec52b17 Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Tue, 7 May 2019 12:09:01 +0300 Subject: [PATCH 03/24] HW-52030. Added user refresh --- .../android/ui/repository/UserRepository.java | 5 +++ .../ui/repository/UserRepositoryImpl.java | 5 +++ .../ui/repository/UserRepositoryImplTest.java | 33 +++++++++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java index ace444050..b338b7aff 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java @@ -17,6 +17,11 @@ public interface UserRepository { */ void loadUser(@NonNull final LoadUserCallback callback); + /** + * Set user to null + */ + void refreshUser(); + /** * Callback interface that responses to action when invoked to * Load User information diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java index 99eef282b..7d25bd000 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java @@ -45,4 +45,9 @@ public Handler getHandler() { callback.onUserLoaded(mUser); } } + + @Override + public void refreshUser() { + mUser = null; + } } diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java index 7110593b5..9611ef126 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -9,6 +9,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static com.hyperwallet.android.model.HyperwalletUser.ProfileTypes.INDIVIDUAL; @@ -72,7 +73,7 @@ public void testLoadUser_returnValidData() { .status(PRE_ACTIVATED) .verificationStatus(NOT_REQUIRED) .createdOn("2017-10-30T22:15:45") - .clientUserId("CSK7b8Ffch") + .clientUserId("123456") .profileType(INDIVIDUAL) .firstName("Some") .lastName("Guy") @@ -107,7 +108,7 @@ public Object answer(InvocationOnMock invocation) { assertThat(resultUser.getField(STATUS), is(PRE_ACTIVATED)); assertThat(resultUser.getField(VERIFICATION_STATUS), is(NOT_REQUIRED)); assertThat(resultUser.getField(CREATED_ON), is("2017-10-30T22:15:45")); - assertThat(resultUser.getField(CLIENT_USER_ID), is("CSK7b8Ffch")); + assertThat(resultUser.getField(CLIENT_USER_ID), is("123456")); assertThat(resultUser.getField(PROFILE_TYPE), is(INDIVIDUAL)); assertThat(resultUser.getField(HyperwalletUser.UserFields.FIRST_NAME), is("Some")); assertThat(resultUser.getField(HyperwalletUser.UserFields.LAST_NAME), is("Guy")); @@ -172,4 +173,32 @@ public Object answer(InvocationOnMock invocation) { assertThat(mErrorCaptor.getValue().getErrors(), hasItem(error)); } + + @Test + public void testRefreshUser_callsGetUserAfterRefresh() { + HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); + final HyperwalletUser user = builder.build(); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[0]; + listener.onSuccess(user); + return listener; + } + }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); + UserRepository.LoadUserCallback mockCallback = mock(UserRepository.LoadUserCallback.class); + + mUserRepository.loadUser(mockCallback); + verify(mHyperwallet).getUser(any(HyperwalletListener.class)); + verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); + + mUserRepository.loadUser(mockCallback); + verify(mHyperwallet).getUser(any(HyperwalletListener.class)); + + mUserRepository.refreshUser(); + mUserRepository.loadUser(mockCallback); + verify(mHyperwallet, times(2)).getUser(any(HyperwalletListener.class)); + } + } From 3630e41679211b1a6eef6a9a7249f645ac30cf00 Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Fri, 10 May 2019 10:27:06 +0300 Subject: [PATCH 04/24] HW-52030 Small fixes after review (license & test renaming) --- .../android/ui/repository/UserRepository.java | 27 +++++++++++++++ .../ui/repository/UserRepositoryImpl.java | 27 +++++++++++++++ .../ui/repository/UserRepositoryImplTest.java | 33 ++----------------- 3 files changed, 56 insertions(+), 31 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java index b338b7aff..fc933bf8e 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java @@ -1,3 +1,30 @@ +/* + * Copyright 2018 Hyperwallet + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO + * EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + package com.hyperwallet.android.ui.repository; import androidx.annotation.NonNull; diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java index 7d25bd000..3619e1fff 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java @@ -1,3 +1,30 @@ +/* + * Copyright 2018 Hyperwallet + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO + * EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + package com.hyperwallet.android.ui.repository; import android.os.Handler; diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java index 9611ef126..3137e2250 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -9,7 +9,6 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static com.hyperwallet.android.model.HyperwalletUser.ProfileTypes.INDIVIDUAL; @@ -125,7 +124,7 @@ public Object answer(InvocationOnMock invocation) { } @Test - public void testLoadUser_returnEmptyUserData() { + public void testLoadUser_returnsNoUser() { doAnswer(new Answer() { @Override @@ -148,7 +147,7 @@ public Object answer(InvocationOnMock invocation) { @Test - public void testLoadUser_returnErrors() { + public void testLoadUser_withError() { final HyperwalletError error = new HyperwalletError("test message", "TEST_CODE"); @@ -173,32 +172,4 @@ public Object answer(InvocationOnMock invocation) { assertThat(mErrorCaptor.getValue().getErrors(), hasItem(error)); } - - @Test - public void testRefreshUser_callsGetUserAfterRefresh() { - HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); - final HyperwalletUser user = builder.build(); - - doAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocation) { - HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[0]; - listener.onSuccess(user); - return listener; - } - }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); - UserRepository.LoadUserCallback mockCallback = mock(UserRepository.LoadUserCallback.class); - - mUserRepository.loadUser(mockCallback); - verify(mHyperwallet).getUser(any(HyperwalletListener.class)); - verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); - - mUserRepository.loadUser(mockCallback); - verify(mHyperwallet).getUser(any(HyperwalletListener.class)); - - mUserRepository.refreshUser(); - mUserRepository.loadUser(mockCallback); - verify(mHyperwallet, times(2)).getUser(any(HyperwalletListener.class)); - } - } From f31e1c09569d295443d0dfc9c01074c956ef7849 Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Fri, 10 May 2019 11:29:16 +0300 Subject: [PATCH 05/24] HW-52030 Added refresh user test --- .../ui/repository/UserRepositoryImplTest.java | 73 +++++++++++++------ 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java index 3137e2250..68f474bf2 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -9,15 +9,10 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static com.hyperwallet.android.model.HyperwalletUser.ProfileTypes.INDIVIDUAL; -import static com.hyperwallet.android.model.HyperwalletUser.UserFields.CLIENT_USER_ID; -import static com.hyperwallet.android.model.HyperwalletUser.UserFields.CREATED_ON; -import static com.hyperwallet.android.model.HyperwalletUser.UserFields.PROFILE_TYPE; -import static com.hyperwallet.android.model.HyperwalletUser.UserFields.STATUS; -import static com.hyperwallet.android.model.HyperwalletUser.UserFields.TOKEN; -import static com.hyperwallet.android.model.HyperwalletUser.UserFields.VERIFICATION_STATUS; import static com.hyperwallet.android.model.HyperwalletUser.UserStatuses.PRE_ACTIVATED; import static com.hyperwallet.android.model.HyperwalletUser.VerificationStatuses.NOT_REQUIRED; @@ -103,24 +98,23 @@ public Object answer(InvocationOnMock invocation) { verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); HyperwalletUser resultUser = mUserCaptor.getValue(); - assertThat(resultUser.getField(TOKEN), is("usr-f9154016-94e8-4686-a840-075688ac07b5")); - assertThat(resultUser.getField(STATUS), is(PRE_ACTIVATED)); - assertThat(resultUser.getField(VERIFICATION_STATUS), is(NOT_REQUIRED)); - assertThat(resultUser.getField(CREATED_ON), is("2017-10-30T22:15:45")); - assertThat(resultUser.getField(CLIENT_USER_ID), is("123456")); - assertThat(resultUser.getField(PROFILE_TYPE), is(INDIVIDUAL)); - assertThat(resultUser.getField(HyperwalletUser.UserFields.FIRST_NAME), is("Some")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.LAST_NAME), is("Guy")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.DATE_OF_BIRTH), is("1991-01-01")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.EMAIL), is("testUser@hyperwallet.com")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.ADDRESS_LINE_1), is("575 Market Street")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.CITY), is("San Francisco")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.STATE_PROVINCE), is("CA")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.COUNTRY), is("US")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.POSTAL_CODE), is("94105")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.LANGUAGE), is("en")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.PROGRAM_TOKEN), - is("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c")); + assertThat(resultUser.getToken(), is("usr-f9154016-94e8-4686-a840-075688ac07b5")); + assertThat(resultUser.getStatus(), is(PRE_ACTIVATED)); + assertThat(resultUser.getVerificationStatus(), is(NOT_REQUIRED)); + assertThat(resultUser.getCreatedOn(), is("2017-10-30T22:15:45")); + assertThat(resultUser.getClientUserId(), is("123456")); + assertThat(resultUser.getProfileType(), is(INDIVIDUAL)); + assertThat(resultUser.getFirstName(), is("Some")); + assertThat(resultUser.getLastName(), is("Guy")); + assertThat(resultUser.getDateOfBirth(), is("1991-01-01")); + assertThat(resultUser.getEmail(), is("testUser@hyperwallet.com")); + assertThat(resultUser.getAddressLine1(), is("575 Market Street")); + assertThat(resultUser.getCity(), is("San Francisco")); + assertThat(resultUser.getStateProvince(), is("CA")); + assertThat(resultUser.getCountry(), is("US")); + assertThat(resultUser.getPostalCode(), is("94105")); + assertThat(resultUser.getLanguage(), is("en")); + assertThat(resultUser.getProgramToken(), is("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c")); } @Test @@ -172,4 +166,35 @@ public Object answer(InvocationOnMock invocation) { assertThat(mErrorCaptor.getValue().getErrors(), hasItem(error)); } + + @Test + public void testRefreshUser_checkHypervaletCallGetUser() { + HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); + final HyperwalletUser user = builder + .token("usr-f9154016-94e8-4686-a840-075688ac07b5") + .profileType(INDIVIDUAL) + .build(); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[0]; + listener.onSuccess(user); + return listener; + } + }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); + UserRepository.LoadUserCallback mockCallback = mock(UserRepository.LoadUserCallback.class); + + mUserRepository.loadUser(mockCallback); + + verify(mHyperwallet).getUser(ArgumentMatchers.>any()); + + mUserRepository.loadUser(mockCallback); + verify(mHyperwallet).getUser(ArgumentMatchers.>any()); + + mUserRepository.refreshUser(); + mUserRepository.loadUser(mockCallback); + verify(mHyperwallet, times(2)).getUser(ArgumentMatchers.>any()); + + } } From ee8cbd5e8f45e76c3a870c2d784f2cb8aa62b3a5 Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Fri, 10 May 2019 11:42:02 +0300 Subject: [PATCH 06/24] HW-52030. Fixed typo --- .../android/ui/repository/UserRepositoryImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java index 68f474bf2..79669cf89 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -168,7 +168,7 @@ public Object answer(InvocationOnMock invocation) { } @Test - public void testRefreshUser_checkHypervaletCallGetUser() { + public void testRefreshUser_checkHyperwalletCallGetUser() { HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); final HyperwalletUser user = builder .token("usr-f9154016-94e8-4686-a840-075688ac07b5") From fdc130d9789ec2fb763b841c943abd42a08803c3 Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Fri, 10 May 2019 15:35:51 -0700 Subject: [PATCH 07/24] update agreement --- .../android/ui/repository/UserRepository.java | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java index fc933bf8e..8ee119fa8 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java @@ -1,28 +1,19 @@ /* * Copyright 2018 Hyperwallet * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated - * documentation files (the "Software"), to deal in the Software without restriction, including - * without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of * the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO - * EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ package com.hyperwallet.android.ui.repository; From 70badbdbb5b27194c047139570582241bf37ceea Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Fri, 10 May 2019 15:36:13 -0700 Subject: [PATCH 08/24] update agreement --- .../ui/repository/UserRepositoryImpl.java | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java index 3619e1fff..561d4cf85 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java @@ -1,28 +1,19 @@ /* * Copyright 2018 Hyperwallet * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated - * documentation files (the "Software"), to deal in the Software without restriction, including - * without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of * the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO - * EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ package com.hyperwallet.android.ui.repository; From bda1289122be22aae25d495e9a722ea1b4c0fe3b Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Fri, 10 May 2019 15:50:06 -0700 Subject: [PATCH 09/24] renaming tests --- .../android/ui/repository/UserRepositoryImplTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java index 79669cf89..5d97211f8 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -60,7 +60,7 @@ public void setup() { } @Test - public void testLoadUser_returnValidData() { + public void testLoadUser_returnsUser() { HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); final HyperwalletUser user = builder .token("usr-f9154016-94e8-4686-a840-075688ac07b5") @@ -168,7 +168,7 @@ public Object answer(InvocationOnMock invocation) { } @Test - public void testRefreshUser_checkHyperwalletCallGetUser() { + public void testRefreshUser_verifyHyperwalletCallGetUser() { HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); final HyperwalletUser user = builder .token("usr-f9154016-94e8-4686-a840-075688ac07b5") From 32062a689e82bab5dbed9ccd347fc1dd9c025369 Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Fri, 3 May 2019 15:00:00 +0300 Subject: [PATCH 10/24] HW-52030 Added User Repository --- .../android/ui/repository/UserRepository.java | 35 ++++ .../ui/repository/UserRepositoryImpl.java | 42 +++++ .../ui/repository/UserRepositoryImplTest.java | 175 ++++++++++++++++++ 3 files changed, 252 insertions(+) create mode 100644 ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java create mode 100644 ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java create mode 100644 ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java new file mode 100644 index 000000000..ace444050 --- /dev/null +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java @@ -0,0 +1,35 @@ +package com.hyperwallet.android.ui.repository; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.hyperwallet.android.model.HyperwalletErrors; +import com.hyperwallet.android.model.HyperwalletUser; + +/** + * User Repository Contract + */ +public interface UserRepository { + /** + * Load user information + * + * @param callback @see {@link UserRepository.LoadUserCallback} + */ + void loadUser(@NonNull final LoadUserCallback callback); + + /** + * Callback interface that responses to action when invoked to + * Load User information + *

+ * When User is properly loaded + * {@link UserRepository.LoadUserCallback#onUserLoaded(HyperwalletUser)} + * is invoked otherwise {@link UserRepository.LoadUserCallback#onError(HyperwalletErrors)} + * is called to further log or show error information + */ + interface LoadUserCallback { + + void onUserLoaded(@Nullable final HyperwalletUser user); + + void onError(@NonNull final HyperwalletErrors errors); + } +} diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java new file mode 100644 index 000000000..1ab9ed466 --- /dev/null +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java @@ -0,0 +1,42 @@ +package com.hyperwallet.android.ui.repository; + +import android.os.Handler; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; + +import com.hyperwallet.android.Hyperwallet; +import com.hyperwallet.android.exception.HyperwalletException; +import com.hyperwallet.android.listener.HyperwalletListener; +import com.hyperwallet.android.model.HyperwalletUser; + +public class UserRepositoryImpl implements UserRepository { + + private Handler mHandler = new Handler(); + + @VisibleForTesting + Hyperwallet getHyperwallet() { + return Hyperwallet.getDefault(); + } + + @Override + public void loadUser(@NonNull final LoadUserCallback callback) { + getHyperwallet().getUser(new HyperwalletListener() { + @Override + public void onSuccess(@Nullable HyperwalletUser result) { + callback.onUserLoaded(result); + } + + @Override + public void onFailure(HyperwalletException exception) { + callback.onError(exception.getHyperwalletErrors()); + } + + @Override + public Handler getHandler() { + return mHandler; + } + }); + } +} diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java new file mode 100644 index 000000000..e17ac2858 --- /dev/null +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -0,0 +1,175 @@ +package com.hyperwallet.android.ui.repository; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.nullValue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import static com.hyperwallet.android.model.HyperwalletUser.ProfileTypes.INDIVIDUAL; +import static com.hyperwallet.android.model.HyperwalletUser.UserFields.CLIENT_USER_ID; +import static com.hyperwallet.android.model.HyperwalletUser.UserFields.CREATED_ON; +import static com.hyperwallet.android.model.HyperwalletUser.UserFields.PROFILE_TYPE; +import static com.hyperwallet.android.model.HyperwalletUser.UserFields.STATUS; +import static com.hyperwallet.android.model.HyperwalletUser.UserFields.TOKEN; +import static com.hyperwallet.android.model.HyperwalletUser.UserFields.VERIFICATION_STATUS; +import static com.hyperwallet.android.model.HyperwalletUser.UserStatuses.PRE_ACTIVATED; +import static com.hyperwallet.android.model.HyperwalletUser.VerificationStatuses.NOT_REQUIRED; + +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.HyperwalletUser; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.ArgumentMatchers; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; +import org.mockito.stubbing.Answer; +import org.robolectric.RobolectricTestRunner; + +import java.util.ArrayList; +import java.util.List; + +@RunWith(RobolectricTestRunner.class) +public class UserRepositoryImplTest { + @Mock + private Hyperwallet mHyperwallet; + @Captor + private ArgumentCaptor mErrorCaptor; + @Captor + private ArgumentCaptor mUserCaptor; + @Rule + public MockitoRule mMockito = MockitoJUnit.rule(); + @Spy + UserRepositoryImpl mUserRepository; + + @Before + public void setup() { + doReturn(mHyperwallet).when(mUserRepository).getHyperwallet(); + } + + @Test + public void testLoadUser_returnValidData() { + HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); + final HyperwalletUser user = builder + .token("usr-f9154016-94e8-4686-a840-075688ac07b5") + .status(PRE_ACTIVATED) + .verificationStatus(NOT_REQUIRED) + .createdOn("2017-10-30T22:15:45") + .clientUserId("CSK7b8Ffch") + .profileType(INDIVIDUAL) + .firstName("Some") + .lastName("Guy") + .dateOfBirth("1991-01-01") + .email("testUser@hyperwallet.com") + .addressLine1("575 Market Street") + .city("San Francisco") + .stateProvince("CA") + .country("US") + .postalCode("94105") + .language("en") + .programToken("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c") + .build(); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[0]; + listener.onSuccess(user); + return listener; + } + }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); + UserRepository.LoadUserCallback mockCallback = mock(UserRepository.LoadUserCallback.class); + + mUserRepository.loadUser(mockCallback); + + verify(mockCallback).onUserLoaded(mUserCaptor.capture()); + verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); + + HyperwalletUser resultUser = mUserCaptor.getValue(); + assertThat(user.getField(TOKEN), is("usr-f9154016-94e8-4686-a840-075688ac07b5")); + assertThat(user.getField(STATUS), is(PRE_ACTIVATED)); + assertThat(user.getField(VERIFICATION_STATUS), is(NOT_REQUIRED)); + assertThat(user.getField(CREATED_ON), is("2017-10-30T22:15:45")); + assertThat(user.getField(CLIENT_USER_ID), is("CSK7b8Ffch")); + assertThat(user.getField(PROFILE_TYPE), is(INDIVIDUAL)); + assertThat(user.getField(HyperwalletUser.UserFields.FIRST_NAME), is("Some")); + assertThat(user.getField(HyperwalletUser.UserFields.LAST_NAME), is("Guy")); + assertThat(user.getField(HyperwalletUser.UserFields.DATE_OF_BIRTH), is("1991-01-01")); + assertThat(user.getField(HyperwalletUser.UserFields.EMAIL), is("testUser@hyperwallet.com")); + assertThat(user.getField(HyperwalletUser.UserFields.ADDRESS_LINE_1), is("575 Market Street")); + assertThat(user.getField(HyperwalletUser.UserFields.CITY), is("San Francisco")); + assertThat(user.getField(HyperwalletUser.UserFields.STATE_PROVINCE), is("CA")); + assertThat(user.getField(HyperwalletUser.UserFields.COUNTRY), is("US")); + assertThat(user.getField(HyperwalletUser.UserFields.POSTAL_CODE), is("94105")); + assertThat(user.getField(HyperwalletUser.UserFields.LANGUAGE), is("en")); + assertThat(user.getField(HyperwalletUser.UserFields.PROGRAM_TOKEN), + is("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c")); + } + + @Test + public void testLoadUser_returnEmptyUserData() { + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[0]; + listener.onSuccess(null); + return listener; + } + }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); + UserRepository.LoadUserCallback mockCallback = mock(UserRepository.LoadUserCallback.class); + + mUserRepository.loadUser(mockCallback); + + verify(mockCallback).onUserLoaded(mUserCaptor.capture()); + verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); + + HyperwalletUser user = mUserCaptor.getValue(); + assertThat(user, is(nullValue())); + } + + + @Test + public void testLoadUser_returnErrors() { + + final HyperwalletError error = new HyperwalletError("test message", "TEST_CODE"); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[0]; + List errorList = new ArrayList<>(); + errorList.add(error); + HyperwalletErrors errors = new HyperwalletErrors(errorList); + listener.onFailure(new HyperwalletException(errors)); + return listener; + } + }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); + UserRepository.LoadUserCallback mockCallback = mock( + UserRepository.LoadUserCallback.class); + + mUserRepository.loadUser(mockCallback); + + verify(mockCallback, never()).onUserLoaded(ArgumentMatchers.any()); + verify(mockCallback).onError(mErrorCaptor.capture()); + + assertThat(mErrorCaptor.getValue().getErrors(), hasItem(error)); + } +} From b0106b72f42e13163478c2094144db70fd7162f9 Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Mon, 6 May 2019 10:47:10 +0300 Subject: [PATCH 11/24] HW-52030. Added User member --- .../ui/repository/RepositoryFactory.java | 6 +++ .../ui/repository/UserRepositoryImpl.java | 38 +++++++++++-------- .../ui/repository/UserRepositoryImplTest.java | 34 ++++++++--------- 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/RepositoryFactory.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/RepositoryFactory.java index ee5b44ea3..ec2a3a935 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/RepositoryFactory.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/RepositoryFactory.java @@ -31,10 +31,12 @@ public class RepositoryFactory { private static RepositoryFactory sInstance; private TransferMethodConfigurationRepository mTransferMethodConfigurationRepository; private TransferMethodRepository mTransferMethodRepository; + private UserRepository mUserRepository; private RepositoryFactory() { mTransferMethodConfigurationRepository = new TransferMethodConfigurationRepositoryImpl(); mTransferMethodRepository = new TransferMethodRepositoryImpl(); + mUserRepository = new UserRepositoryImpl(); } public static synchronized RepositoryFactory getInstance() { @@ -52,6 +54,10 @@ public TransferMethodRepository getTransferMethodRepository() { return mTransferMethodRepository; } + public UserRepository getUserRepository() { + return mUserRepository; + } + public static void clearInstance() { sInstance = null; } diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java index 1ab9ed466..99eef282b 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java @@ -14,6 +14,7 @@ public class UserRepositoryImpl implements UserRepository { private Handler mHandler = new Handler(); + private HyperwalletUser mUser; @VisibleForTesting Hyperwallet getHyperwallet() { @@ -22,21 +23,26 @@ Hyperwallet getHyperwallet() { @Override public void loadUser(@NonNull final LoadUserCallback callback) { - getHyperwallet().getUser(new HyperwalletListener() { - @Override - public void onSuccess(@Nullable HyperwalletUser result) { - callback.onUserLoaded(result); - } - - @Override - public void onFailure(HyperwalletException exception) { - callback.onError(exception.getHyperwalletErrors()); - } - - @Override - public Handler getHandler() { - return mHandler; - } - }); + if (mUser == null) { + getHyperwallet().getUser(new HyperwalletListener() { + @Override + public void onSuccess(@Nullable HyperwalletUser result) { + mUser = result; + callback.onUserLoaded(mUser); + } + + @Override + public void onFailure(HyperwalletException exception) { + callback.onError(exception.getHyperwalletErrors()); + } + + @Override + public Handler getHandler() { + return mHandler; + } + }); + } else { + callback.onUserLoaded(mUser); + } } } diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java index e17ac2858..7110593b5 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -103,23 +103,23 @@ public Object answer(InvocationOnMock invocation) { verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); HyperwalletUser resultUser = mUserCaptor.getValue(); - assertThat(user.getField(TOKEN), is("usr-f9154016-94e8-4686-a840-075688ac07b5")); - assertThat(user.getField(STATUS), is(PRE_ACTIVATED)); - assertThat(user.getField(VERIFICATION_STATUS), is(NOT_REQUIRED)); - assertThat(user.getField(CREATED_ON), is("2017-10-30T22:15:45")); - assertThat(user.getField(CLIENT_USER_ID), is("CSK7b8Ffch")); - assertThat(user.getField(PROFILE_TYPE), is(INDIVIDUAL)); - assertThat(user.getField(HyperwalletUser.UserFields.FIRST_NAME), is("Some")); - assertThat(user.getField(HyperwalletUser.UserFields.LAST_NAME), is("Guy")); - assertThat(user.getField(HyperwalletUser.UserFields.DATE_OF_BIRTH), is("1991-01-01")); - assertThat(user.getField(HyperwalletUser.UserFields.EMAIL), is("testUser@hyperwallet.com")); - assertThat(user.getField(HyperwalletUser.UserFields.ADDRESS_LINE_1), is("575 Market Street")); - assertThat(user.getField(HyperwalletUser.UserFields.CITY), is("San Francisco")); - assertThat(user.getField(HyperwalletUser.UserFields.STATE_PROVINCE), is("CA")); - assertThat(user.getField(HyperwalletUser.UserFields.COUNTRY), is("US")); - assertThat(user.getField(HyperwalletUser.UserFields.POSTAL_CODE), is("94105")); - assertThat(user.getField(HyperwalletUser.UserFields.LANGUAGE), is("en")); - assertThat(user.getField(HyperwalletUser.UserFields.PROGRAM_TOKEN), + assertThat(resultUser.getField(TOKEN), is("usr-f9154016-94e8-4686-a840-075688ac07b5")); + assertThat(resultUser.getField(STATUS), is(PRE_ACTIVATED)); + assertThat(resultUser.getField(VERIFICATION_STATUS), is(NOT_REQUIRED)); + assertThat(resultUser.getField(CREATED_ON), is("2017-10-30T22:15:45")); + assertThat(resultUser.getField(CLIENT_USER_ID), is("CSK7b8Ffch")); + assertThat(resultUser.getField(PROFILE_TYPE), is(INDIVIDUAL)); + assertThat(resultUser.getField(HyperwalletUser.UserFields.FIRST_NAME), is("Some")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.LAST_NAME), is("Guy")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.DATE_OF_BIRTH), is("1991-01-01")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.EMAIL), is("testUser@hyperwallet.com")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.ADDRESS_LINE_1), is("575 Market Street")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.CITY), is("San Francisco")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.STATE_PROVINCE), is("CA")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.COUNTRY), is("US")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.POSTAL_CODE), is("94105")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.LANGUAGE), is("en")); + assertThat(resultUser.getField(HyperwalletUser.UserFields.PROGRAM_TOKEN), is("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c")); } From 2694fb26c2336e10a1671f036e1c06da8b70d9fc Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Tue, 7 May 2019 12:09:01 +0300 Subject: [PATCH 12/24] HW-52030. Added user refresh --- .../android/ui/repository/UserRepository.java | 5 +++ .../ui/repository/UserRepositoryImpl.java | 5 +++ .../ui/repository/UserRepositoryImplTest.java | 33 +++++++++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java index ace444050..b338b7aff 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java @@ -17,6 +17,11 @@ public interface UserRepository { */ void loadUser(@NonNull final LoadUserCallback callback); + /** + * Set user to null + */ + void refreshUser(); + /** * Callback interface that responses to action when invoked to * Load User information diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java index 99eef282b..7d25bd000 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java @@ -45,4 +45,9 @@ public Handler getHandler() { callback.onUserLoaded(mUser); } } + + @Override + public void refreshUser() { + mUser = null; + } } diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java index 7110593b5..9611ef126 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -9,6 +9,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static com.hyperwallet.android.model.HyperwalletUser.ProfileTypes.INDIVIDUAL; @@ -72,7 +73,7 @@ public void testLoadUser_returnValidData() { .status(PRE_ACTIVATED) .verificationStatus(NOT_REQUIRED) .createdOn("2017-10-30T22:15:45") - .clientUserId("CSK7b8Ffch") + .clientUserId("123456") .profileType(INDIVIDUAL) .firstName("Some") .lastName("Guy") @@ -107,7 +108,7 @@ public Object answer(InvocationOnMock invocation) { assertThat(resultUser.getField(STATUS), is(PRE_ACTIVATED)); assertThat(resultUser.getField(VERIFICATION_STATUS), is(NOT_REQUIRED)); assertThat(resultUser.getField(CREATED_ON), is("2017-10-30T22:15:45")); - assertThat(resultUser.getField(CLIENT_USER_ID), is("CSK7b8Ffch")); + assertThat(resultUser.getField(CLIENT_USER_ID), is("123456")); assertThat(resultUser.getField(PROFILE_TYPE), is(INDIVIDUAL)); assertThat(resultUser.getField(HyperwalletUser.UserFields.FIRST_NAME), is("Some")); assertThat(resultUser.getField(HyperwalletUser.UserFields.LAST_NAME), is("Guy")); @@ -172,4 +173,32 @@ public Object answer(InvocationOnMock invocation) { assertThat(mErrorCaptor.getValue().getErrors(), hasItem(error)); } + + @Test + public void testRefreshUser_callsGetUserAfterRefresh() { + HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); + final HyperwalletUser user = builder.build(); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[0]; + listener.onSuccess(user); + return listener; + } + }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); + UserRepository.LoadUserCallback mockCallback = mock(UserRepository.LoadUserCallback.class); + + mUserRepository.loadUser(mockCallback); + verify(mHyperwallet).getUser(any(HyperwalletListener.class)); + verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); + + mUserRepository.loadUser(mockCallback); + verify(mHyperwallet).getUser(any(HyperwalletListener.class)); + + mUserRepository.refreshUser(); + mUserRepository.loadUser(mockCallback); + verify(mHyperwallet, times(2)).getUser(any(HyperwalletListener.class)); + } + } From 02ea8cb1d116a70d2685e142875f912f666ddd74 Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Fri, 10 May 2019 10:27:06 +0300 Subject: [PATCH 13/24] HW-52030 Small fixes after review (license & test renaming) --- .../android/ui/repository/UserRepository.java | 27 +++++++++++++++ .../ui/repository/UserRepositoryImpl.java | 27 +++++++++++++++ .../ui/repository/UserRepositoryImplTest.java | 33 ++----------------- 3 files changed, 56 insertions(+), 31 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java index b338b7aff..fc933bf8e 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java @@ -1,3 +1,30 @@ +/* + * Copyright 2018 Hyperwallet + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO + * EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + package com.hyperwallet.android.ui.repository; import androidx.annotation.NonNull; diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java index 7d25bd000..3619e1fff 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java @@ -1,3 +1,30 @@ +/* + * Copyright 2018 Hyperwallet + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated + * documentation files (the "Software"), to deal in the Software without restriction, including + * without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO + * EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + package com.hyperwallet.android.ui.repository; import android.os.Handler; diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java index 9611ef126..3137e2250 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -9,7 +9,6 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static com.hyperwallet.android.model.HyperwalletUser.ProfileTypes.INDIVIDUAL; @@ -125,7 +124,7 @@ public Object answer(InvocationOnMock invocation) { } @Test - public void testLoadUser_returnEmptyUserData() { + public void testLoadUser_returnsNoUser() { doAnswer(new Answer() { @Override @@ -148,7 +147,7 @@ public Object answer(InvocationOnMock invocation) { @Test - public void testLoadUser_returnErrors() { + public void testLoadUser_withError() { final HyperwalletError error = new HyperwalletError("test message", "TEST_CODE"); @@ -173,32 +172,4 @@ public Object answer(InvocationOnMock invocation) { assertThat(mErrorCaptor.getValue().getErrors(), hasItem(error)); } - - @Test - public void testRefreshUser_callsGetUserAfterRefresh() { - HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); - final HyperwalletUser user = builder.build(); - - doAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocation) { - HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[0]; - listener.onSuccess(user); - return listener; - } - }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); - UserRepository.LoadUserCallback mockCallback = mock(UserRepository.LoadUserCallback.class); - - mUserRepository.loadUser(mockCallback); - verify(mHyperwallet).getUser(any(HyperwalletListener.class)); - verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); - - mUserRepository.loadUser(mockCallback); - verify(mHyperwallet).getUser(any(HyperwalletListener.class)); - - mUserRepository.refreshUser(); - mUserRepository.loadUser(mockCallback); - verify(mHyperwallet, times(2)).getUser(any(HyperwalletListener.class)); - } - } From de86116e4fb3127d467755096396dcefa816d046 Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Fri, 10 May 2019 11:29:16 +0300 Subject: [PATCH 14/24] HW-52030 Added refresh user test --- .../ui/repository/UserRepositoryImplTest.java | 73 +++++++++++++------ 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java index 3137e2250..68f474bf2 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -9,15 +9,10 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static com.hyperwallet.android.model.HyperwalletUser.ProfileTypes.INDIVIDUAL; -import static com.hyperwallet.android.model.HyperwalletUser.UserFields.CLIENT_USER_ID; -import static com.hyperwallet.android.model.HyperwalletUser.UserFields.CREATED_ON; -import static com.hyperwallet.android.model.HyperwalletUser.UserFields.PROFILE_TYPE; -import static com.hyperwallet.android.model.HyperwalletUser.UserFields.STATUS; -import static com.hyperwallet.android.model.HyperwalletUser.UserFields.TOKEN; -import static com.hyperwallet.android.model.HyperwalletUser.UserFields.VERIFICATION_STATUS; import static com.hyperwallet.android.model.HyperwalletUser.UserStatuses.PRE_ACTIVATED; import static com.hyperwallet.android.model.HyperwalletUser.VerificationStatuses.NOT_REQUIRED; @@ -103,24 +98,23 @@ public Object answer(InvocationOnMock invocation) { verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); HyperwalletUser resultUser = mUserCaptor.getValue(); - assertThat(resultUser.getField(TOKEN), is("usr-f9154016-94e8-4686-a840-075688ac07b5")); - assertThat(resultUser.getField(STATUS), is(PRE_ACTIVATED)); - assertThat(resultUser.getField(VERIFICATION_STATUS), is(NOT_REQUIRED)); - assertThat(resultUser.getField(CREATED_ON), is("2017-10-30T22:15:45")); - assertThat(resultUser.getField(CLIENT_USER_ID), is("123456")); - assertThat(resultUser.getField(PROFILE_TYPE), is(INDIVIDUAL)); - assertThat(resultUser.getField(HyperwalletUser.UserFields.FIRST_NAME), is("Some")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.LAST_NAME), is("Guy")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.DATE_OF_BIRTH), is("1991-01-01")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.EMAIL), is("testUser@hyperwallet.com")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.ADDRESS_LINE_1), is("575 Market Street")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.CITY), is("San Francisco")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.STATE_PROVINCE), is("CA")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.COUNTRY), is("US")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.POSTAL_CODE), is("94105")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.LANGUAGE), is("en")); - assertThat(resultUser.getField(HyperwalletUser.UserFields.PROGRAM_TOKEN), - is("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c")); + assertThat(resultUser.getToken(), is("usr-f9154016-94e8-4686-a840-075688ac07b5")); + assertThat(resultUser.getStatus(), is(PRE_ACTIVATED)); + assertThat(resultUser.getVerificationStatus(), is(NOT_REQUIRED)); + assertThat(resultUser.getCreatedOn(), is("2017-10-30T22:15:45")); + assertThat(resultUser.getClientUserId(), is("123456")); + assertThat(resultUser.getProfileType(), is(INDIVIDUAL)); + assertThat(resultUser.getFirstName(), is("Some")); + assertThat(resultUser.getLastName(), is("Guy")); + assertThat(resultUser.getDateOfBirth(), is("1991-01-01")); + assertThat(resultUser.getEmail(), is("testUser@hyperwallet.com")); + assertThat(resultUser.getAddressLine1(), is("575 Market Street")); + assertThat(resultUser.getCity(), is("San Francisco")); + assertThat(resultUser.getStateProvince(), is("CA")); + assertThat(resultUser.getCountry(), is("US")); + assertThat(resultUser.getPostalCode(), is("94105")); + assertThat(resultUser.getLanguage(), is("en")); + assertThat(resultUser.getProgramToken(), is("prg-83836cdf-2ce2-4696-8bc5-f1b86077238c")); } @Test @@ -172,4 +166,35 @@ public Object answer(InvocationOnMock invocation) { assertThat(mErrorCaptor.getValue().getErrors(), hasItem(error)); } + + @Test + public void testRefreshUser_checkHypervaletCallGetUser() { + HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); + final HyperwalletUser user = builder + .token("usr-f9154016-94e8-4686-a840-075688ac07b5") + .profileType(INDIVIDUAL) + .build(); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + HyperwalletListener listener = (HyperwalletListener) invocation.getArguments()[0]; + listener.onSuccess(user); + return listener; + } + }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); + UserRepository.LoadUserCallback mockCallback = mock(UserRepository.LoadUserCallback.class); + + mUserRepository.loadUser(mockCallback); + + verify(mHyperwallet).getUser(ArgumentMatchers.>any()); + + mUserRepository.loadUser(mockCallback); + verify(mHyperwallet).getUser(ArgumentMatchers.>any()); + + mUserRepository.refreshUser(); + mUserRepository.loadUser(mockCallback); + verify(mHyperwallet, times(2)).getUser(ArgumentMatchers.>any()); + + } } From 3beba73325940d0bd91e9f310c88aadbc86a0b92 Mon Sep 17 00:00:00 2001 From: azakrevska-epam Date: Fri, 10 May 2019 11:42:02 +0300 Subject: [PATCH 15/24] HW-52030. Fixed typo --- .../android/ui/repository/UserRepositoryImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java index 68f474bf2..79669cf89 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -168,7 +168,7 @@ public Object answer(InvocationOnMock invocation) { } @Test - public void testRefreshUser_checkHypervaletCallGetUser() { + public void testRefreshUser_checkHyperwalletCallGetUser() { HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); final HyperwalletUser user = builder .token("usr-f9154016-94e8-4686-a840-075688ac07b5") From 025d64dcde02291c5d1021ca86d4d840ef539ff6 Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Fri, 10 May 2019 15:35:51 -0700 Subject: [PATCH 16/24] update agreement --- .../android/ui/repository/UserRepository.java | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java index fc933bf8e..8ee119fa8 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java @@ -1,28 +1,19 @@ /* * Copyright 2018 Hyperwallet * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated - * documentation files (the "Software"), to deal in the Software without restriction, including - * without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of * the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO - * EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ package com.hyperwallet.android.ui.repository; From 09cc06a4b8c9063e17590a36f8d085fe291bd78e Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Fri, 10 May 2019 15:36:13 -0700 Subject: [PATCH 17/24] update agreement --- .../ui/repository/UserRepositoryImpl.java | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java index 3619e1fff..561d4cf85 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepositoryImpl.java @@ -1,28 +1,19 @@ /* * Copyright 2018 Hyperwallet * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated - * documentation files (the "Software"), to deal in the Software without restriction, including - * without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and - * to permit persons to whom the Software is furnished to do so, subject to the following - * conditions: + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and + * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of * the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO - * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO - * EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO + * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. */ package com.hyperwallet.android.ui.repository; From 7e6e30728165b613593ed3ef5d76f4e17a8f7ac7 Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Fri, 10 May 2019 15:50:06 -0700 Subject: [PATCH 18/24] renaming tests --- .../android/ui/repository/UserRepositoryImplTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java index 79669cf89..5d97211f8 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -60,7 +60,7 @@ public void setup() { } @Test - public void testLoadUser_returnValidData() { + public void testLoadUser_returnsUser() { HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); final HyperwalletUser user = builder .token("usr-f9154016-94e8-4686-a840-075688ac07b5") @@ -168,7 +168,7 @@ public Object answer(InvocationOnMock invocation) { } @Test - public void testRefreshUser_checkHyperwalletCallGetUser() { + public void testRefreshUser_verifyHyperwalletCallGetUser() { HyperwalletUser.Builder builder = new HyperwalletUser.Builder(); final HyperwalletUser user = builder .token("usr-f9154016-94e8-4686-a840-075688ac07b5") From 6de4ab06333f9cf5e556728586e6699c8e8b2c91 Mon Sep 17 00:00:00 2001 From: Anna <48258136+azakrevska-epam@users.noreply.github.com> Date: Tue, 14 May 2019 00:03:49 +0300 Subject: [PATCH 19/24] HW-52031. Update select method presenter (#3) * HW-52031 Get user profile type --- ...TransferMethodConfigurationRepository.java | 3 +- ...sferMethodConfigurationRepositoryImpl.java | 8 +- .../android/ui/repository/UserRepository.java | 3 +- .../AddTransferMethodActivity.java | 9 +- .../AddTransferMethodContract.java | 3 +- .../AddTransferMethodFragment.java | 23 +- .../AddTransferMethodPresenter.java | 11 +- .../SelectTransferMethodFragment.java | 4 +- .../SelectTransferMethodPresenter.java | 173 ++++++++----- ...MethodConfigurationRepositoryImplTest.java | 9 +- .../ui/repository/UserRepositoryImplTest.java | 31 +-- .../AddTransferMethodPresenterTest.java | 28 +- .../SelectTransferMethodPresenterTest.java | 244 +++++++++++++++--- ui/src/test/resources/user_response.json | 26 ++ 14 files changed, 424 insertions(+), 151 deletions(-) create mode 100644 ui/src/test/resources/user_response.json diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepository.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepository.java index e89c8bab5..bea52cb18 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepository.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepository.java @@ -39,7 +39,8 @@ public interface TransferMethodConfigurationRepository { void getKeys(@NonNull final LoadKeysCallback loadKeysCallback); void getFields(@NonNull final String country, @NonNull final String currency, - @NonNull final String transferMethodType, @NonNull final LoadFieldsCallback loadFieldsCallback); + @NonNull final String transferMethodType, @NonNull final String transferMethodProfileType, + @NonNull final LoadFieldsCallback loadFieldsCallback); void refreshKeys(); diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImpl.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImpl.java index 008c87176..89aa23f59 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImpl.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImpl.java @@ -47,7 +47,6 @@ import java.util.Objects; public class TransferMethodConfigurationRepositoryImpl implements TransferMethodConfigurationRepository { - private static final String INDIVIDUAL = "INDIVIDUAL"; private HyperwalletTransferMethodConfigurationKeyResult mTransferMethodConfigurationKeyResult; private final Handler mHandler; private final Map mFieldMap; @@ -104,9 +103,11 @@ public Handler getHandler() { void getTransferMethodConfigurationFieldResult(@NonNull final String country, @NonNull final String currency, @NonNull final String transferMethodType, + @NonNull final String transferMethodProfileType, @NonNull final LoadFieldsCallback loadFieldsCallback) { HyperwalletTransferMethodConfigurationFieldQuery query = - new HyperwalletTransferMethodConfigurationFieldQuery(country, currency, transferMethodType, INDIVIDUAL); + new HyperwalletTransferMethodConfigurationFieldQuery(country, currency, transferMethodType, + transferMethodProfileType); EspressoIdlingResource.increment(); getHyperwallet().retrieveTransferMethodConfigurationFields( @@ -146,6 +147,7 @@ public synchronized void getKeys(@NonNull final LoadKeysCallback loadKeysCallbac @Override public synchronized void getFields(@NonNull final String country, @NonNull final String currency, @NonNull final String transferMethodType, + @NonNull final String transferMethodProfileType, @NonNull final LoadFieldsCallback loadFieldsCallback) { FieldMapKey fieldMapKey = new FieldMapKey(country, currency, transferMethodType); HyperwalletTransferMethodConfigurationFieldResult transferMethodConfigurationFieldResult = mFieldMap.get( @@ -153,7 +155,7 @@ public synchronized void getFields(@NonNull final String country, @NonNull final // if there is no value for country-currency-type combination, // it means api call was never made or this combination or it was refreshed if (transferMethodConfigurationFieldResult == null) { - getTransferMethodConfigurationFieldResult(country, currency, transferMethodType, loadFieldsCallback); + getTransferMethodConfigurationFieldResult(country, currency, transferMethodType, transferMethodProfileType, loadFieldsCallback); } else { loadFieldsCallback.onFieldsLoaded(transferMethodConfigurationFieldResult); } diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java index 8ee119fa8..902a8d13b 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/UserRepository.java @@ -19,7 +19,6 @@ package com.hyperwallet.android.ui.repository; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import com.hyperwallet.android.model.HyperwalletErrors; import com.hyperwallet.android.model.HyperwalletUser; @@ -51,7 +50,7 @@ public interface UserRepository { */ interface LoadUserCallback { - void onUserLoaded(@Nullable final HyperwalletUser user); + void onUserLoaded(@NonNull final HyperwalletUser user); void onError(@NonNull final HyperwalletErrors errors); } diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodActivity.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodActivity.java index 5e6fcba75..381446c7a 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodActivity.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodActivity.java @@ -45,6 +45,7 @@ public class AddTransferMethodActivity extends AppCompatActivity implements public static final String EXTRA_TRANSFER_METHOD_COUNTRY = "TRANSFER_METHOD_COUNTRY"; public static final String EXTRA_TRANSFER_METHOD_CURRENCY = "TRANSFER_METHOD_CURRENCY"; public static final String EXTRA_TRANSFER_METHOD_TYPE = "TRANSFER_METHOD_TYPE"; + public static final String EXTRA_TRANSFER_METHOD_PROFILE_TYPE = "TRANSFER_METHOD_PROFILE_TYPE"; public static final int REQUEST_CODE = 100; private static final String ARGUMENT_RETRY_ACTION = "ARGUMENT_RETRY_ACTION"; private static final short RETRY_SHOW_ERROR_ADD_TRANSFER_METHOD = 100; @@ -75,7 +76,9 @@ public void onClick(View v) { initFragment(AddTransferMethodFragment.newInstance( getIntent().getStringExtra(EXTRA_TRANSFER_METHOD_COUNTRY), getIntent().getStringExtra(EXTRA_TRANSFER_METHOD_CURRENCY), - getIntent().getStringExtra(EXTRA_TRANSFER_METHOD_TYPE))); + getIntent().getStringExtra(EXTRA_TRANSFER_METHOD_TYPE), + getIntent().getStringExtra(EXTRA_TRANSFER_METHOD_PROFILE_TYPE) + )); } else { mRetryCode = savedInstanceState.getShort(ARGUMENT_RETRY_ACTION); } @@ -181,7 +184,9 @@ private AddTransferMethodFragment getAddTransferMethodFragment() { fragment = AddTransferMethodFragment.newInstance( getIntent().getStringExtra(EXTRA_TRANSFER_METHOD_COUNTRY), getIntent().getStringExtra(EXTRA_TRANSFER_METHOD_CURRENCY), - getIntent().getStringExtra(EXTRA_TRANSFER_METHOD_TYPE)); + getIntent().getStringExtra(EXTRA_TRANSFER_METHOD_TYPE), + getIntent().getStringExtra(EXTRA_TRANSFER_METHOD_PROFILE_TYPE) + ); } return fragment; } diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodContract.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodContract.java index 6b2d136ba..93f3aa9da 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodContract.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodContract.java @@ -71,6 +71,7 @@ interface Presenter { void loadTransferMethodConfigurationFields(boolean forceUpdate, @NonNull String country, @NonNull String currency, - @NonNull String transferMethodType); + @NonNull String transferMethodType, + @NonNull String transferMethodProfileType); } } diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java index 28d977e7a..d52e6ad5f 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java @@ -71,6 +71,7 @@ public class AddTransferMethodFragment extends Fragment implements WidgetEventLi private static final String ARGUMENT_TRANSFER_METHOD_COUNTRY = "ARGUMENT_TRANSFER_METHOD_COUNTRY"; private static final String ARGUMENT_TRANSFER_METHOD_CURRENCY = "ARGUMENT_TRANSFER_METHOD_CURRENCY"; private static final String ARGUMENT_TRANSFER_METHOD_TYPE = "ARGUMENT_TRANSFER_METHOD_TYPE"; + private static final String ARGUMENT_TRANSFER_METHOD_PROFILE_TYPE = "ARGUMENT_TRANSFER_METHOD_PROFILE_TYPE"; private static final String ARGUMENT_SHOW_CREATE_PROGRESS_BAR = "ARGUMENT_SHOW_CREATE_PROGRESS_BAR"; private static final String ARGUMENT_TRANSFER_METHOD = "ARGUMENT_TRANSFER_METHOD"; private static final String ARGUMENT_WIDGET_STATE_MAP = "ARGUMENT_WIDGET_STATE_MAP"; @@ -89,6 +90,7 @@ public class AddTransferMethodFragment extends Fragment implements WidgetEventLi private boolean mShowCreateProgressBar; private String mTransferMethodType; private HyperwalletTransferMethod mTransferMethod; + private String mTransferMethodProfileType; private HashMap mWidgetInputStateHashMap; private TextView sectionHeaderTextView; @@ -101,16 +103,18 @@ public AddTransferMethodFragment() { /** * Creates new instance of AddTransferMethodFragment this is the proper initialization of this class * since the default constructor is reserved for android framework when lifecycle is triggered. - * The parameters in {@link AddTransferMethodFragment#newInstance(String, String, String)} is mandatory + * The parameters in {@link AddTransferMethodFragment#newInstance(String, String, String, String)} is mandatory * and should be supplied with correct data or this fragment will not initialize properly. * - * @param transferMethodCountry the country selected when creating transfer method - * @param transferMethodCurrency the currency selected when creating transfer method - * @param transferMethodType the type of transfer method needed to create transfer method + * @param transferMethodCountry the country selected when creating transfer method + * @param transferMethodCurrency the currency selected when creating transfer method + * @param transferMethodType the type of transfer method needed to create transfer method + * @param transferMethodProfileType the type of transfer method profile needed to create transfer method */ public static AddTransferMethodFragment newInstance(@NonNull String transferMethodCountry, @NonNull String transferMethodCurrency, - @NonNull String transferMethodType) { + @NonNull String transferMethodType, + @NonNull String transferMethodProfileType) { AddTransferMethodFragment addTransferMethodFragment = new AddTransferMethodFragment(); Bundle arguments = new Bundle(); @@ -119,10 +123,13 @@ public static AddTransferMethodFragment newInstance(@NonNull String transferMeth addTransferMethodFragment.mCurrency = transferMethodCurrency; addTransferMethodFragment.mWidgetInputStateHashMap = new HashMap<>(1); addTransferMethodFragment.mTransferMethod = null; + addTransferMethodFragment.mTransferMethodProfileType = transferMethodProfileType; arguments.putString(ARGUMENT_TRANSFER_METHOD_COUNTRY, addTransferMethodFragment.mCountry); arguments.putString(ARGUMENT_TRANSFER_METHOD_CURRENCY, addTransferMethodFragment.mCurrency); arguments.putString(ARGUMENT_TRANSFER_METHOD_TYPE, addTransferMethodFragment.mTransferMethodType); + arguments.putString(ARGUMENT_TRANSFER_METHOD_PROFILE_TYPE, + addTransferMethodFragment.mTransferMethodProfileType); arguments.putParcelable(ARGUMENT_TRANSFER_METHOD, addTransferMethodFragment.mTransferMethod); arguments.putSerializable(ARGUMENT_WIDGET_STATE_MAP, addTransferMethodFragment.mWidgetInputStateHashMap); addTransferMethodFragment.setArguments(arguments); @@ -222,7 +229,8 @@ public void onViewStateRestored(@Nullable Bundle savedInstanceState) { @Override public void onResume() { super.onResume(); - mPresenter.loadTransferMethodConfigurationFields(FORCE_UPDATE, mCountry, mCurrency, mTransferMethodType); + mPresenter.loadTransferMethodConfigurationFields(FORCE_UPDATE, mCountry, mCurrency, mTransferMethodType, + mTransferMethodProfileType); } @Override @@ -254,7 +262,8 @@ public void retryAddTransferMethod() { @Override public void reloadTransferMethodConfigurationFields() { - mPresenter.loadTransferMethodConfigurationFields(FORCE_UPDATE, mCountry, mCurrency, mTransferMethodType); + mPresenter.loadTransferMethodConfigurationFields(FORCE_UPDATE, mCountry, mCurrency, mTransferMethodType, + mTransferMethodProfileType); } @Override diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenter.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenter.java index dc048c1d1..73b10717d 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenter.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenter.java @@ -75,7 +75,8 @@ public void onError(HyperwalletErrors errors) { @Override public void loadTransferMethodConfigurationFields(final boolean forceUpdate, @NonNull final String country, - @NonNull final String currency, @NonNull final String transferMethodType) { + @NonNull final String currency, @NonNull final String transferMethodType, + @NonNull final String transferMethodProfileType) { mView.showProgressBar(); if (forceUpdate) { @@ -83,7 +84,8 @@ public void loadTransferMethodConfigurationFields(final boolean forceUpdate, @No } mTransferMethodConfigurationRepository.getFields( - country, currency, transferMethodType, new TransferMethodConfigurationRepository.LoadFieldsCallback() { + country, currency, transferMethodType, transferMethodProfileType, + new TransferMethodConfigurationRepository.LoadFieldsCallback() { @Override public void onFieldsLoaded( HyperwalletTransferMethodConfigurationFieldResult transferMethodConfigurationFieldResult) { @@ -95,10 +97,11 @@ public void onFieldsLoaded( mView.showTransferMethodFields(transferMethodConfigurationFieldResult.getFields()); // there can be multiple fees when we have flat fee + percentage fees List fees = transferMethodConfigurationFieldResult - .getFees(country, currency, transferMethodType, "INDIVIDUAL"); + .getFees(country, currency, transferMethodType, transferMethodProfileType); mView.showTransactionInformation(fees, transferMethodConfigurationFieldResult - .getProcessingTime(country, currency, transferMethodType, "INDIVIDUAL")); + .getProcessingTime(country, currency, transferMethodType, + transferMethodProfileType)); } @Override diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodFragment.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodFragment.java index ec2f3c9ba..4b8c399d2 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodFragment.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodFragment.java @@ -190,7 +190,9 @@ public void onTransferMethodSelected(TransferMethodSelectionItem transferMethodT public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); RepositoryFactory factory = RepositoryFactory.getInstance(); - mPresenter = new SelectTransferMethodPresenter(this, factory.getTransferMethodConfigurationRepository()); + mPresenter = new SelectTransferMethodPresenter(this, + factory.getTransferMethodConfigurationRepository(), + factory.getUserRepository()); } diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java index 8abdb1ce1..ae21c4d2e 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java @@ -22,9 +22,11 @@ import androidx.annotation.Nullable; import com.hyperwallet.android.model.HyperwalletErrors; +import com.hyperwallet.android.model.HyperwalletUser; import com.hyperwallet.android.model.meta.Fee; import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationKeyResult; import com.hyperwallet.android.ui.repository.TransferMethodConfigurationRepository; +import com.hyperwallet.android.ui.repository.UserRepository; import java.util.ArrayList; import java.util.Currency; @@ -33,16 +35,17 @@ import java.util.TreeMap; public class SelectTransferMethodPresenter implements SelectTransferMethodContract.Presenter { - private static final String TAG = SelectTransferMethodPresenter.class.getName(); - private static final String INDIVIDUAL = "INDIVIDUAL"; private final TransferMethodConfigurationRepository mTransferMethodConfigurationRepository; + private final UserRepository mUserRepository; private final SelectTransferMethodContract.View mView; SelectTransferMethodPresenter(SelectTransferMethodContract.View view, - TransferMethodConfigurationRepository transferMethodConfigurationRepository) { + @NonNull final TransferMethodConfigurationRepository transferMethodConfigurationRepository, + @NonNull final UserRepository userRepository) { this.mView = view; this.mTransferMethodConfigurationRepository = transferMethodConfigurationRepository; + this.mUserRepository = userRepository; } @Override @@ -55,35 +58,50 @@ public void loadTransferMethodConfigurationKeys(final boolean forceUpdate, @NonN mTransferMethodConfigurationRepository.refreshKeys(); } - mTransferMethodConfigurationRepository.getKeys(new TransferMethodConfigurationRepository.LoadKeysCallback() { + mUserRepository.loadUser(new UserRepository.LoadUserCallback() { @Override - public void onKeysLoaded( - @Nullable final HyperwalletTransferMethodConfigurationKeyResult transferMethodConfigurationKeyResult) { - if (!mView.isActive()) { - return; - } - - mView.hideProgressBar(); - List transferMethodTypes = - transferMethodConfigurationKeyResult.getTransferMethods(countryCode, currencyCode, INDIVIDUAL); - - mView.showTransferMethodCountry(countryCode); - mView.showTransferMethodCurrency(currencyCode); - mView.showTransferMethodTypes(getTransferMethodSelectionItems(countryCode, currencyCode, - transferMethodTypes, transferMethodConfigurationKeyResult)); + public void onUserLoaded(@NonNull final HyperwalletUser user) { + mTransferMethodConfigurationRepository.getKeys( + new TransferMethodConfigurationRepository.LoadKeysCallback() { + @Override + public void onKeysLoaded( + @Nullable final HyperwalletTransferMethodConfigurationKeyResult transferMethodConfigurationKeyResult) { + if (!mView.isActive()) { + return; + } + mView.hideProgressBar(); + List transferMethodTypes = + transferMethodConfigurationKeyResult.getTransferMethods(countryCode, + currencyCode, user.getProfileType()); + + mView.showTransferMethodCountry(countryCode); + mView.showTransferMethodCurrency(currencyCode); + mView.showTransferMethodTypes(getTransferMethodSelectionItems(countryCode, currencyCode, + user.getProfileType(), transferMethodTypes, transferMethodConfigurationKeyResult)); + } + + @Override + public void onError(@NonNull final HyperwalletErrors errors) { + showErrorLoadTransferMethods(errors); + } + }); } @Override - public void onError(@NonNull final HyperwalletErrors errors) { - if (!mView.isActive()) { - return; - } - mView.hideProgressBar(); - mView.showErrorLoadTransferMethodConfigurationKeys(errors.getErrors()); + public void onError(@NonNull HyperwalletErrors errors) { + showErrorLoadTransferMethods(errors); } }); } + private void showErrorLoadTransferMethods(@NonNull HyperwalletErrors errors) { + if (!mView.isActive()) { + return; + } + mView.hideProgressBar(); + mView.showErrorLoadTransferMethodConfigurationKeys(errors.getErrors()); + } + @Override public void loadCurrency(final boolean forceUpdate, @NonNull final String countryCode) { @@ -91,30 +109,47 @@ public void loadCurrency(final boolean forceUpdate, @NonNull final String countr mTransferMethodConfigurationRepository.refreshKeys(); } - mTransferMethodConfigurationRepository.getKeys(new TransferMethodConfigurationRepository.LoadKeysCallback() { + mUserRepository.loadUser(new UserRepository.LoadUserCallback() { @Override - public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationKeyResult result) { - if (!mView.isActive()) { - return; - } - List transferMethodCurrencies = result.getCurrencies(countryCode); - List transferMethodTypes = result.getTransferMethods( - countryCode, transferMethodCurrencies.get(0), INDIVIDUAL); - - mView.showTransferMethodCountry(countryCode); - mView.showTransferMethodCurrency(transferMethodCurrencies.get(0)); - mView.showTransferMethodTypes(getTransferMethodSelectionItems(countryCode, - transferMethodCurrencies.get(0), transferMethodTypes, result)); + public void onUserLoaded(@NonNull final HyperwalletUser user) { + mTransferMethodConfigurationRepository.getKeys( + new TransferMethodConfigurationRepository.LoadKeysCallback() { + @Override + public void onKeysLoaded( + @Nullable final HyperwalletTransferMethodConfigurationKeyResult result) { + if (!mView.isActive()) { + return; + } + List transferMethodCurrencies = result.getCurrencies(countryCode); + List transferMethodTypes = result.getTransferMethods( + countryCode, transferMethodCurrencies.get(0), user.getProfileType()); + + mView.showTransferMethodCountry(countryCode); + mView.showTransferMethodCurrency(transferMethodCurrencies.get(0)); + mView.showTransferMethodTypes(getTransferMethodSelectionItems(countryCode, + transferMethodCurrencies.get(0), user.getProfileType(), transferMethodTypes, result)); + } + + @Override + public void onError(@NonNull final HyperwalletErrors errors) { + showErrorLoadCurrency(errors); + } + }); } @Override - public void onError(@NonNull final HyperwalletErrors errors) { - if (!mView.isActive()) { - return; - } - mView.showErrorLoadCurrency(errors.getErrors()); + public void onError(@NonNull HyperwalletErrors errors) { + showErrorLoadCurrency(errors); } }); + + } + + private void showErrorLoadCurrency(@NonNull HyperwalletErrors errors) { + if (!mView.isActive()) { + return; + } + mView.showErrorLoadCurrency(errors.getErrors()); } @Override @@ -124,31 +159,47 @@ public void loadTransferMethodTypes(final boolean forceUpdate, mTransferMethodConfigurationRepository.refreshKeys(); } - mTransferMethodConfigurationRepository.getKeys(new TransferMethodConfigurationRepository.LoadKeysCallback() { + mUserRepository.loadUser(new UserRepository.LoadUserCallback() { @Override - public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationKeyResult - transferMethodConfigurationKeyResult) { - if (!mView.isActive()) { - return; - } - - List transferMethodTypes = transferMethodConfigurationKeyResult.getTransferMethods( - countryCode, currencyCode, INDIVIDUAL); - - mView.showTransferMethodCountry(countryCode); - mView.showTransferMethodCurrency(currencyCode); - mView.showTransferMethodTypes(getTransferMethodSelectionItems(countryCode, currencyCode, - transferMethodTypes, transferMethodConfigurationKeyResult)); + public void onUserLoaded(@NonNull final HyperwalletUser user) { + mTransferMethodConfigurationRepository.getKeys( + new TransferMethodConfigurationRepository.LoadKeysCallback() { + @Override + public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationKeyResult + transferMethodConfigurationKeyResult) { + if (!mView.isActive()) { + return; + } + + List transferMethodTypes = + transferMethodConfigurationKeyResult.getTransferMethods( + countryCode, currencyCode, user.getProfileType()); + + mView.showTransferMethodCountry(countryCode); + mView.showTransferMethodCurrency(currencyCode); + mView.showTransferMethodTypes(getTransferMethodSelectionItems(countryCode, currencyCode, + user.getProfileType(), transferMethodTypes, transferMethodConfigurationKeyResult)); + } + + @Override + public void onError(@NonNull final HyperwalletErrors errors) { + if (!mView.isActive()) { + return; + } + mView.showErrorLoadTransferMethodTypes(errors.getErrors()); + } + }); } @Override - public void onError(@NonNull final HyperwalletErrors errors) { + public void onError(@NonNull HyperwalletErrors errors) { if (!mView.isActive()) { return; } mView.showErrorLoadTransferMethodTypes(errors.getErrors()); } }); + } @Override @@ -219,17 +270,19 @@ public void onError(@NonNull final HyperwalletErrors errors) { private List getTransferMethodSelectionItems( @NonNull final String country, @NonNull final String currency, + @NonNull final String userProfileType, @NonNull final List transferMethodTypes, @NonNull final HyperwalletTransferMethodConfigurationKeyResult result) { List selectionItems = new ArrayList<>(); for (String transferMethodType : transferMethodTypes) { - List fees = result.getFees(country, currency, transferMethodType, INDIVIDUAL); - String processingTime = result.getProcessingTime(country, currency, transferMethodType, INDIVIDUAL); - TransferMethodSelectionItem data = new TransferMethodSelectionItem(country, currency, INDIVIDUAL, + List fees = result.getFees(country, currency, transferMethodType, userProfileType); + String processingTime = result.getProcessingTime(country, currency, transferMethodType, userProfileType); + TransferMethodSelectionItem data = new TransferMethodSelectionItem(country, currency, userProfileType, transferMethodType, processingTime, fees); selectionItems.add(data); } return selectionItems; } + } diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImplTest.java index c89e2d298..ee6bd294e 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImplTest.java @@ -13,6 +13,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static com.hyperwallet.android.model.HyperwalletUser.ProfileTypes.INDIVIDUAL; + import com.hyperwallet.android.Hyperwallet; import com.hyperwallet.android.exception.HyperwalletException; import com.hyperwallet.android.listener.HyperwalletListener; @@ -168,7 +170,7 @@ public Object answer(InvocationOnMock invocation) { ArgumentMatchers.any(), ArgumentMatchers.>any()); - mTransferMethodConfigurationRepositoryImplMock.getFields(COUNTRY, CURRENCY, TRANSFER_METHOD_TYPE, + mTransferMethodConfigurationRepositoryImplMock.getFields(COUNTRY, CURRENCY, TRANSFER_METHOD_TYPE, INDIVIDUAL, loadFieldsCallback); verify(loadFieldsCallback).onFieldsLoaded(fieldResultArgumentCaptor.capture()); @@ -204,7 +206,7 @@ public Object answer(InvocationOnMock invocation) { ArgumentMatchers.>any()); - mTransferMethodConfigurationRepositoryImplMock.getFields(COUNTRY, CURRENCY, TRANSFER_METHOD_TYPE, + mTransferMethodConfigurationRepositoryImplMock.getFields(COUNTRY, CURRENCY, TRANSFER_METHOD_TYPE, INDIVIDUAL, loadFieldsCallback); verify(loadFieldsCallback, never()).onFieldsLoaded( @@ -248,13 +250,14 @@ public void testGetFields_callsListenerWithFieldResultFromCacheWhenNotNull() thr FieldMapKey fieldMapKey = new FieldMapKey(COUNTRY, CURRENCY, TRANSFER_METHOD_TYPE); when(mFieldsMap.get(fieldMapKey)).thenReturn(result); - mTransferMethodConfigurationRepositoryImplMock.getFields(COUNTRY, CURRENCY, TRANSFER_METHOD_TYPE, + mTransferMethodConfigurationRepositoryImplMock.getFields(COUNTRY, CURRENCY, TRANSFER_METHOD_TYPE,INDIVIDUAL, loadFieldsCallback); verify(mTransferMethodConfigurationRepositoryImplMock, never()).getTransferMethodConfigurationFieldResult( any(String.class), any(String.class), any(String.class), + any(String.class), any(TransferMethodConfigurationRepository.LoadFieldsCallback.class)); verify(loadFieldsCallback).onFieldsLoaded(fieldResultArgumentCaptor.capture()); verify(loadFieldsCallback, never()).onError(any(HyperwalletErrors.class)); diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java index 5d97211f8..0f54ad10f 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/UserRepositoryImplTest.java @@ -45,6 +45,8 @@ public class UserRepositoryImplTest { @Mock private Hyperwallet mHyperwallet; + @Mock + UserRepository.LoadUserCallback mMockCallback; @Captor private ArgumentCaptor mErrorCaptor; @Captor @@ -90,12 +92,11 @@ public Object answer(InvocationOnMock invocation) { return listener; } }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); - UserRepository.LoadUserCallback mockCallback = mock(UserRepository.LoadUserCallback.class); - mUserRepository.loadUser(mockCallback); + mUserRepository.loadUser(mMockCallback); - verify(mockCallback).onUserLoaded(mUserCaptor.capture()); - verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); + verify(mMockCallback).onUserLoaded(mUserCaptor.capture()); + verify(mMockCallback, never()).onError(any(HyperwalletErrors.class)); HyperwalletUser resultUser = mUserCaptor.getValue(); assertThat(resultUser.getToken(), is("usr-f9154016-94e8-4686-a840-075688ac07b5")); @@ -128,12 +129,11 @@ public Object answer(InvocationOnMock invocation) { return listener; } }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); - UserRepository.LoadUserCallback mockCallback = mock(UserRepository.LoadUserCallback.class); - mUserRepository.loadUser(mockCallback); + mUserRepository.loadUser(mMockCallback); - verify(mockCallback).onUserLoaded(mUserCaptor.capture()); - verify(mockCallback, never()).onError(any(HyperwalletErrors.class)); + verify(mMockCallback).onUserLoaded(mUserCaptor.capture()); + verify(mMockCallback, never()).onError(any(HyperwalletErrors.class)); HyperwalletUser user = mUserCaptor.getValue(); assertThat(user, is(nullValue())); @@ -156,13 +156,11 @@ public Object answer(InvocationOnMock invocation) { return listener; } }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); - UserRepository.LoadUserCallback mockCallback = mock( - UserRepository.LoadUserCallback.class); - mUserRepository.loadUser(mockCallback); + mUserRepository.loadUser(mMockCallback); - verify(mockCallback, never()).onUserLoaded(ArgumentMatchers.any()); - verify(mockCallback).onError(mErrorCaptor.capture()); + verify(mMockCallback, never()).onUserLoaded(ArgumentMatchers.any()); + verify(mMockCallback).onError(mErrorCaptor.capture()); assertThat(mErrorCaptor.getValue().getErrors(), hasItem(error)); } @@ -183,17 +181,16 @@ public Object answer(InvocationOnMock invocation) { return listener; } }).when(mHyperwallet).getUser(ArgumentMatchers.>any()); - UserRepository.LoadUserCallback mockCallback = mock(UserRepository.LoadUserCallback.class); - mUserRepository.loadUser(mockCallback); + mUserRepository.loadUser(mMockCallback); verify(mHyperwallet).getUser(ArgumentMatchers.>any()); - mUserRepository.loadUser(mockCallback); + mUserRepository.loadUser(mMockCallback); verify(mHyperwallet).getUser(ArgumentMatchers.>any()); mUserRepository.refreshUser(); - mUserRepository.loadUser(mockCallback); + mUserRepository.loadUser(mMockCallback); verify(mHyperwallet, times(2)).getUser(ArgumentMatchers.>any()); } diff --git a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenterTest.java b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenterTest.java index 4169726f8..a0f809ee0 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenterTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenterTest.java @@ -13,6 +13,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static com.hyperwallet.android.model.HyperwalletUser.ProfileTypes.INDIVIDUAL; + import com.hyperwallet.android.model.HyperwalletBankAccount; import com.hyperwallet.android.model.HyperwalletError; import com.hyperwallet.android.model.HyperwalletErrors; @@ -149,15 +151,15 @@ public void testLoadTransferMethodConfigurationFields_loadsTransferMethodFieldsI @Override public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadFieldsCallback callback = - (TransferMethodConfigurationRepository.LoadFieldsCallback) invocation.getArguments()[3]; + (TransferMethodConfigurationRepository.LoadFieldsCallback) invocation.getArguments()[4]; callback.onFieldsLoaded(result); return callback; } - }).when(tmcRepository).getFields(anyString(), anyString(), anyString(), + }).when(tmcRepository).getFields(anyString(), anyString(), anyString(), anyString(), any(TransferMethodConfigurationRepository.LoadFieldsCallback.class)); // Then - presenter.loadTransferMethodConfigurationFields(false, "CA", "CAD", "BANK_ACCOUNT"); + presenter.loadTransferMethodConfigurationFields(false, "CA", "CAD", "BANK_ACCOUNT", INDIVIDUAL); LATCH.await(AWAIT_TIME_MS, TimeUnit.MILLISECONDS); verify(view).showTransferMethodFields(fieldArgumentCaptor.capture()); @@ -177,15 +179,15 @@ public void testLoadTransferMethodConfigurationFields_showsErrorOnFailure() thro @Override public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadFieldsCallback callback = - (TransferMethodConfigurationRepository.LoadFieldsCallback) invocation.getArguments()[3]; + (TransferMethodConfigurationRepository.LoadFieldsCallback) invocation.getArguments()[4]; callback.onError(errors); return callback; } - }).when(tmcRepository).getFields(anyString(), anyString(), anyString(), + }).when(tmcRepository).getFields(anyString(), anyString(), anyString(),anyString(), any(TransferMethodConfigurationRepository.LoadFieldsCallback.class)); // Then - presenter.loadTransferMethodConfigurationFields(false, "CA", "CAD", "BANK_ACCOUNT"); + presenter.loadTransferMethodConfigurationFields(false, "CA", "CAD", "BANK_ACCOUNT", INDIVIDUAL); LATCH.await(AWAIT_TIME_MS, TimeUnit.MILLISECONDS); verify(view, never()).showTransferMethodFields(ArgumentMatchers.anyList()); @@ -195,10 +197,10 @@ public Object answer(InvocationOnMock invocation) { @Test public void testLoadTransferMethodConfigurationFields_updatesFieldsWhenForceUpdateIsTrue() { - presenter.loadTransferMethodConfigurationFields(true, "CA", "CAD", "BANK_ACCOUNT"); + presenter.loadTransferMethodConfigurationFields(true, "CA", "CAD", "BANK_ACCOUNT", INDIVIDUAL); verify(tmcRepository, atLeastOnce()).refreshFields(); - verify(tmcRepository, atLeastOnce()).getFields(anyString(), anyString(), anyString(), + verify(tmcRepository, atLeastOnce()).getFields(anyString(), anyString(), anyString(), anyString(), any(TransferMethodConfigurationRepository.LoadFieldsCallback.class)); verify(view, never()).showTransferMethodFields(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadTransferMethodConfigurationFields( @@ -212,10 +214,10 @@ public void testLoadTransferMethodConfigurationFields_loadsTransferMethodFieldsI when(view.isActive()).thenReturn(false); // Then - presenter.loadTransferMethodConfigurationFields(true, "CA", "CAD", "BANK_ACCOUNT"); + presenter.loadTransferMethodConfigurationFields(true, "CA", "CAD", "BANK_ACCOUNT", INDIVIDUAL); verify(tmcRepository, atLeastOnce()).refreshFields(); - verify(tmcRepository, atLeastOnce()).getFields(anyString(), anyString(), anyString(), + verify(tmcRepository, atLeastOnce()).getFields(anyString(), anyString(), anyString(), anyString(), any(TransferMethodConfigurationRepository.LoadFieldsCallback.class)); verify(view, never()).hideProgressBar(); verify(view, never()).showTransferMethodFields(ArgumentMatchers.anyList()); @@ -232,15 +234,15 @@ public void testLoadTransferMethodConfigurationFields_loadsTransferMethodFieldsE @Override public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadFieldsCallback callback = - (TransferMethodConfigurationRepository.LoadFieldsCallback) invocation.getArguments()[3]; + (TransferMethodConfigurationRepository.LoadFieldsCallback) invocation.getArguments()[4]; callback.onError(errors); return callback; } - }).when(tmcRepository).getFields(anyString(), anyString(), anyString(), + }).when(tmcRepository).getFields(anyString(), anyString(), anyString(), anyString(), any(TransferMethodConfigurationRepository.LoadFieldsCallback.class)); // Then - presenter.loadTransferMethodConfigurationFields(false, "CA", "CAD", "BANK_ACCOUNT"); + presenter.loadTransferMethodConfigurationFields(false, "CA", "CAD", "BANK_ACCOUNT", INDIVIDUAL); LATCH.await(AWAIT_TIME_MS, TimeUnit.MILLISECONDS); verify(view, never()).hideProgressBar(); diff --git a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java index 5a666ec6e..4c596a39a 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java @@ -13,9 +13,12 @@ import com.hyperwallet.android.model.HyperwalletError; import com.hyperwallet.android.model.HyperwalletErrors; +import com.hyperwallet.android.model.HyperwalletUser; import com.hyperwallet.android.model.meta.TransferMethodConfigurationResult; import com.hyperwallet.android.ui.repository.TransferMethodConfigurationRepository; import com.hyperwallet.android.ui.repository.TransferMethodConfigurationRepositoryImpl; +import com.hyperwallet.android.ui.repository.UserRepository; +import com.hyperwallet.android.ui.repository.UserRepositoryImpl; import com.hyperwallet.android.ui.rule.HyperwalletExternalResourceManager; import org.json.JSONObject; @@ -42,21 +45,31 @@ public class SelectTransferMethodPresenterTest { @Mock private SelectTransferMethodContract.View view; @Mock - private TransferMethodConfigurationRepositoryImpl transferMethodConfigurationRepository; + private TransferMethodConfigurationRepositoryImpl mTransferMethodConfigurationRepository; + @Mock + private UserRepositoryImpl mUserRepository; @Rule public HyperwalletExternalResourceManager externalResourceManager = new HyperwalletExternalResourceManager(); - private TransferMethodConfigurationResult result; + private TransferMethodConfigurationResult mResult; + private HyperwalletUser mUser; private SelectTransferMethodPresenter selectTransferMethodPresenter; private final HyperwalletErrors errors = createErrors(); @Before public void initialize() throws Exception { initMocks(this); - String responseBody = externalResourceManager.getResourceContent("successful_tmc_keys_response.json"); - final JSONObject jsonObject = new JSONObject(responseBody); - result = new TransferMethodConfigurationResult(jsonObject); - selectTransferMethodPresenter = new SelectTransferMethodPresenter(view, transferMethodConfigurationRepository); + + String methodsResponseBody = externalResourceManager.getResourceContent("successful_tmc_keys_response.json"); + final JSONObject methodsJsonObject = new JSONObject(methodsResponseBody); + mResult = new TransferMethodConfigurationResult(methodsJsonObject); + + String userResponseBody = externalResourceManager.getResourceContent("user_response.json"); + final JSONObject userJsonObject = new JSONObject(userResponseBody); + mUser = new HyperwalletUser(userJsonObject); + + selectTransferMethodPresenter = new SelectTransferMethodPresenter(view, mTransferMethodConfigurationRepository, + mUserRepository); } @Test @@ -69,12 +82,23 @@ public void testLoadTransferMethodConfigurationKeys_loadsKeysIntoViewOnSuccess() public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback callback = (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[0]; - callback.onKeysLoaded(result); + callback.onKeysLoaded(mResult); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + UserRepository.LoadUserCallback userCallback = + (UserRepository.LoadUserCallback) invocation.getArguments()[0]; + userCallback.onUserLoaded(mUser); + return userCallback; + } + }).when(mUserRepository).loadUser(any( + UserRepository.LoadUserCallback.class)); + // Then selectTransferMethodPresenter.loadTransferMethodConfigurationKeys(false, "CA", "CAD"); @@ -100,12 +124,23 @@ public void testLoadTransferMethodConfigurationKeys_loadsKeysIntoViewOnSuccessIn public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback callback = (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[0]; - callback.onKeysLoaded(result); + callback.onKeysLoaded(mResult); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + UserRepository.LoadUserCallback userCallback = + (UserRepository.LoadUserCallback) invocation.getArguments()[0]; + userCallback.onUserLoaded(mUser); + return userCallback; + } + }).when(mUserRepository).loadUser(any( + UserRepository.LoadUserCallback.class)); + // Then selectTransferMethodPresenter.loadTransferMethodConfigurationKeys(false, "CA", "CAD"); @@ -133,9 +168,20 @@ public Object answer(InvocationOnMock invocation) { callback.onError(errors); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + UserRepository.LoadUserCallback userCallback = + (UserRepository.LoadUserCallback) invocation.getArguments()[0]; + userCallback.onUserLoaded(mUser); + return userCallback; + } + }).when(mUserRepository).loadUser(any( + UserRepository.LoadUserCallback.class)); + // Then selectTransferMethodPresenter.loadTransferMethodConfigurationKeys(false, "CA", "CAD"); @@ -155,12 +201,23 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback callback = (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[0]; - callback.onKeysLoaded(result); + callback.onKeysLoaded(mResult); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + UserRepository.LoadUserCallback userCallback = + (UserRepository.LoadUserCallback) invocation.getArguments()[0]; + userCallback.onUserLoaded(mUser); + return userCallback; + } + }).when(mUserRepository).loadUser(any( + UserRepository.LoadUserCallback.class)); + // Then selectTransferMethodPresenter.loadCurrency(false, "CA"); @@ -187,11 +244,21 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback callback = (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[0]; - callback.onKeysLoaded(result); + callback.onKeysLoaded(mResult); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + UserRepository.LoadUserCallback userCallback = + (UserRepository.LoadUserCallback) invocation.getArguments()[0]; + userCallback.onUserLoaded(mUser); + return userCallback; + } + }).when(mUserRepository).loadUser(any( + UserRepository.LoadUserCallback.class)); // Then selectTransferMethodPresenter.loadCurrency(false, "CA"); @@ -209,7 +276,7 @@ public Object answer(InvocationOnMock invocation) { @Test public void testLoadCurrency_loadsCurrenciesWhenRefreshingKeys() { selectTransferMethodPresenter.loadCurrency(true, "CA"); - verify(transferMethodConfigurationRepository, times(1)).refreshKeys(); + verify(mTransferMethodConfigurationRepository, times(1)).refreshKeys(); } @@ -227,9 +294,20 @@ public Object answer(InvocationOnMock invocation) { callback.onError(errors); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + UserRepository.LoadUserCallback userCallback = + (UserRepository.LoadUserCallback) invocation.getArguments()[0]; + userCallback.onUserLoaded(mUser); + return userCallback; + } + }).when(mUserRepository).loadUser(any( + UserRepository.LoadUserCallback.class)); + // Then selectTransferMethodPresenter.loadCurrency(false, "CA"); @@ -249,12 +327,24 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback callback = (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[0]; - callback.onKeysLoaded(result); + callback.onKeysLoaded(mResult); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + UserRepository.LoadUserCallback userCallback = + (UserRepository.LoadUserCallback) invocation.getArguments()[0]; + userCallback.onUserLoaded(mUser); + return userCallback; + } + }).when(mUserRepository).loadUser(any( + UserRepository.LoadUserCallback.class)); + + // Then selectTransferMethodPresenter.loadTransferMethodTypes(false, COUNTRY, CURRENCY); @@ -279,12 +369,24 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback callback = (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[0]; - callback.onKeysLoaded(result); + callback.onKeysLoaded(mResult); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + UserRepository.LoadUserCallback userCallback = + (UserRepository.LoadUserCallback) invocation.getArguments()[0]; + userCallback.onUserLoaded(mUser); + return userCallback; + } + }).when(mUserRepository).loadUser(any( + UserRepository.LoadUserCallback.class)); + + // Then selectTransferMethodPresenter.loadTransferMethodTypes(false, COUNTRY, CURRENCY); @@ -312,9 +414,20 @@ public Object answer(InvocationOnMock invocation) { callback.onError(errors); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + UserRepository.LoadUserCallback userCallback = + (UserRepository.LoadUserCallback) invocation.getArguments()[0]; + userCallback.onUserLoaded(mUser); + return userCallback; + } + }).when(mUserRepository).loadUser(any( + UserRepository.LoadUserCallback.class)); + // Then selectTransferMethodPresenter.loadTransferMethodTypes(false, "CA", "CAD"); @@ -335,9 +448,20 @@ public Object answer(InvocationOnMock invocation) { callback.onError(errors); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + UserRepository.LoadUserCallback userCallback = + (UserRepository.LoadUserCallback) invocation.getArguments()[0]; + userCallback.onUserLoaded(mUser); + return userCallback; + } + }).when(mUserRepository).loadUser(any( + UserRepository.LoadUserCallback.class)); + // Then selectTransferMethodPresenter.loadTransferMethodTypes(false, "CA", "CAD"); @@ -355,10 +479,10 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback callback = (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[0]; - callback.onKeysLoaded(result); + callback.onKeysLoaded(mResult); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any(TransferMethodConfigurationRepository. + }).when(mTransferMethodConfigurationRepository).getKeys(any(TransferMethodConfigurationRepository. LoadKeysCallback.class)); // Then @@ -387,10 +511,10 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback callback = (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[0]; - callback.onKeysLoaded(result); + callback.onKeysLoaded(mResult); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then @@ -415,10 +539,10 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback callback = (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[0]; - callback.onKeysLoaded(result); + callback.onKeysLoaded(mResult); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then @@ -448,7 +572,7 @@ public Object answer(InvocationOnMock invocation) { callback.onError(errors); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then @@ -471,7 +595,7 @@ public Object answer(InvocationOnMock invocation) { callback.onError(errors); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then @@ -498,10 +622,10 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback callback = (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[0]; - callback.onKeysLoaded(result); + callback.onKeysLoaded(mResult); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then @@ -526,10 +650,10 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback callback = (TransferMethodConfigurationRepository.LoadKeysCallback) invocation.getArguments()[0]; - callback.onKeysLoaded(result); + callback.onKeysLoaded(mResult); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then @@ -559,7 +683,7 @@ public Object answer(InvocationOnMock invocation) { callback.onError(errors); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then @@ -582,7 +706,7 @@ public Object answer(InvocationOnMock invocation) { callback.onError(errors); return callback; } - }).when(transferMethodConfigurationRepository).getKeys(any( + }).when(mTransferMethodConfigurationRepository).getKeys(any( TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then @@ -604,4 +728,50 @@ private HyperwalletErrors createErrors() { errors.add(error); return new HyperwalletErrors(errors); } + + @Test + public void testLoadMethods_whenLoadUserWithError_checkShowingErrors() { + + final HyperwalletError error = new HyperwalletError("test message", "TEST_CODE"); + List errorList = new ArrayList<>(); + errorList.add(error); + final HyperwalletErrors errors = new HyperwalletErrors(errorList); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) { + UserRepository.LoadUserCallback userCallback = + (UserRepository.LoadUserCallback) invocation.getArguments()[0]; + userCallback.onError(errors); + return userCallback; + } + }).when(mUserRepository).loadUser(any( + UserRepository.LoadUserCallback.class)); + when(view.isActive()).thenReturn(false); + // Then + selectTransferMethodPresenter.loadTransferMethodConfigurationKeys(false, "CA", "CAD"); + + verify(view, never()).showErrorLoadTransferMethodConfigurationKeys(ArgumentMatchers.anyList()); + + selectTransferMethodPresenter.loadCurrency(false, "CA"); + verify(view, never()).showErrorLoadCurrency(ArgumentMatchers.anyList()); + + selectTransferMethodPresenter.loadTransferMethodTypes(false, COUNTRY, CURRENCY); + verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); + + + // When + when(view.isActive()).thenReturn(true); + + // Then + selectTransferMethodPresenter.loadTransferMethodConfigurationKeys(false, "CA", "CAD"); + + verify(view).showErrorLoadTransferMethodConfigurationKeys(ArgumentMatchers.anyList()); + + selectTransferMethodPresenter.loadCurrency(false, "CA"); + verify(view).showErrorLoadCurrency(ArgumentMatchers.anyList()); + + selectTransferMethodPresenter.loadTransferMethodTypes(false, COUNTRY, CURRENCY); + verify(view).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); + } } diff --git a/ui/src/test/resources/user_response.json b/ui/src/test/resources/user_response.json new file mode 100644 index 000000000..e65074bef --- /dev/null +++ b/ui/src/test/resources/user_response.json @@ -0,0 +1,26 @@ +{ + "token": "usr-f9154016-94e8-4686-a840-075688ac07b5", + "status": "PRE_ACTIVATED", + "createdOn": "2017-10-30T22:15:45", + "clientUserId": "123456", + "profileType": "INDIVIDUAL", + "firstName": "Some", + "lastName": "Guy", + "dateOfBirth": "1991-01-01", + "email": "user+4satF1xV@hyperwallet.com", + "addressLine1": "575 Market Street", + "city": "San Francisco", + "stateProvince": "CA", + "country": "US", + "postalCode": "94105", + "language": "en", + "programToken": "prg-83836cdf-2ce2-4696-8bc5-f1b86077238c", + "links": [ + { + "params": { + "rel": "self" + }, + "href": "https://api.sandbox.hyperwallet.com/rest/v3/users/usr-f9154016-94e8-4686-a840-075688ac07b5" + } + ] +} \ No newline at end of file From cc1f54eae17f03ab6aac9db61ae0eeacdeb922d8 Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Mon, 13 May 2019 18:44:34 -0700 Subject: [PATCH 20/24] HW-52030 bugfix passing profile type to add transfer method activity --- .../AddTransferMethodFragment.java | 2 +- .../SelectTransferMethodContract.java | 5 +++-- .../SelectTransferMethodFragment.java | 9 ++++++--- .../SelectTransferMethodPresenter.java | 4 ++-- .../TransferMethodSelectionItem.java | 19 +++++++++++-------- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java index d52e6ad5f..2507c3eed 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java @@ -121,9 +121,9 @@ public static AddTransferMethodFragment newInstance(@NonNull String transferMeth addTransferMethodFragment.mCountry = transferMethodCountry; addTransferMethodFragment.mTransferMethodType = transferMethodType; addTransferMethodFragment.mCurrency = transferMethodCurrency; + addTransferMethodFragment.mTransferMethodProfileType = transferMethodProfileType; addTransferMethodFragment.mWidgetInputStateHashMap = new HashMap<>(1); addTransferMethodFragment.mTransferMethod = null; - addTransferMethodFragment.mTransferMethodProfileType = transferMethodProfileType; arguments.putString(ARGUMENT_TRANSFER_METHOD_COUNTRY, addTransferMethodFragment.mCountry); arguments.putString(ARGUMENT_TRANSFER_METHOD_CURRENCY, addTransferMethodFragment.mCurrency); diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodContract.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodContract.java index dc7538e82..ec4a747fb 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodContract.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodContract.java @@ -38,7 +38,8 @@ public interface SelectTransferMethodContract { interface View { - void showAddTransferMethod(String country, String currency, String transferMethodType); + void showAddTransferMethod(@NonNull final String country, @NonNull final String currency, + @NonNull final String transferMethodType, @NonNull final String profileType); void showErrorLoadTransferMethodConfigurationKeys(@NonNull final List errors); @@ -95,7 +96,7 @@ void loadTransferMethodTypes(final boolean forceUpdate, @NonNull final String co @NonNull final String currencyCode); void openAddTransferMethod(@NonNull final String country, @NonNull final String currency, - @NonNull final String transferMethodType); + @NonNull final String transferMethodType, @NonNull final String profileType); void loadCountrySelection(@NonNull final String countryCode); diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodFragment.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodFragment.java index 4b8c399d2..db873d8f7 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodFragment.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodFragment.java @@ -174,8 +174,9 @@ public void onClick(View v) { new TransferMethodSelectionItemListener() { @Override public void onTransferMethodSelected(TransferMethodSelectionItem transferMethodType) { - mPresenter.openAddTransferMethod(mSelectedCountryCode, mSelectedCurrencyCode, - transferMethodType.getTransferMethodType()); + mPresenter.openAddTransferMethod(transferMethodType.getCountry(), + transferMethodType.getCurrency(), + transferMethodType.getTransferMethodType(), transferMethodType.getProfileType()); } }); @@ -288,11 +289,13 @@ public void showCurrencySelectionDialog(@NonNull final TreeMap c } @Override - public void showAddTransferMethod(String country, String currency, String transferMethodType) { + public void showAddTransferMethod(@NonNull final String country, @NonNull final String currency, + @NonNull final String transferMethodType, @NonNull final String profileType) { Intent intent = new Intent(getActivity(), AddTransferMethodActivity.class); intent.putExtra(AddTransferMethodActivity.EXTRA_TRANSFER_METHOD_COUNTRY, country); intent.putExtra(AddTransferMethodActivity.EXTRA_TRANSFER_METHOD_CURRENCY, currency); intent.putExtra(AddTransferMethodActivity.EXTRA_TRANSFER_METHOD_TYPE, transferMethodType); + intent.putExtra(AddTransferMethodActivity.EXTRA_TRANSFER_METHOD_PROFILE_TYPE, profileType); getActivity().startActivityForResult(intent, AddTransferMethodActivity.REQUEST_CODE); } diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java index ae21c4d2e..4524e8ff0 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java @@ -204,8 +204,8 @@ public void onError(@NonNull HyperwalletErrors errors) { @Override public void openAddTransferMethod(@NonNull final String country, @NonNull final String currency, - @NonNull final String transferMethodType) { - mView.showAddTransferMethod(country, currency, transferMethodType); + @NonNull final String transferMethodType, @NonNull final String profileType) { + mView.showAddTransferMethod(country, currency, transferMethodType, profileType); } @Override diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodSelectionItem.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodSelectionItem.java index ca5e04c9e..d065d7ac1 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodSelectionItem.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodSelectionItem.java @@ -16,6 +16,8 @@ */ package com.hyperwallet.android.ui.transfermethod; +import androidx.annotation.NonNull; + import com.hyperwallet.android.model.meta.Fee; import java.util.List; @@ -27,14 +29,15 @@ public class TransferMethodSelectionItem { private final String mCurrency; private final List mFees; private final String mProcessingTime; - private final String mProfile; + private final String mProfileType; private final String mTransferMethodType; - public TransferMethodSelectionItem(String country, String currency, String profile, String transferMethodType, - String processingTime, List fees) { + public TransferMethodSelectionItem(@NonNull final String country, @NonNull final String currency, + @NonNull final String profileType, @NonNull final String transferMethodType, + @NonNull final String processingTime, @NonNull final List fees) { mCountry = country; mCurrency = currency; - mProfile = profile; + mProfileType = profileType; mTransferMethodType = transferMethodType; mProcessingTime = processingTime; mFees = fees; @@ -48,8 +51,8 @@ public String getCurrency() { return mCurrency; } - public String getProfile() { - return mProfile; + public String getProfileType() { + return mProfileType; } public String getTransferMethodType() { @@ -71,12 +74,12 @@ public boolean equals(Object o) { TransferMethodSelectionItem that = (TransferMethodSelectionItem) o; return Objects.equals(mCountry, that.mCountry) && Objects.equals(mCurrency, that.mCurrency) && - Objects.equals(mProfile, that.mProfile) && + Objects.equals(mProfileType, that.mProfileType) && Objects.equals(mTransferMethodType, that.mTransferMethodType); } @Override public int hashCode() { - return Objects.hash(mCountry, mCurrency, mProfile, mTransferMethodType); + return Objects.hash(mCountry, mCurrency, mProfileType, mTransferMethodType); } } From 9f050d112b7514a023eb04ff021106cedc157c2c Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Mon, 13 May 2019 20:05:48 -0700 Subject: [PATCH 21/24] HW-52030 fix unit and ui tests --- ui/build.gradle | 5 +- .../transfermethod/ui/BankAccountTest.java | 1 + .../transfermethod/ui/BankCardTest.java | 1 + .../android/transfermethod/ui/PayPalTest.java | 1 + .../ui/SelectTransferMethodTest.java | 21 ++++++ .../SelectTransferMethodPresenterTest.java | 71 ++++++++++--------- 6 files changed, 64 insertions(+), 36 deletions(-) diff --git a/ui/build.gradle b/ui/build.gradle index f7328be25..b31b0e293 100644 --- a/ui/build.gradle +++ b/ui/build.gradle @@ -22,10 +22,13 @@ android { } buildTypes { - dev { + release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } + debug { + testCoverageEnabled true + } } lintOptions { diff --git a/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/BankAccountTest.java b/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/BankAccountTest.java index 72594174c..3a48ac15e 100644 --- a/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/BankAccountTest.java +++ b/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/BankAccountTest.java @@ -84,6 +84,7 @@ protected Intent getActivityIntent() { intent.putExtra("TRANSFER_METHOD_TYPE", "BANK_ACCOUNT"); intent.putExtra("TRANSFER_METHOD_COUNTRY", "US"); intent.putExtra("TRANSFER_METHOD_CURRENCY", "USD"); + intent.putExtra("TRANSFER_METHOD_PROFILE_TYPE", "INDIVIDUAL"); return intent; } }; diff --git a/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/BankCardTest.java b/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/BankCardTest.java index b3cfa405e..8f05f330d 100644 --- a/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/BankCardTest.java +++ b/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/BankCardTest.java @@ -86,6 +86,7 @@ protected Intent getActivityIntent() { intent.putExtra("TRANSFER_METHOD_TYPE", "BANK_CARD"); intent.putExtra("TRANSFER_METHOD_COUNTRY", "US"); intent.putExtra("TRANSFER_METHOD_CURRENCY", "USD"); + intent.putExtra("TRANSFER_METHOD_PROFILE_TYPE", "INDIVIDUAL"); return intent; } }; diff --git a/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/PayPalTest.java b/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/PayPalTest.java index 40574449f..6bf0ec8bd 100644 --- a/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/PayPalTest.java +++ b/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/PayPalTest.java @@ -76,6 +76,7 @@ protected Intent getActivityIntent() { intent.putExtra("TRANSFER_METHOD_TYPE", "PAYPAL_ACCOUNT"); intent.putExtra("TRANSFER_METHOD_COUNTRY", "US"); intent.putExtra("TRANSFER_METHOD_CURRENCY", "USD"); + intent.putExtra("TRANSFER_METHOD_PROFILE_TYPE", "INDIVIDUAL"); return intent; } }; diff --git a/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/SelectTransferMethodTest.java b/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/SelectTransferMethodTest.java index 45ab1f01f..74ac12220 100644 --- a/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/SelectTransferMethodTest.java +++ b/ui/src/androidTest/java/com/hyperwallet/android/transfermethod/ui/SelectTransferMethodTest.java @@ -83,6 +83,8 @@ public void unregisterIdlingResource() { @Test public void testSelectTransferMethod_verifyCorrectLabelsDisplayed() { + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("user_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); @@ -108,6 +110,8 @@ public void testSelectTransferMethod_verifyCorrectLabelsDisplayed() { @Test public void testSelectTransferMethod_verifyCountrySelectionList() { + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("user_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); @@ -130,6 +134,8 @@ public void testSelectTransferMethod_verifyCountrySelectionList() { @Test public void testSelectTransferMethod_verifyCountrySelectionSearch() { + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("user_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_large_response.json")).mock(); @@ -149,6 +155,9 @@ public void testSelectTransferMethod_verifyCountrySelectionSearch() { @Test public void testSelectTransferMethod_verifyCurrencySelectionList() { + + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("user_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); @@ -172,6 +181,8 @@ public void testSelectTransferMethod_verifyCurrencySelectionList() { @Test public void testSelectTransferMethod_verifyTransferMethodsList() { + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("user_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); @@ -201,6 +212,8 @@ public void testSelectTransferMethod_verifyTransferMethodsList() { @Test public void testSelectTransferMethod_verifyTransferMethodsListEmptyFee() { + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("user_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_empty_fee_response.json")).mock(); @@ -223,6 +236,8 @@ public void testSelectTransferMethod_verifyTransferMethodsListEmptyFee() { @Test public void testSelectTransferMethod_verifyTransferMethodsListEmptyProcessing() { + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("user_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_empty_processing_response.json")).mock(); @@ -245,6 +260,8 @@ public void testSelectTransferMethod_verifyTransferMethodsListEmptyProcessing() @Test public void testSelectTransferMethod_verifyTransferMethodsListUpdatedOnSelectionChange() { + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("user_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); @@ -271,6 +288,8 @@ public void testSelectTransferMethod_verifyTransferMethodsListUpdatedOnSelection @Test public void testSelectTransferMethod_clickBankAccountOpensAddTransferMethodUi() { + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("user_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager @@ -286,6 +305,8 @@ public void testSelectTransferMethod_clickBankAccountOpensAddTransferMethodUi() @Test public void testSelectTransferMethod_clickBankCardOpensAddTransferMethodUi() { + mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager + .getResourceContent("user_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager .getResourceContent("successful_tmc_keys_response.json")).mock(); mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager diff --git a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java index 4c596a39a..6d1346ffd 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java @@ -13,6 +13,7 @@ import com.hyperwallet.android.model.HyperwalletError; import com.hyperwallet.android.model.HyperwalletErrors; +import com.hyperwallet.android.model.HyperwalletTransferMethod; import com.hyperwallet.android.model.HyperwalletUser; import com.hyperwallet.android.model.meta.TransferMethodConfigurationResult; import com.hyperwallet.android.ui.repository.TransferMethodConfigurationRepository; @@ -38,9 +39,7 @@ @RunWith(RobolectricTestRunner.class) public class SelectTransferMethodPresenterTest { - private static final String COUNTRY = "CA"; - private static final String CURRENCY = "CAD"; - private static final String BANK_ACCOUNT = "BANK_ACCOUNT"; + @Mock private SelectTransferMethodContract.View view; @@ -111,7 +110,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.anyList()); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -152,7 +151,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.anyList()); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -187,7 +186,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showTransferMethodTypes(ArgumentMatchers.anyList()); verify(view).showErrorLoadTransferMethodConfigurationKeys(eq(errors.getErrors())); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -229,7 +228,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.anyList()); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); verify(view, atLeastOnce()).showTransferMethodCountry(anyString()); } @@ -270,7 +269,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.anyList()); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -313,7 +312,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showTransferMethodTypes(ArgumentMatchers.anyList()); verify(view).showErrorLoadCurrency(eq(errors.getErrors())); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -346,7 +345,7 @@ public Object answer(InvocationOnMock invocation) { // Then - selectTransferMethodPresenter.loadTransferMethodTypes(false, COUNTRY, CURRENCY); + selectTransferMethodPresenter.loadTransferMethodTypes(false, "CA", "CAD"); verify(view).showTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadTransferMethodConfigurationKeys( @@ -355,7 +354,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.anyList()); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); verify(view, atLeastOnce()).showTransferMethodCountry(anyString()); verify(view, atLeastOnce()).showTransferMethodCurrency(anyString()); } @@ -388,7 +387,7 @@ public Object answer(InvocationOnMock invocation) { // Then - selectTransferMethodPresenter.loadTransferMethodTypes(false, COUNTRY, CURRENCY); + selectTransferMethodPresenter.loadTransferMethodTypes(false, "CA", "CAD"); verify(view, never()).showTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadTransferMethodConfigurationKeys( @@ -397,7 +396,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.anyList()); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -433,7 +432,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showTransferMethodTypes(ArgumentMatchers.anyList()); verify(view).showErrorLoadTransferMethodTypes(eq(errors.getErrors())); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -467,7 +466,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadTransferMethodTypes(eq(errors.getErrors())); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -486,9 +485,11 @@ public Object answer(InvocationOnMock invocation) { LoadKeysCallback.class)); // Then - selectTransferMethodPresenter.openAddTransferMethod(COUNTRY, CURRENCY, BANK_ACCOUNT); + selectTransferMethodPresenter.openAddTransferMethod("CA", "CAD", HyperwalletTransferMethod.TransferMethodTypes.BANK_ACCOUNT, + HyperwalletUser.ProfileTypes.INDIVIDUAL); - verify(view).showAddTransferMethod(COUNTRY, CURRENCY, BANK_ACCOUNT); + verify(view).showAddTransferMethod("CA", "CAD", HyperwalletTransferMethod.TransferMethodTypes.BANK_ACCOUNT, + HyperwalletUser.ProfileTypes.INDIVIDUAL); verify(view, never()).showErrorLoadTransferMethodConfigurationKeys( ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrency(ArgumentMatchers.anyList()); @@ -518,7 +519,7 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then - selectTransferMethodPresenter.loadCountrySelection(COUNTRY); + selectTransferMethodPresenter.loadCountrySelection("CA"); verify(view).showCountrySelectionDialog(any(TreeMap.class), anyString()); verify(view, never()).showErrorLoadTransferMethodConfigurationKeys( @@ -527,7 +528,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.anyList()); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -546,7 +547,7 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then - selectTransferMethodPresenter.loadCountrySelection(COUNTRY); + selectTransferMethodPresenter.loadCountrySelection("CA"); verify(view, never()).showCountrySelectionDialog(any(TreeMap.class), anyString()); verify(view, never()).showErrorLoadTransferMethodConfigurationKeys( @@ -555,7 +556,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.anyList()); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -576,11 +577,11 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then - selectTransferMethodPresenter.loadCountrySelection(COUNTRY); + selectTransferMethodPresenter.loadCountrySelection("CA"); verify(view, never()).showCountrySelectionDialog(any(TreeMap.class), anyString()); verify(view).showErrorLoadCountrySelection(eq(errors.getErrors())); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -599,7 +600,7 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then - selectTransferMethodPresenter.loadCountrySelection(COUNTRY); + selectTransferMethodPresenter.loadCountrySelection("CA"); verify(view, never()).showCountrySelectionDialog(any(TreeMap.class), anyString()); verify(view, never()).showErrorLoadTransferMethodConfigurationKeys( @@ -608,7 +609,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.anyList()); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -629,7 +630,7 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then - selectTransferMethodPresenter.loadCurrencySelection(COUNTRY, CURRENCY); + selectTransferMethodPresenter.loadCurrencySelection("CA", "CAD"); verify(view).showCurrencySelectionDialog(any(TreeMap.class), anyString()); verify(view, never()).showErrorLoadTransferMethodConfigurationKeys( @@ -638,7 +639,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.anyList()); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -657,7 +658,7 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then - selectTransferMethodPresenter.loadCurrencySelection(COUNTRY, CURRENCY); + selectTransferMethodPresenter.loadCurrencySelection("CA", "CAD"); verify(view, never()).showCurrencySelectionDialog(any(TreeMap.class), anyString()); verify(view, never()).showErrorLoadTransferMethodConfigurationKeys( @@ -666,7 +667,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.anyList()); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -687,11 +688,11 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then - selectTransferMethodPresenter.loadCurrencySelection(COUNTRY, CURRENCY); + selectTransferMethodPresenter.loadCurrencySelection("CA", "CAD"); verify(view, never()).showCurrencySelectionDialog(any(TreeMap.class), anyString()); verify(view).showErrorLoadCurrencySelection(eq(errors.getErrors())); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } @Test @@ -710,7 +711,7 @@ public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadKeysCallback.class)); // Then - selectTransferMethodPresenter.loadCurrencySelection(COUNTRY, CURRENCY); + selectTransferMethodPresenter.loadCurrencySelection("CA", "CAD"); verify(view, never()).showCurrencySelectionDialog(any(TreeMap.class), anyString()); verify(view, never()).showErrorLoadTransferMethodConfigurationKeys( @@ -719,7 +720,7 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCountrySelection(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadCurrencySelection(ArgumentMatchers.anyList()); - verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString()); + verify(view, never()).showAddTransferMethod(anyString(), anyString(), anyString(), anyString()); } private HyperwalletErrors createErrors() { @@ -756,7 +757,7 @@ public Object answer(InvocationOnMock invocation) { selectTransferMethodPresenter.loadCurrency(false, "CA"); verify(view, never()).showErrorLoadCurrency(ArgumentMatchers.anyList()); - selectTransferMethodPresenter.loadTransferMethodTypes(false, COUNTRY, CURRENCY); + selectTransferMethodPresenter.loadTransferMethodTypes(false, "CA", "CAD"); verify(view, never()).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); @@ -771,7 +772,7 @@ public Object answer(InvocationOnMock invocation) { selectTransferMethodPresenter.loadCurrency(false, "CA"); verify(view).showErrorLoadCurrency(ArgumentMatchers.anyList()); - selectTransferMethodPresenter.loadTransferMethodTypes(false, COUNTRY, CURRENCY); + selectTransferMethodPresenter.loadTransferMethodTypes(false, "CA", "CAD"); verify(view).showErrorLoadTransferMethodTypes(ArgumentMatchers.anyList()); } } From 2474310592990bd942e6675b4618eecdc3964c46 Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Mon, 13 May 2019 21:23:02 -0700 Subject: [PATCH 22/24] HW-52030 fix jacoco config after renaming build type --- ui/config/jacoco-settings.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/config/jacoco-settings.gradle b/ui/config/jacoco-settings.gradle index 1a29fbfa8..c810d1d89 100644 --- a/ui/config/jacoco-settings.gradle +++ b/ui/config/jacoco-settings.gradle @@ -35,7 +35,7 @@ def debugClassPaths = [ final def coverageSourceDirs = ["$project.projectDir/src/main/java/*"] -task jacocoTestReport(type: JacocoReport, dependsOn: 'testDevUnitTest') { +task jacocoTestReport(type: JacocoReport, dependsOn: 'testDebugUnitTest') { group = 'Reporting' description = 'Generate Jacoco coverage reports.' @@ -68,7 +68,7 @@ task jacocoTestCoverageVerification(type: JacocoCoverageVerification, dependsOn: ) additionalSourceDirs = files(coverageSourceDirs) sourceDirectories = files(coverageSourceDirs) - executionData = files("${buildDir}/jacoco/testDevUnitTest.exec") + executionData = files("${buildDir}/jacoco/testDebugUnitTest.exec") violationRules { setFailOnViolation(true) From 238cc80b7fa7252ec8e86cafe7cd8df4904d7e4d Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Tue, 14 May 2019 14:43:41 -0700 Subject: [PATCH 23/24] HW-52030 adding extra parameter --- .../main/java/com/hyperwallet/android/ui/HyperwalletUi.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/HyperwalletUi.java b/ui/src/main/java/com/hyperwallet/android/ui/HyperwalletUi.java index 666a2ef6c..db19f0c9c 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/HyperwalletUi.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/HyperwalletUi.java @@ -21,6 +21,7 @@ import static com.hyperwallet.android.ui.transfermethod.AddTransferMethodActivity.EXTRA_TRANSFER_METHOD_COUNTRY; import static com.hyperwallet.android.ui.transfermethod.AddTransferMethodActivity.EXTRA_TRANSFER_METHOD_CURRENCY; +import static com.hyperwallet.android.ui.transfermethod.AddTransferMethodActivity.EXTRA_TRANSFER_METHOD_PROFILE_TYPE; import static com.hyperwallet.android.ui.transfermethod.AddTransferMethodActivity.EXTRA_TRANSFER_METHOD_TYPE; import android.content.Context; @@ -87,11 +88,12 @@ public Intent getIntentSelectTransferMethodActivity(@NonNull final Context conte * @return an Intent with the data necessary to launch the {@link AddTransferMethodActivity} */ public Intent getIntentAddTransferMethodActivity(@NonNull final Context context, @NonNull final String country, - @NonNull final String currency, @NonNull final String transferMethodType) { + @NonNull final String currency, @NonNull final String transferMethodType, @NonNull final String profileType) { Intent intent = new Intent(context, AddTransferMethodActivity.class); intent.putExtra(EXTRA_TRANSFER_METHOD_COUNTRY, country); intent.putExtra(EXTRA_TRANSFER_METHOD_CURRENCY, currency); intent.putExtra(EXTRA_TRANSFER_METHOD_TYPE, transferMethodType); + intent.putExtra(EXTRA_TRANSFER_METHOD_PROFILE_TYPE, profileType); return intent; } From 40a45490c8eac05e7db8f9e085adc855e6e0e0b4 Mon Sep 17 00:00:00 2001 From: Flavio Mattos Date: Tue, 14 May 2019 14:48:40 -0700 Subject: [PATCH 24/24] HW-5203 update javadocs --- .../main/java/com/hyperwallet/android/ui/HyperwalletUi.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/HyperwalletUi.java b/ui/src/main/java/com/hyperwallet/android/ui/HyperwalletUi.java index db19f0c9c..4c5759831 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/HyperwalletUi.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/HyperwalletUi.java @@ -85,10 +85,13 @@ public Intent getIntentSelectTransferMethodActivity(@NonNull final Context conte * @param currency The transfer method currency code. ISO 4217 format. * @param transferMethodType The type of transfer method. For a complete list of transfer methods, see {@link * com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes} + * @param profileType The type of the account holder profile. For a complete list of options, see + * {@link com.hyperwallet.android.model.HyperwalletUser.ProfileTypes} * @return an Intent with the data necessary to launch the {@link AddTransferMethodActivity} */ public Intent getIntentAddTransferMethodActivity(@NonNull final Context context, @NonNull final String country, - @NonNull final String currency, @NonNull final String transferMethodType, @NonNull final String profileType) { + @NonNull final String currency, @NonNull final String transferMethodType, + @NonNull final String profileType) { Intent intent = new Intent(context, AddTransferMethodActivity.class); intent.putExtra(EXTRA_TRANSFER_METHOD_COUNTRY, country); intent.putExtra(EXTRA_TRANSFER_METHOD_CURRENCY, currency);