Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
169175c
HW-52030 Added User Repository
azakrevska-epam May 3, 2019
23f6c25
HW-52030. Added User member
azakrevska-epam May 6, 2019
bc20273
HW-52030. Added user refresh
azakrevska-epam May 7, 2019
3630e41
HW-52030 Small fixes after review (license & test renaming)
azakrevska-epam May 10, 2019
f31e1c0
HW-52030 Added refresh user test
azakrevska-epam May 10, 2019
ee8cbd5
HW-52030. Fixed typo
azakrevska-epam May 10, 2019
fdc130d
update agreement
fmattos-hw May 10, 2019
70badbd
update agreement
fmattos-hw May 10, 2019
bda1289
renaming tests
fmattos-hw May 10, 2019
32062a6
HW-52030 Added User Repository
azakrevska-epam May 3, 2019
b0106b7
HW-52030. Added User member
azakrevska-epam May 6, 2019
2694fb2
HW-52030. Added user refresh
azakrevska-epam May 7, 2019
02ea8cb
HW-52030 Small fixes after review (license & test renaming)
azakrevska-epam May 10, 2019
de86116
HW-52030 Added refresh user test
azakrevska-epam May 10, 2019
3beba73
HW-52030. Fixed typo
azakrevska-epam May 10, 2019
025d64d
update agreement
fmattos-hw May 10, 2019
09cc06a
update agreement
fmattos-hw May 10, 2019
7e6e307
renaming tests
fmattos-hw May 10, 2019
d9f12d2
Merge branch 'feature/HW-52030-user-repository' of https://github.com…
azakrevska-epam May 13, 2019
6de4ab0
HW-52031. Update select method presenter (#3)
azakrevska-epam May 13, 2019
cc1f54e
HW-52030 bugfix passing profile type to add transfer method activity
fmattos-hw May 14, 2019
9f050d1
HW-52030 fix unit and ui tests
fmattos-hw May 14, 2019
2474310
HW-52030 fix jacoco config after renaming build type
fmattos-hw May 14, 2019
238cc80
HW-52030 adding extra parameter
fmattos-hw May 14, 2019
40a4549
HW-5203 update javadocs
fmattos-hw May 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ android {
}

buildTypes {
dev {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}

lintOptions {
Expand Down
4 changes: 2 additions & 2 deletions ui/config/jacoco-settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,14 +85,18 @@ 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 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -52,6 +54,10 @@ public TransferMethodRepository getTransferMethodRepository() {
return mTransferMethodRepository;
}

public UserRepository getUserRepository() {
return mUserRepository;
}

public static void clearInstance() {
sInstance = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FieldMapKey, HyperwalletTransferMethodConfigurationFieldResult> mFieldMap;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -146,14 +147,15 @@ 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(
fieldMapKey);
// 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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;

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);

/**
* Set user to null
*/
void refreshUser();

/**
* Callback interface that responses to action when invoked to
* Load User information
* <p>
* 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(@NonNull final HyperwalletUser user);

void onError(@NonNull final HyperwalletErrors errors);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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;

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();
private HyperwalletUser mUser;

@VisibleForTesting
Hyperwallet getHyperwallet() {
return Hyperwallet.getDefault();
}

@Override
public void loadUser(@NonNull final LoadUserCallback callback) {
if (mUser == null) {
getHyperwallet().getUser(new HyperwalletListener<HyperwalletUser>() {
@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);
}
}

@Override
public void refreshUser() {
mUser = null;
}
}
Loading