### Question:
PaymentMethodsActivity extends AppCompatActivity { @VisibleForTesting void initializeCustomerSourceData() { Customer cachedCustomer = mCustomerSessionProxy == null ? CustomerSession.getInstance().getCachedCustomer() : mCustomerSessionProxy.getCachedCustomer(); if (cachedCustomer != null) { mCustomer = cachedCustomer; createListFromCustomerSources(); } else { getCustomerFromSession(); } }  static Intent newIntent(Context context); @Override boolean onPrepareOptionsMenu(Menu menu); @Override boolean onCreateOptionsMenu(Menu menu); @Override boolean onOptionsItemSelected(MenuItem item); static final String EXTRA_SELECTED_PAYMENT; }### Answer:
@Test public void onCreate_withCachedCustomer_showsUi() { Customer customer = Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT); when(mCustomerSessionProxy.getCachedCustomer()).thenReturn(customer); mActivityController.get().initializeCustomerSourceData(); assertNotNull(mProgressBar); assertNotNull(mRecyclerView); assertNotNull(mAddCardView); assertEquals(View.VISIBLE, mAddCardView.getVisibility()); assertEquals(View.VISIBLE, mRecyclerView.getVisibility()); assertEquals(View.GONE, mProgressBar.getVisibility()); }
@Test public void onCreate_withoutCacheCustomer_callsApiAndDisplaysProgressBarWhileWaiting() { Customer customer = Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT); assertNotNull(customer); when(mCustomerSessionProxy.getCachedCustomer()).thenReturn(null); ArgumentCaptor<CustomerSession.CustomerRetrievalListener> listenerArgumentCaptor = ArgumentCaptor.forClass(CustomerSession.CustomerRetrievalListener.class); assertNotNull(mProgressBar); assertNotNull(mRecyclerView); assertNotNull(mAddCardView); mActivityController.get().initializeCustomerSourceData(); verify(mCustomerSessionProxy).retrieveCurrentCustomer(listenerArgumentCaptor.capture()); assertEquals(View.VISIBLE, mProgressBar.getVisibility()); assertEquals(View.VISIBLE, mAddCardView.getVisibility()); assertEquals(View.VISIBLE, mRecyclerView.getVisibility()); CustomerSession.CustomerRetrievalListener listener = listenerArgumentCaptor.getValue(); assertNotNull(listener); listener.onCustomerRetrieved(customer); assertEquals(View.GONE, mProgressBar.getVisibility()); }
@Test public void onClickAddSourceView_withoutPaymentSessoin_launchesAddSourceActivityWithoutLog() { Customer customer = Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT); when(mCustomerSessionProxy.getCachedCustomer()).thenReturn(customer); mActivityController.get().initializeCustomerSourceData(); mAddCardView.performClick(); ShadowActivity.IntentForResult intentForResult = mShadowActivity.getNextStartedActivityForResult(); assertNotNull(intentForResult); assertEquals(AddSourceActivity.class.getName(), intentForResult.intent.getComponent().getClassName()); assertFalse(intentForResult.intent.hasExtra(EXTRA_PAYMENT_SESSION_ACTIVE)); }