@Test public void setCustomerSourceList_filtersOutNonCardSources() { List<CustomerSource> customerSourceList = new ArrayList<>(); CustomerSource cardCustomerSource = Mockito.mock(CustomerSource.class); Card card = Mockito.mock(Card.class); Mockito.when(cardCustomerSource.asCard()).thenReturn(card); CustomerSource nonCardCustomerSource = Mockito.mock(CustomerSource.class); customerSourceList.add(cardCustomerSource); customerSourceList.add(nonCardCustomerSource); mMaskedCardAdapter.setCustomerSourceList(customerSourceList); assertEquals(1, mMaskedCardAdapter.getItemCount()); } }
@Test public void updateCustomer_filtersOutNonCardSources() { List<CustomerSource> customerSourceList = new ArrayList<>(); CustomerSource cardCustomerSource = Mockito.mock(CustomerSource.class); Card card = Mockito.mock(Card.class); Mockito.when(cardCustomerSource.asCard()).thenReturn(card); CustomerSource nonCardCustomerSource = Mockito.mock(CustomerSource.class); customerSourceList.add(cardCustomerSource); customerSourceList.add(nonCardCustomerSource); Customer customer = Mockito.mock(Customer.class); Mockito.when(customer.getSources()).thenReturn(customerSourceList); mMaskedCardAdapter.updateCustomer(customer); assertEquals(1, mMaskedCardAdapter.getItemCount()); }
@Test public void addSources_onlyDisplaysCards() { CustomerSource cardSource = CustomerSource.fromString(CardInputTestActivity.EXAMPLE_JSON_CARD_SOURCE); CustomerSource bitcoinSource = CustomerSource.fromString(CardInputTestActivity.EXAMPLE_JSON_SOURCE_BITCOIN); mMaskedCardAdapter.addCustomerSourceIfSupported(cardSource, bitcoinSource); assertEquals(1, mMaskedCardAdapter.getItemCount()); verify(mAdapterDataObserver).onChanged(); }
@Test public void updateCustomer_removesExistingSourcesAndAddsAllCustomerSources() { CustomerSource cardSource = CustomerSource.fromString(CardInputTestActivity.EXAMPLE_JSON_CARD_SOURCE_SECOND); mMaskedCardAdapter.addCustomerSourceIfSupported(cardSource); assertEquals(1, mMaskedCardAdapter.getItemCount()); assertNull(mMaskedCardAdapter.getSelectedSource()); Customer customer = Customer.fromString(PaymentMethodsActivityTest.TEST_CUSTOMER_OBJECT_WITH_SOURCES); assertNotNull(customer); mMaskedCardAdapter.updateCustomer(customer); assertEquals(2, mMaskedCardAdapter.getItemCount()); assertNotNull(mMaskedCardAdapter.getSelectedSource()); assertEquals(customer.getDefaultSource(), mMaskedCardAdapter.getSelectedSource().getId()); verify(mAdapterDataObserver, times(4)).onChanged(); }
@Test public void setSelection_changesSelection() { CustomerSource cardSource = CustomerSource.fromString(CardInputTestActivity.EXAMPLE_JSON_CARD_SOURCE); CustomerSource secondCardSource = CustomerSource.fromString(CardInputTestActivity.EXAMPLE_JSON_CARD_SOURCE_SECOND); mMaskedCardAdapter.addCustomerSourceIfSupported(cardSource, secondCardSource); assertEquals(2, mMaskedCardAdapter.getItemCount()); verify(mAdapterDataObserver, times(1)).onChanged(); assertNull(mMaskedCardAdapter.getSelectedSource()); assertNotNull(secondCardSource); assertNotNull(secondCardSource.getId()); mMaskedCardAdapter.setSelectedSource(secondCardSource.getId()); verify(mAdapterDataObserver, times(2)).onChanged(); assertNotNull(mMaskedCardAdapter.getSelectedSource()); assertEquals(secondCardSource.getId(), mMaskedCardAdapter.getSelectedSource().getId()); }