Skip to content

Commit 18fccd7

Browse files
vshcherbyna-epamskoong
authored andcommitted
HW-52637 pay pal account second line (#44)
1 parent 87ee60b commit 18fccd7

File tree

4 files changed

+120
-31
lines changed

4 files changed

+120
-31
lines changed

ui/src/androidTest/java/com/hyperwallet/android/ui/transfermethod/ListTransferMethodTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public void testListTransferMethod_userHasMultipleTransferMethods() {
131131
onView(withId(R.id.list_transfer_method_item)).check(
132132
matches(atPosition(3, hasDescendant(withText(R.string.paper_check)))));
133133
onView(withId(R.id.list_transfer_method_item)).check(matches(atPosition(3, hasDescendant(withText("Canada")))));
134+
onView(withId(R.id.list_transfer_method_item)).check(
135+
matches(atPosition(3, hasDescendant(withText("")))));
134136
onView(withId(R.id.list_transfer_method_item)).check(
135137
matches(atPosition(3, hasDescendant(withDrawable(R.drawable.ic_three_dots_16dp)))));
136138

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

ui/src/main/java/com/hyperwallet/android/ui/transfermethod/ListTransferMethodFragment.java

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,11 @@
1616
*/
1717
package com.hyperwallet.android.ui.transfermethod;
1818

19-
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.BANK_ACCOUNT_ID;
20-
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.CARD_NUMBER;
2119
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.TRANSFER_METHOD_COUNTRY;
2220
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.TYPE;
23-
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.BANK_ACCOUNT;
24-
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.BANK_CARD;
25-
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.PREPAID_CARD;
26-
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.WIRE_ACCOUNT;
2721
import static com.hyperwallet.android.ui.transfermethod.TransferMethodUtils.getStringFontIcon;
2822
import static com.hyperwallet.android.ui.transfermethod.TransferMethodUtils.getStringResourceByName;
23+
import static com.hyperwallet.android.ui.transfermethod.TransferMethodUtils.getTransferMethodDetail;
2924

3025
import android.content.Context;
3126
import android.content.Intent;
@@ -65,7 +60,7 @@ public class ListTransferMethodFragment extends Fragment implements ListTransfer
6560

6661
static final String ARGUMENT_IS_TRANSFER_METHODS_RELOAD_NEEDED = "ARGUMENT_IS_TRANSFER_METHODS_RELOAD_NEEDED";
6762

68-
private static final int LAST_FOUR_DIGIT = 4;
63+
6964
private static final String ARGUMENT_TRANSFER_METHOD_LIST = "ARGUMENT_TRANSFER_METHOD_LIST";
7065

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

311306
@NonNull
312307
@Override
313-
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
308+
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int position) {
314309
LayoutInflater layout = LayoutInflater.from(viewGroup.getContext());
315310
View itemViewLayout = layout.inflate(R.layout.item_transfer_method_type, viewGroup, false);
316311
return new ViewHolder(itemViewLayout);
@@ -327,23 +322,6 @@ public void onViewRecycled(@NonNull ViewHolder holder) {
327322
holder.recycle();
328323
}
329324

330-
private String getAccountIdentifier(HyperwalletTransferMethod transferMethod) {
331-
String transferIdentification = "";
332-
switch (transferMethod.getField(TYPE)) {
333-
case BANK_ACCOUNT:
334-
case WIRE_ACCOUNT:
335-
transferIdentification = transferMethod.getField(BANK_ACCOUNT_ID);
336-
break;
337-
case BANK_CARD:
338-
case PREPAID_CARD:
339-
transferIdentification = transferMethod.getField(CARD_NUMBER);
340-
break;
341-
default: // none for paper check
342-
}
343-
return (transferIdentification.length() > LAST_FOUR_DIGIT
344-
? transferIdentification.substring(transferIdentification.length() - LAST_FOUR_DIGIT)
345-
: transferIdentification);
346-
}
347325

348326
@Override
349327
public int getItemCount() {
@@ -373,16 +351,20 @@ class ViewHolder extends RecyclerView.ViewHolder {
373351

374352

375353
void bind(@NonNull final HyperwalletTransferMethod transferMethod) {
354+
String type = transferMethod.getField(TYPE);
355+
final String transferMethodIdentification = getTransferMethodDetail(
356+
mTransferMethodIdentification.getContext(),
357+
transferMethod,
358+
type);
359+
376360
mTitle.setText(
377-
getStringResourceByName(mTitle.getContext(), transferMethod.getField(TYPE)));
361+
getStringResourceByName(mTitle.getContext(), type));
378362

379363
Locale locale = new Locale.Builder().setRegion(
380364
transferMethod.getField(TRANSFER_METHOD_COUNTRY)).build();
381-
mIcon.setText(getStringFontIcon(mIcon.getContext(), transferMethod.getField(TYPE)));
365+
mIcon.setText(getStringFontIcon(mIcon.getContext(), type));
382366
mTransferMethodCountry.setText(locale.getDisplayName());
383-
mTransferMethodIdentification.setText(mTransferMethodIdentification
384-
.getContext().getString(R.string.transfer_method_list_item_description,
385-
getAccountIdentifier(transferMethod)));
367+
mTransferMethodIdentification.setText(transferMethodIdentification);
386368

387369
mImageButton.setOnClickListener(new View.OnClickListener() {
388370
@Override

ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodUtils.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717
package com.hyperwallet.android.ui.transfermethod;
1818

19+
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.BANK_ACCOUNT_ID;
20+
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.CARD_NUMBER;
21+
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.EMAIL;
1922
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodFields.TYPE;
2023
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.BANK_ACCOUNT;
2124
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.BANK_CARD;
@@ -28,6 +31,8 @@
2831
import android.content.res.Resources;
2932

3033
import androidx.annotation.NonNull;
34+
import androidx.annotation.Nullable;
35+
import androidx.annotation.StringRes;
3136

3237
import com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod;
3338
import com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodType;
@@ -37,6 +42,8 @@
3742

3843
public class TransferMethodUtils {
3944

45+
private static final int LAST_FOUR_DIGIT = 4;
46+
4047
/**
4148
* Get string resource by TransferMethodType
4249
*
@@ -125,4 +132,52 @@ public static String getTransferMethodName(@NonNull final Context context,
125132

126133
return title;
127134
}
135+
136+
/**
137+
* Gets Transfer method identifier from the {@link HyperwalletTransferMethod} field
138+
* by a {@link TransferMethodType}.
139+
*
140+
* @param context Context
141+
* @param transferMethod HyperwalletTransferMethod
142+
* @param type TransferMethodType
143+
*/
144+
public static String getTransferMethodDetail(@NonNull Context context,
145+
@NonNull final HyperwalletTransferMethod transferMethod,
146+
@Nullable @TransferMethodType final String type) {
147+
if (type == null) {
148+
return "";
149+
}
150+
151+
switch (type) {
152+
case BANK_CARD:
153+
case PREPAID_CARD:
154+
return getFourDigitsIdentification(context,
155+
transferMethod,
156+
CARD_NUMBER,
157+
R.string.transfer_method_list_item_description);
158+
case BANK_ACCOUNT:
159+
case WIRE_ACCOUNT:
160+
return getFourDigitsIdentification(context, transferMethod, BANK_ACCOUNT_ID,
161+
R.string.transfer_method_list_item_description);
162+
case PAYPAL_ACCOUNT:
163+
final String transferIdentification = transferMethod.getField(EMAIL);
164+
return transferIdentification != null ? transferIdentification : "";
165+
default:
166+
return "";
167+
}
168+
}
169+
170+
private static String getFourDigitsIdentification(@NonNull final Context context,
171+
@NonNull final HyperwalletTransferMethod transferMethod,
172+
@NonNull @HyperwalletTransferMethod.TransferMethodFieldKey final String fieldKey,
173+
@StringRes final int stringResId) {
174+
final String transferIdentification = transferMethod.getField(fieldKey);
175+
176+
final String identificationText =
177+
transferIdentification != null && transferIdentification.length() > LAST_FOUR_DIGIT
178+
? transferIdentification.substring(transferIdentification.length() - LAST_FOUR_DIGIT)
179+
: "";
180+
181+
return context.getString(stringResId, identificationText);
182+
}
128183
}

ui/src/test/java/com/hyperwallet/android/ui/transfermethod/TransferMethodUtilsTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,28 @@
55
import static org.mockito.ArgumentMatchers.anyInt;
66
import static org.mockito.ArgumentMatchers.anyString;
77
import static org.mockito.ArgumentMatchers.eq;
8+
import static org.mockito.Mockito.never;
89
import static org.mockito.Mockito.times;
910
import static org.mockito.Mockito.verify;
1011
import static org.mockito.Mockito.when;
1112

13+
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.BANK_ACCOUNT;
1214
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.BANK_CARD;
15+
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.PAPER_CHECK;
16+
import static com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod.TransferMethodTypes.PAYPAL_ACCOUNT;
17+
import static com.hyperwallet.android.ui.transfermethod.TransferMethodUtils.getTransferMethodDetail;
1318

1419
import android.content.Context;
1520
import android.content.res.Resources;
1621

22+
import com.hyperwallet.android.model.transfermethod.HyperwalletBankAccount;
23+
import com.hyperwallet.android.model.transfermethod.HyperwalletBankCard;
1724
import com.hyperwallet.android.model.transfermethod.HyperwalletTransferMethod;
25+
import com.hyperwallet.android.model.transfermethod.PayPalAccount;
1826
import com.hyperwallet.android.ui.R;
1927
import com.hyperwallet.android.ui.rule.HyperwalletExternalResourceManager;
2028

29+
import org.hamcrest.CoreMatchers;
2130
import org.json.JSONException;
2231
import org.json.JSONObject;
2332
import org.junit.Before;
@@ -134,4 +143,44 @@ public void testGetStringFontIcon_returnsDefaultValue() {
134143
verify(mResources, times(2)).getIdentifier(anyString(), anyString(), anyString());
135144
verify(mContext, times(1)).getString(anyInt());
136145
}
146+
147+
@Test
148+
public void getTransferMethodDetail_returnsPayPalDetails() {
149+
HyperwalletTransferMethod transferMethod = new PayPalAccount.Builder().email(
150+
"sunshine.carreiro@hyperwallet.com").build();
151+
152+
String actual = getTransferMethodDetail(mContext, transferMethod, PAYPAL_ACCOUNT);
153+
assertThat(actual, is("sunshine.carreiro@hyperwallet.com"));
154+
}
155+
156+
@Test
157+
public void getTransferMethodDetail_returnsCardDetails() {
158+
HyperwalletTransferMethod transferMethod = new HyperwalletBankCard.Builder().cardNumber(
159+
"************0006").build();
160+
161+
when(mContext.getString(eq(R.string.transfer_method_list_item_description), eq("0006"))).thenReturn(
162+
"Ending on 0006");
163+
String actual = getTransferMethodDetail(mContext, transferMethod, BANK_CARD);
164+
assertThat(actual, is("Ending on 0006"));
165+
}
166+
167+
@Test
168+
public void getTransferMethodDetail_returnsBankAccountDetails() {
169+
HyperwalletTransferMethod transferMethod = new HyperwalletBankAccount.Builder().bankAccountId(
170+
"8017110254").build();
171+
172+
when(mContext.getString(eq(R.string.transfer_method_list_item_description), eq("0254"))).thenReturn(
173+
"Ending on 0254");
174+
String actual = getTransferMethodDetail(mContext, transferMethod, BANK_ACCOUNT);
175+
assertThat(actual, is("Ending on 0254"));
176+
}
177+
178+
@Test
179+
public void getTransferMethodDetail_returnsPaperCheckDetails() {
180+
HyperwalletTransferMethod transferMethod = new HyperwalletTransferMethod();
181+
182+
String actual = getTransferMethodDetail(mContext, transferMethod, PAPER_CHECK);
183+
assertThat(actual, CoreMatchers.is(""));
184+
verify(mContext, never()).getString(eq(R.string.transfer_method_list_item_description), anyString());
185+
}
137186
}

0 commit comments

Comments
 (0)