From 65ae04a5bc060399ca1a204e89d1a3cf96c1d70e Mon Sep 17 00:00:00 2001 From: Michael Shafrir <45020849+mshafrir-stripe@users.noreply.github.com> Date: Wed, 10 Apr 2019 15:01:55 -0400 Subject: [PATCH] Remove CustomerSessionProxy from PaymentMethodsActivity (#861) * Remove CustomerSessionProxy from PaymentMethodsActivity The `CustomerSessionProxy` interface is not necessary and complicates the logic of `PaymentMethodsActivity` Instead, set a mock `CustomerSession` object as the current instance. --- .../android/view/PaymentMethodsActivity.java | 136 ++++++------------ .../stripe/android/CustomerSessionTest.java | 8 -- .../android/CustomerSessionTestHelper.java | 12 ++ .../view/PaymentMethodsActivityTest.java | 76 +++++----- 4 files changed, 99 insertions(+), 133 deletions(-) create mode 100644 stripe/src/test/java/com/stripe/android/CustomerSessionTestHelper.java diff --git a/stripe/src/main/java/com/stripe/android/view/PaymentMethodsActivity.java b/stripe/src/main/java/com/stripe/android/view/PaymentMethodsActivity.java index 795f797d1a8..3af0883d64c 100644 --- a/stripe/src/main/java/com/stripe/android/view/PaymentMethodsActivity.java +++ b/stripe/src/main/java/com/stripe/android/view/PaymentMethodsActivity.java @@ -44,13 +44,14 @@ public class PaymentMethodsActivity extends AppCompatActivity { static final int REQUEST_CODE_ADD_CARD = 700; private boolean mCommunicating; private Customer mCustomer; - private CustomerSessionProxy mCustomerSessionProxy; private MaskedCardAdapter mMaskedCardAdapter; private ProgressBar mProgressBar; private RecyclerView mRecyclerView; private boolean mRecyclerViewUpdated; private boolean mStartedFromPaymentSession; + private CustomerSession mCustomerSession; + /** * @deprecated use {@link PaymentMethodsActivityStarter#newIntent()} */ @@ -67,24 +68,26 @@ protected void onCreate(Bundle savedInstanceState) { mProgressBar = findViewById(R.id.payment_methods_progress_bar); mRecyclerView = findViewById(R.id.payment_methods_recycler); - View addCardView = findViewById(R.id.payment_methods_add_payment_container); + final View addCardView = findViewById(R.id.payment_methods_add_payment_container); - addCardView.setOnClickListener( - new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent addSourceIntent = AddSourceActivity.newIntent( - PaymentMethodsActivity.this, - false, - true); - if (mStartedFromPaymentSession) { - addSourceIntent.putExtra(EXTRA_PAYMENT_SESSION_ACTIVE, true); - } - startActivityForResult(addSourceIntent, REQUEST_CODE_ADD_CARD); - } - }); + mCustomerSession = CustomerSession.getInstance(); + mStartedFromPaymentSession = getIntent().hasExtra(EXTRA_PAYMENT_SESSION_ACTIVE); + + addCardView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(@NonNull View view) { + final Intent addSourceIntent = AddSourceActivity.newIntent( + PaymentMethodsActivity.this, + false, + true); + if (mStartedFromPaymentSession) { + addSourceIntent.putExtra(EXTRA_PAYMENT_SESSION_ACTIVE, true); + } + startActivityForResult(addSourceIntent, REQUEST_CODE_ADD_CARD); + } + }); - Toolbar toolbar = findViewById(R.id.payment_methods_toolbar); + final Toolbar toolbar = findViewById(R.id.payment_methods_toolbar); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -96,7 +99,6 @@ public void onClick(View view) { } // This prevents the first click from being eaten by the focus. addCardView.requestFocusFromTouch(); - mStartedFromPaymentSession = getIntent().hasExtra(EXTRA_PAYMENT_SESSION_ACTIVE); } @Override @@ -122,23 +124,18 @@ public void onError(int httpCode, @Nullable String errorMessage, setCommunicatingProgress(false); } }; - if (mCustomerSessionProxy == null) { - CustomerSession.getInstance().updateCurrentCustomer(listener); - } else { - mCustomerSessionProxy.updateCurrentCustomer(listener); - } + mCustomerSession.updateCurrentCustomer(listener); } } @Override public boolean onPrepareOptionsMenu(Menu menu) { final MenuItem saveItem = menu.findItem(R.id.action_save); - final Drawable compatIcon = - ViewUtils.getTintedIconWithAttribute( - this, - getTheme(), - R.attr.titleTextColor, - R.drawable.ic_checkmark); + final Drawable compatIcon = ViewUtils.getTintedIconWithAttribute( + this, + getTheme(), + R.attr.titleTextColor, + R.drawable.ic_checkmark); saveItem.setIcon(compatIcon); return super.onPrepareOptionsMenu(menu); } @@ -157,7 +154,7 @@ public boolean onOptionsItemSelected(MenuItem item) { setSelectionAndFinish(); return true; } else { - boolean handled = super.onOptionsItemSelected(item); + final boolean handled = super.onOptionsItemSelected(item); if (!handled) { onBackPressed(); } @@ -167,9 +164,7 @@ public boolean onOptionsItemSelected(MenuItem item) { @VisibleForTesting void initializeCustomerSourceData() { - final Customer cachedCustomer = mCustomerSessionProxy == null - ? CustomerSession.getInstance().getCachedCustomer() - : mCustomerSessionProxy.getCachedCustomer(); + final Customer cachedCustomer = mCustomerSession.getCachedCustomer(); if (cachedCustomer != null) { mCustomer = cachedCustomer; @@ -179,23 +174,11 @@ void initializeCustomerSourceData() { } } - @VisibleForTesting - void setCustomerSessionProxy(CustomerSessionProxy proxy) { - mCustomerSessionProxy = proxy; - } - private void initLoggingTokens() { - if (mCustomerSessionProxy == null) { - if (mStartedFromPaymentSession) { - CustomerSession.getInstance().addProductUsageTokenIfValid(TOKEN_PAYMENT_SESSION); - } - CustomerSession.getInstance().addProductUsageTokenIfValid(PAYMENT_METHODS_ACTIVITY); - } else { - if (mStartedFromPaymentSession) { - mCustomerSessionProxy.addProductUsageTokenIfValid(TOKEN_PAYMENT_SESSION); - } - mCustomerSessionProxy.addProductUsageTokenIfValid(PAYMENT_METHODS_ACTIVITY); + if (mStartedFromPaymentSession) { + mCustomerSession.addProductUsageTokenIfValid(TOKEN_PAYMENT_SESSION); } + mCustomerSession.addProductUsageTokenIfValid(PAYMENT_METHODS_ACTIVITY); } /** @@ -214,7 +197,7 @@ private void updateCustomerAndSetDefaultSourceIfNecessary(@NonNull Customer cust return; } - CustomerSession.CustomerRetrievalListener listener = + final CustomerSession.CustomerRetrievalListener listener = new CustomerSession.CustomerRetrievalListener() { @Override public void onCustomerRetrieved(@NonNull Customer customer) { @@ -236,7 +219,7 @@ public void onError(int httpCode, @Nullable String errorMessage, }; // We only activate this if there is a single source in the list - CustomerSource customerSource = customer.getSources().get(0); + final CustomerSource customerSource = customer.getSources().get(0); if (customerSource == null || customerSource.getId() == null) { // If the source ID is null for the only source we have, then there is nothing // we can do but update the display. This should not happen. It is only possible @@ -246,18 +229,11 @@ public void onError(int httpCode, @Nullable String errorMessage, return; } - if (mCustomerSessionProxy == null) { - CustomerSession.getInstance().setCustomerDefaultSource( - this, - customerSource.getId(), - customerSource.getSourceType(), - listener); - } else { - mCustomerSessionProxy.setCustomerDefaultSource( - customerSource.getId(), - customerSource.getSourceType(), - listener); - } + mCustomerSession.setCustomerDefaultSource( + this, + customerSource.getId(), + customerSource.getSourceType(), + listener); } private void createListFromCustomerSources() { @@ -320,11 +296,7 @@ public void onError(int httpCode, @Nullable String errorMessage, }; setCommunicatingProgress(true); - if (mCustomerSessionProxy == null) { - CustomerSession.getInstance().retrieveCurrentCustomer(listener); - } else { - mCustomerSessionProxy.retrieveCurrentCustomer(listener); - } + mCustomerSession.retrieveCurrentCustomer(listener); } private void setCommunicatingProgress(boolean communicating) { @@ -343,8 +315,8 @@ private void setSelectionAndFinish() { return; } - CustomerSource selectedSource = mMaskedCardAdapter.getSelectedSource(); - CustomerSession.CustomerRetrievalListener listener = + final CustomerSource selectedSource = mMaskedCardAdapter.getSelectedSource(); + final CustomerSession.CustomerRetrievalListener listener = new CustomerSession.CustomerRetrievalListener() { @Override public void onCustomerRetrieved(@NonNull Customer customer) { @@ -365,15 +337,8 @@ public void onError(int httpCode, @Nullable String errorMessage, if (selectedSource == null || selectedSource.getId() == null) { return; } - if (mCustomerSessionProxy == null) { - CustomerSession.getInstance().setCustomerDefaultSource( - this, selectedSource.getId(), selectedSource.getSourceType(), listener); - } else { - mCustomerSessionProxy.setCustomerDefaultSource( - selectedSource.getId(), - selectedSource.getSourceType(), - listener); - } + mCustomerSession.setCustomerDefaultSource( + this, selectedSource.getId(), selectedSource.getSourceType(), listener); setCommunicatingProgress(true); } @@ -401,19 +366,4 @@ private void updateAdapterWithCustomer(@NonNull Customer customer) { mMaskedCardAdapter.updateCustomer(customer); setCommunicatingProgress(false); } - - interface CustomerSessionProxy { - void addProductUsageTokenIfValid(@NonNull String token); - - @Nullable - Customer getCachedCustomer(); - - void retrieveCurrentCustomer(@NonNull CustomerSession.CustomerRetrievalListener listener); - - void setCustomerDefaultSource(@NonNull String sourceId, - @NonNull String sourceType, - @Nullable CustomerSession.CustomerRetrievalListener listener); - - void updateCurrentCustomer(@NonNull CustomerSession.CustomerRetrievalListener listener); - } } diff --git a/stripe/src/test/java/com/stripe/android/CustomerSessionTest.java b/stripe/src/test/java/com/stripe/android/CustomerSessionTest.java index 73e81935d3a..5ca40ce05dc 100644 --- a/stripe/src/test/java/com/stripe/android/CustomerSessionTest.java +++ b/stripe/src/test/java/com/stripe/android/CustomerSessionTest.java @@ -24,7 +24,6 @@ import com.stripe.android.view.PaymentFlowActivity; import org.json.JSONException; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -241,13 +240,6 @@ public Object answer(InvocationOnMock invocation) { }).when(mThreadPoolExecutor).execute(any(Runnable.class)); } - @After - public void teardown() { - LocalBroadcastManager.getInstance(mContext) - .unregisterReceiver(mBroadcastReceiver); - CustomerSession.endCustomerSession(); - } - @Test(expected = IllegalStateException.class) public void getInstance_withoutInitializing_throwsException() { CustomerSession.clearInstance(); diff --git a/stripe/src/test/java/com/stripe/android/CustomerSessionTestHelper.java b/stripe/src/test/java/com/stripe/android/CustomerSessionTestHelper.java new file mode 100644 index 00000000000..4ab1977ab24 --- /dev/null +++ b/stripe/src/test/java/com/stripe/android/CustomerSessionTestHelper.java @@ -0,0 +1,12 @@ +package com.stripe.android; + +import android.support.annotation.NonNull; + +public class CustomerSessionTestHelper { + private CustomerSessionTestHelper() { + } + + public static void setInstance(@NonNull CustomerSession customerSession) { + CustomerSession.setInstance(customerSession); + } +} diff --git a/stripe/src/test/java/com/stripe/android/view/PaymentMethodsActivityTest.java b/stripe/src/test/java/com/stripe/android/view/PaymentMethodsActivityTest.java index af0c79e5130..48c9bae3275 100644 --- a/stripe/src/test/java/com/stripe/android/view/PaymentMethodsActivityTest.java +++ b/stripe/src/test/java/com/stripe/android/view/PaymentMethodsActivityTest.java @@ -1,6 +1,7 @@ package com.stripe.android.view; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; @@ -9,6 +10,7 @@ import android.widget.ProgressBar; import com.stripe.android.CustomerSession; +import com.stripe.android.CustomerSessionTestHelper; import com.stripe.android.CustomerSessionTest; import com.stripe.android.R; import com.stripe.android.model.Customer; @@ -37,6 +39,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -83,7 +86,7 @@ public class PaymentMethodsActivityTest { " }\n" + "}"; - @Mock PaymentMethodsActivity.CustomerSessionProxy mCustomerSessionProxy; + @Mock private CustomerSession mCustomerSession; private PaymentMethodsActivity mPaymentMethodsActivity; private ProgressBar mProgressBar; @@ -94,9 +97,10 @@ public class PaymentMethodsActivityTest { @Before public void setup() { MockitoAnnotations.initMocks(this); + CustomerSessionTestHelper.setInstance(mCustomerSession); + mPaymentMethodsActivity = createActivity(createIntent() .putExtra(EXTRA_PROXY_DELAY, true)); - mPaymentMethodsActivity.setCustomerSessionProxy(mCustomerSessionProxy); mShadowActivity = Shadows.shadowOf(mPaymentMethodsActivity); mProgressBar = mPaymentMethodsActivity.findViewById(R.id.payment_methods_progress_bar); @@ -106,8 +110,8 @@ public void setup() { @Test public void onCreate_withCachedCustomer_showsUi() { - Customer customer = Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT); - when(mCustomerSessionProxy.getCachedCustomer()).thenReturn(customer); + when(mCustomerSession.getCachedCustomer()) + .thenReturn(Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT)); mPaymentMethodsActivity.initializeCustomerSourceData(); assertNotNull(mProgressBar); @@ -120,9 +124,10 @@ public void onCreate_withCachedCustomer_showsUi() { @Test public void onCreate_withoutCacheCustomer_callsApiAndDisplaysProgressBarWhileWaiting() { - Customer customer = Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT); + final Customer customer = + Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT); assertNotNull(customer); - when(mCustomerSessionProxy.getCachedCustomer()).thenReturn(null); + when(mCustomerSession.getCachedCustomer()).thenReturn(null); ArgumentCaptor listenerArgumentCaptor = ArgumentCaptor.forClass(CustomerSession.CustomerRetrievalListener.class); @@ -131,7 +136,7 @@ public void onCreate_withoutCacheCustomer_callsApiAndDisplaysProgressBarWhileWai assertNotNull(mAddCardView); mPaymentMethodsActivity.initializeCustomerSourceData(); - verify(mCustomerSessionProxy).retrieveCurrentCustomer(listenerArgumentCaptor.capture()); + verify(mCustomerSession).retrieveCurrentCustomer(listenerArgumentCaptor.capture()); assertEquals(View.VISIBLE, mProgressBar.getVisibility()); assertEquals(View.VISIBLE, mAddCardView.getVisibility()); assertEquals(View.VISIBLE, mRecyclerView.getVisibility()); @@ -146,14 +151,15 @@ public void onCreate_withoutCacheCustomer_callsApiAndDisplaysProgressBarWhileWai @Test public void onClickAddSourceView_withoutPaymentSessoin_launchesAddSourceActivityWithoutLog() { - Customer customer = Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT); - when(mCustomerSessionProxy.getCachedCustomer()).thenReturn(customer); + when(mCustomerSession.getCachedCustomer()) + .thenReturn(Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT)); mPaymentMethodsActivity.initializeCustomerSourceData(); mAddCardView.performClick(); ShadowActivity.IntentForResult intentForResult = mShadowActivity.getNextStartedActivityForResult(); assertNotNull(intentForResult); + assertNotNull(intentForResult.intent.getComponent()); assertEquals(AddSourceActivity.class.getName(), intentForResult.intent.getComponent().getClassName()); assertFalse(intentForResult.intent.hasExtra(EXTRA_PAYMENT_SESSION_ACTIVE)); @@ -161,22 +167,23 @@ public void onClickAddSourceView_withoutPaymentSessoin_launchesAddSourceActivity @Test public void onClickAddSourceView_whenStartedFromPaymentSession_launchesActivityWithLog() { - mPaymentMethodsActivity = createActivity(createIntent() + final PaymentMethodsActivity paymentMethodsActivity = createActivity(createIntent() .putExtra(EXTRA_PROXY_DELAY, true) .putExtra(EXTRA_PAYMENT_SESSION_ACTIVE, true)); - mPaymentMethodsActivity.setCustomerSessionProxy(mCustomerSessionProxy); - mShadowActivity = Shadows.shadowOf(mPaymentMethodsActivity); + mShadowActivity = Shadows.shadowOf(paymentMethodsActivity); - mAddCardView = mPaymentMethodsActivity.findViewById(R.id.payment_methods_add_payment_container); + mAddCardView = paymentMethodsActivity + .findViewById(R.id.payment_methods_add_payment_container); - Customer customer = Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT); - when(mCustomerSessionProxy.getCachedCustomer()).thenReturn(customer); - mPaymentMethodsActivity.initializeCustomerSourceData(); + when(mCustomerSession.getCachedCustomer()) + .thenReturn(Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT)); + paymentMethodsActivity.initializeCustomerSourceData(); mAddCardView.performClick(); - ShadowActivity.IntentForResult intentForResult = + final ShadowActivity.IntentForResult intentForResult = mShadowActivity.getNextStartedActivityForResult(); assertNotNull(intentForResult); + assertNotNull(intentForResult.intent.getComponent()); assertEquals(AddSourceActivity.class.getName(), intentForResult.intent.getComponent().getClassName()); assertTrue(intentForResult.intent.hasExtra(EXTRA_PAYMENT_SESSION_ACTIVE)); @@ -184,54 +191,56 @@ public void onClickAddSourceView_whenStartedFromPaymentSession_launchesActivityW @Test public void onActivityResult_withValidSource_refreshesCustomer() { - Customer customer = Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT); - when(mCustomerSessionProxy.getCachedCustomer()).thenReturn(customer); + when(mCustomerSession.getCachedCustomer()) + .thenReturn(Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT)); mPaymentMethodsActivity.initializeCustomerSourceData(); - Source source = Source.fromString(CardInputTestActivity.EXAMPLE_JSON_CARD_SOURCE); + final Source source = Source.fromString(CardInputTestActivity.EXAMPLE_JSON_CARD_SOURCE); assertNotNull(source); - Intent resultIntent = new Intent(); - resultIntent.putExtra(AddSourceActivity.EXTRA_NEW_SOURCE, source.toJson().toString()); + final Intent resultIntent = new Intent() + .putExtra(AddSourceActivity.EXTRA_NEW_SOURCE, source.toJson().toString()); ArgumentCaptor listenerArgumentCaptor = ArgumentCaptor.forClass(CustomerSession.CustomerRetrievalListener.class); mPaymentMethodsActivity.onActivityResult(REQUEST_CODE_ADD_CARD, RESULT_OK, resultIntent); assertEquals(View.VISIBLE, mProgressBar.getVisibility()); - verify(mCustomerSessionProxy).updateCurrentCustomer(listenerArgumentCaptor.capture()); + verify(mCustomerSession).updateCurrentCustomer(listenerArgumentCaptor.capture()); - CustomerSession.CustomerRetrievalListener listener = listenerArgumentCaptor.getValue(); + final CustomerSession.CustomerRetrievalListener listener = + listenerArgumentCaptor.getValue(); assertNotNull(listener); // Note - this doesn't make sense as the actual update; just testing that the customer // changes - Customer updatedCustomer = Customer.fromString(TEST_CUSTOMER_OBJECT_WITH_SOURCES); + final Customer updatedCustomer = Customer.fromString(TEST_CUSTOMER_OBJECT_WITH_SOURCES); assertNotNull(updatedCustomer); listener.onCustomerRetrieved(updatedCustomer); assertEquals(View.GONE, mProgressBar.getVisibility()); + assertNotNull(mRecyclerView.getAdapter()); assertEquals(2, mRecyclerView.getAdapter().getItemCount()); } @Test public void onActivityResult_whenOneSourceButNoSelection_updatesSelectedItem() { Customer customer = Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT); - when(mCustomerSessionProxy.getCachedCustomer()).thenReturn(customer); + when(mCustomerSession.getCachedCustomer()).thenReturn(customer); mPaymentMethodsActivity.initializeCustomerSourceData(); Source source = Source.fromString(CardInputTestActivity.EXAMPLE_JSON_CARD_SOURCE); assertNotNull(source); - Intent resultIntent = new Intent(); - resultIntent.putExtra(AddSourceActivity.EXTRA_NEW_SOURCE, source.toJson().toString()); + Intent resultIntent = new Intent() + .putExtra(AddSourceActivity.EXTRA_NEW_SOURCE, source.toJson().toString()); ArgumentCaptor listenerArgumentCaptor = ArgumentCaptor.forClass(CustomerSession.CustomerRetrievalListener.class); mPaymentMethodsActivity.onActivityResult(REQUEST_CODE_ADD_CARD, RESULT_OK, resultIntent); assertEquals(View.VISIBLE, mProgressBar.getVisibility()); - verify(mCustomerSessionProxy).updateCurrentCustomer(listenerArgumentCaptor.capture()); + verify(mCustomerSession).updateCurrentCustomer(listenerArgumentCaptor.capture()); CustomerSession.CustomerRetrievalListener listener = listenerArgumentCaptor.getValue(); assertNotNull(listener); @@ -250,7 +259,8 @@ public void onActivityResult_whenOneSourceButNoSelection_updatesSelectedItem() { // Progress bar stays visible because we have another server trip to make assertEquals(View.VISIBLE, mProgressBar.getVisibility()); - verify(mCustomerSessionProxy).setCustomerDefaultSource( + verify(mCustomerSession).setCustomerDefaultSource( + any(Context.class), stringArgumentCaptor.capture(), eq(Source.CARD), selectionCaptor.capture()); @@ -265,6 +275,7 @@ public void onActivityResult_whenOneSourceButNoSelection_updatesSelectedItem() { updateListener.onCustomerRetrieved(anotherCustomer); assertEquals(View.GONE, mProgressBar.getVisibility()); + assertNotNull(mRecyclerView.getAdapter()); assertEquals(2, mRecyclerView.getAdapter().getItemCount()); } @@ -278,7 +289,7 @@ public void onSaveMenuItem_sendsSelectionToApi_finishedWithExpectedResult() { assertEquals(2, sourceList.size()); assertEquals(customer.getDefaultSource(), sourceList.get(0).getId()); - when(mCustomerSessionProxy.getCachedCustomer()).thenReturn(customer); + when(mCustomerSession.getCachedCustomer()).thenReturn(customer); mPaymentMethodsActivity.initializeCustomerSourceData(); assertEquals(View.GONE, mProgressBar.getVisibility()); @@ -291,7 +302,8 @@ public void onSaveMenuItem_sendsSelectionToApi_finishedWithExpectedResult() { mPaymentMethodsActivity.onOptionsItemSelected(menuItem); - verify(mCustomerSessionProxy).setCustomerDefaultSource( + verify(mCustomerSession).setCustomerDefaultSource( + any(Context.class), selectionArgumentCaptor.capture(), eq(Source.CARD), listenerArgumentCaptor.capture());