Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public void testListTransferMethod_userHasMultipleTransferMethods() {
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(3, hasDescendant(withText(R.string.paper_check)))));
onView(withId(R.id.list_transfer_method_item)).check(matches(atPosition(3, hasDescendant(withText("Canada")))));
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(3, hasDescendant(withText("")))));
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(3, hasDescendant(withDrawable(R.drawable.ic_three_dots_16dp)))));

Expand All @@ -150,7 +152,8 @@ public void testListTransferMethod_userHasMultipleTransferMethods() {
matches(atPosition(5, hasDescendant(withText(R.string.paypal_account)))));
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(5, hasDescendant(withText("United States")))));
//TODO: Try to check for non existence of transfer_method_type_description_2
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(5, hasDescendant(withText("honey.thigpen@ukbuilder.com")))));
onView(withId(R.id.list_transfer_method_item)).check(
matches(atPosition(5, hasDescendant(withDrawable(R.drawable.ic_three_dots_16dp)))));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@
*/
package com.hyperwallet.android.ui.transfermethod;

import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.BANK_ACCOUNT_ID;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.CARD_NUMBER;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_COUNTRY;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.TYPE;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.BANK_ACCOUNT;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.BANK_CARD;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.PREPAID_CARD;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.WIRE_ACCOUNT;
import static com.hyperwallet.android.ui.transfermethod.TransferMethodUtils.getStringFontIcon;
import static com.hyperwallet.android.ui.transfermethod.TransferMethodUtils.getStringResourceByName;
import static com.hyperwallet.android.ui.transfermethod.TransferMethodUtils.getTransferMethodDetail;

import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -65,7 +60,7 @@ public class ListTransferMethodFragment extends Fragment implements ListTransfer

static final String ARGUMENT_IS_TRANSFER_METHODS_RELOAD_NEEDED = "ARGUMENT_IS_TRANSFER_METHODS_RELOAD_NEEDED";

private static final int LAST_FOUR_DIGIT = 4;

private static final String ARGUMENT_TRANSFER_METHOD_LIST = "ARGUMENT_TRANSFER_METHOD_LIST";

private View mEmptyListView;
Expand Down Expand Up @@ -310,7 +305,7 @@ private static class ListTransferMethodAdapter extends RecyclerView.Adapter<List

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int position) {
LayoutInflater layout = LayoutInflater.from(viewGroup.getContext());
View itemViewLayout = layout.inflate(R.layout.item_transfer_method_type, viewGroup, false);
return new ViewHolder(itemViewLayout);
Expand All @@ -327,23 +322,6 @@ public void onViewRecycled(@NonNull ViewHolder holder) {
holder.recycle();
}

private String getAccountIdentifier(HyperwalletTransferMethod transferMethod) {
String transferIdentification = "";
switch (transferMethod.getField(TYPE)) {
case BANK_ACCOUNT:
case WIRE_ACCOUNT:
transferIdentification = transferMethod.getField(BANK_ACCOUNT_ID);
break;
case BANK_CARD:
case PREPAID_CARD:
transferIdentification = transferMethod.getField(CARD_NUMBER);
break;
default: // none for paper check
}
return (transferIdentification.length() > LAST_FOUR_DIGIT
? transferIdentification.substring(transferIdentification.length() - LAST_FOUR_DIGIT)
: transferIdentification);
}

@Override
public int getItemCount() {
Expand Down Expand Up @@ -373,16 +351,20 @@ class ViewHolder extends RecyclerView.ViewHolder {


void bind(@NonNull final HyperwalletTransferMethod transferMethod) {
String type = transferMethod.getField(TYPE);
final String transferMethodIdentification = getTransferMethodDetail(
mTransferMethodIdentification.getContext(),
transferMethod,
type);

mTitle.setText(
getStringResourceByName(mTitle.getContext(), transferMethod.getField(TYPE)));
getStringResourceByName(mTitle.getContext(), type));

Locale locale = new Locale.Builder().setRegion(
transferMethod.getField(TRANSFER_METHOD_COUNTRY)).build();
mIcon.setText(getStringFontIcon(mIcon.getContext(), transferMethod.getField(TYPE)));
mIcon.setText(getStringFontIcon(mIcon.getContext(), type));
mTransferMethodCountry.setText(locale.getDisplayName());
mTransferMethodIdentification.setText(mTransferMethodIdentification
.getContext().getString(R.string.transfer_method_list_item_description,
getAccountIdentifier(transferMethod)));
mTransferMethodIdentification.setText(transferMethodIdentification);

mImageButton.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package com.hyperwallet.android.ui.transfermethod;

import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.BANK_ACCOUNT_ID;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.CARD_NUMBER;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.EMAIL;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.TYPE;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.BANK_ACCOUNT;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.BANK_CARD;
Expand All @@ -28,6 +31,8 @@
import android.content.res.Resources;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod;
import com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodType;
Expand All @@ -37,6 +42,8 @@

public class TransferMethodUtils {

private static final int LAST_FOUR_DIGIT = 4;

/**
* Get string resource by TransferMethodType
*
Expand Down Expand Up @@ -125,4 +132,52 @@ public static String getTransferMethodName(@NonNull final Context context,

return title;
}

/**
* Gets Transfer method identifier from the {@link HyperwalletTransferMethod} field
* by a {@link TransferMethodType}.
*
* @param context Context
* @param transferMethod HyperwalletTransferMethod
* @param type TransferMethodType
*/
public static String getTransferMethodDetail(@NonNull Context context,
@NonNull final HyperwalletTransferMethod transferMethod,
@Nullable @TransferMethodType final String type) {
if (type == null) {
return "";
}

switch (type) {
case BANK_CARD:
case PREPAID_CARD:
return getFourDigitsIdentification(context,
transferMethod,
CARD_NUMBER,
R.string.transfer_method_list_item_description);
case BANK_ACCOUNT:
case WIRE_ACCOUNT:
return getFourDigitsIdentification(context, transferMethod, BANK_ACCOUNT_ID,
R.string.transfer_method_list_item_description);
case PAYPAL_ACCOUNT:
final String transferIdentification = transferMethod.getField(EMAIL);
return transferIdentification != null ? transferIdentification : "";
default:
return "";
}
}

private static String getFourDigitsIdentification(@NonNull final Context context,
@NonNull final HyperwalletTransferMethod transferMethod,
@NonNull @HyperwalletTransferMethod.TransferMethodFieldKey final String fieldKey,
@StringRes final int stringResId) {
final String transferIdentification = transferMethod.getField(fieldKey);

final String identificationText =
transferIdentification != null && transferIdentification.length() > LAST_FOUR_DIGIT
? transferIdentification.substring(transferIdentification.length() - LAST_FOUR_DIGIT)
: "";

return context.getString(stringResId, identificationText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,28 @@
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.BANK_ACCOUNT;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.BANK_CARD;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.PAPER_CHECK;
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT;
import static com.hyperwallet.android.ui.transfermethod.TransferMethodUtils.getTransferMethodDetail;

import android.content.Context;
import android.content.res.Resources;

import com.hyperwallet.android.model.transfermethod.HyperwalletBankAccount;
import com.hyperwallet.android.model.transfermethod.HyperwalletBankCard;
import com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod;
import com.hyperwallet.android.model.transfermethod.PayPalAccount;
import com.hyperwallet.android.ui.R;
import com.hyperwallet.android.ui.rule.HyperwalletExternalResourceManager;

import org.hamcrest.CoreMatchers;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
Expand Down Expand Up @@ -134,4 +143,44 @@ public void testGetStringFontIcon_returnsDefaultValue() {
verify(mResources, times(2)).getIdentifier(anyString(), anyString(), anyString());
verify(mContext, times(1)).getString(anyInt());
}

@Test
public void getTransferMethodDetail_returnsPayPalDetails() {
HyperwalletTransferMethod transferMethod = new PayPalAccount.Builder().email(
"sunshine.carreiro@hyperwallet.com").build();

String actual = getTransferMethodDetail(mContext, transferMethod, PAYPAL_ACCOUNT);
assertThat(actual, is("sunshine.carreiro@hyperwallet.com"));
}

@Test
public void getTransferMethodDetail_returnsCardDetails() {
HyperwalletTransferMethod transferMethod = new HyperwalletBankCard.Builder().cardNumber(
"************0006").build();

when(mContext.getString(eq(R.string.transfer_method_list_item_description), eq("0006"))).thenReturn(
"Ending on 0006");
String actual = getTransferMethodDetail(mContext, transferMethod, BANK_CARD);
assertThat(actual, is("Ending on 0006"));
}

@Test
public void getTransferMethodDetail_returnsBankAccountDetails() {
HyperwalletTransferMethod transferMethod = new HyperwalletBankAccount.Builder().bankAccountId(
"8017110254").build();

when(mContext.getString(eq(R.string.transfer_method_list_item_description), eq("0254"))).thenReturn(
"Ending on 0254");
String actual = getTransferMethodDetail(mContext, transferMethod, BANK_ACCOUNT);
assertThat(actual, is("Ending on 0254"));
}

@Test
public void getTransferMethodDetail_returnsPaperCheckDetails() {
HyperwalletTransferMethod transferMethod = new HyperwalletTransferMethod();

String actual = getTransferMethodDetail(mContext, transferMethod, PAPER_CHECK);
assertThat(actual, CoreMatchers.is(""));
verify(mContext, never()).getString(eq(R.string.transfer_method_list_item_description), anyString());
}
}