Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -5,6 +5,8 @@
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.intent.Intents.intended;
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra;
import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant;
import static androidx.test.espresso.matcher.ViewMatchers.hasSibling;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
Expand All @@ -19,13 +21,22 @@

import static java.net.HttpURLConnection.HTTP_OK;

import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.BANK_ACCOUNT;
import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodTypes.BANK_CARD;
import static com.hyperwallet.android.model.HyperwalletUser.ProfileTypes.BUSINESS;
import static com.hyperwallet.android.model.HyperwalletUser.ProfileTypes.INDIVIDUAL;
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 static com.hyperwallet.android.util.EspressoUtils.atPosition;
import static com.hyperwallet.android.util.EspressoUtils.withDrawable;

import android.widget.TextView;

import androidx.test.espresso.IdlingRegistry;
import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;
Expand Down Expand Up @@ -57,6 +68,9 @@ public class SelectTransferMethodTest {
@Rule
public ActivityTestRule<SelectTransferMethodActivity> mActivityTestRule =
new ActivityTestRule<>(SelectTransferMethodActivity.class, true, false);
@Rule
public IntentsTestRule<SelectTransferMethodActivity> mIntentsTestRule =
new IntentsTestRule<>(SelectTransferMethodActivity.class, true, false);

@Before
public void setup() {
Expand All @@ -83,6 +97,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 +124,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 +148,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 +169,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 +195,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 +226,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 +250,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 +274,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 @@ -269,8 +300,48 @@ public void testSelectTransferMethod_verifyTransferMethodsListUpdatedOnSelection

}

@Test
public void testSelectTransferMethod_verifyIntentIndividualUser() {
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
.getResourceContent("successful_tmc_fields_response.json")).mock();

mIntentsTestRule.launchActivity(null);

onView(withId(R.id.select_transfer_method_types_list))
.perform(RecyclerViewActions.actionOnItem(withChild(withText(R.string.bank_account)), click()));
intended(hasExtra(EXTRA_TRANSFER_METHOD_PROFILE_TYPE, INDIVIDUAL));
intended(hasExtra(EXTRA_TRANSFER_METHOD_COUNTRY, "US"));
intended(hasExtra(EXTRA_TRANSFER_METHOD_CURRENCY, "USD"));
intended(hasExtra(EXTRA_TRANSFER_METHOD_TYPE, BANK_ACCOUNT));
}

@Test
public void testSelectTransferMethod_verifyIntentBusinessUser() {
mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager
.getResourceContent("user_business_response.json")).mock();
mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager
.getResourceContent("successful_tmc_keys_response.json")).mock();
mMockWebServer.mockResponse().withHttpResponseCode(HTTP_OK).withBody(sResourceManager
.getResourceContent("successful_tmc_fields_response.json")).mock();

mIntentsTestRule.launchActivity(null);

onView(withId(R.id.select_transfer_method_types_list))
.perform(RecyclerViewActions.actionOnItem(withChild(withText(R.string.bank_card)), click()));
intended(hasExtra(EXTRA_TRANSFER_METHOD_PROFILE_TYPE, BUSINESS));
intended(hasExtra(EXTRA_TRANSFER_METHOD_COUNTRY, "US"));
intended(hasExtra(EXTRA_TRANSFER_METHOD_CURRENCY, "USD"));
intended(hasExtra(EXTRA_TRANSFER_METHOD_TYPE, BANK_CARD));
}

@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 +357,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
Loading