diff --git a/ui/src/androidTest/java/com/hyperwallet/android/ui/transfermethod/ListTransferMethodTest.java b/ui/src/androidTest/java/com/hyperwallet/android/ui/transfermethod/ListTransferMethodTest.java index 3f8412743..fc567b50e 100644 --- a/ui/src/androidTest/java/com/hyperwallet/android/ui/transfermethod/ListTransferMethodTest.java +++ b/ui/src/androidTest/java/com/hyperwallet/android/ui/transfermethod/ListTransferMethodTest.java @@ -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))))); @@ -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))))); diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/ListTransferMethodFragment.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/ListTransferMethodFragment.java index 34b93cf50..e38385540 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/ListTransferMethodFragment.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/ListTransferMethodFragment.java @@ -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; @@ -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; @@ -310,7 +305,7 @@ private static class ListTransferMethodAdapter extends RecyclerView.Adapter LAST_FOUR_DIGIT - ? transferIdentification.substring(transferIdentification.length() - LAST_FOUR_DIGIT) - : transferIdentification); - } @Override public int getItemCount() { @@ -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 diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodUtils.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodUtils.java index 127c21818..2566e479f 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodUtils.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodUtils.java @@ -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; @@ -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; @@ -37,6 +42,8 @@ public class TransferMethodUtils { + private static final int LAST_FOUR_DIGIT = 4; + /** * Get string resource by TransferMethodType * @@ -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); + } } diff --git a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/TransferMethodUtilsTest.java b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/TransferMethodUtilsTest.java index 186428ef3..7fd0bbece 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/TransferMethodUtilsTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/TransferMethodUtilsTest.java @@ -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; @@ -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()); + } }