void updateCustomer(@NonNull Customer customer) { mCustomerSourceList.clear(); CustomerSource[] customerSources = new CustomerSource[customer.getSources().size()]; addCustomerSourceIfSupported(customer.getSources().toArray(customerSources)); String sourceId = customer.getDefaultSource(); if (sourceId == null) { updateSelectedIndex(NO_SELECTION); } else { setSelectedSource(sourceId); } notifyDataSetChanged(); }
@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()); }
if (!TextUtils.isEmpty(customer.getDefaultSource()) || customer.getSources().size() != 1) { updateAdapterWithCustomer(customer); return; CustomerSource customerSource = customer.getSources().get(0); if (customerSource == null || customerSource.getId() == null) {
@Test public void fromJson_whenCustomerHasApplePay_returnsCustomerWithoutApplePaySources() { Customer customer = Customer.fromString(createTestCustomerObjectWithApplePaySource()); assertNotNull(customer); assertEquals(2, customer.getSources().size()); // Note that filtering the apple_pay sources intentionally does not change the total // count value. assertEquals(Integer.valueOf(5), customer.getTotalCount()); }
private void createListFromCustomerSources() { setCommunicatingProgress(false); if (mCustomer == null) { return; } List<CustomerSource> customerSourceList = mCustomer.getSources(); if (!mRecyclerViewUpdated) { mMaskedCardAdapter = new MaskedCardAdapter(customerSourceList); // init the RecyclerView RecyclerView.LayoutManager linearLayoutManager = new LinearLayoutManager(this); mRecyclerView.setHasFixedSize(false); mRecyclerView.setLayoutManager(linearLayoutManager); mRecyclerView.setAdapter(mMaskedCardAdapter); mRecyclerViewUpdated = true; } else { mMaskedCardAdapter.setCustomerSourceList(customerSourceList); } String defaultSource = mCustomer.getDefaultSource(); if (!TextUtils.isEmpty(defaultSource)) { mMaskedCardAdapter.setSelectedSource(defaultSource); } mMaskedCardAdapter.notifyDataSetChanged(); }
assertEquals(updatedCustomer.getSources().get(0).getId(), stringArgumentCaptor.getValue()); assertNotNull(updateListener);
assertNotNull(customer); assertNotNull(customer.getDefaultSource()); List<CustomerSource> sourceList = customer.getSources();
@Test public void fromJson_whenCustomer_returnsExpectedCustomer() { Customer customer = Customer.fromString(TEST_CUSTOMER_OBJECT); assertNotNull(customer); assertEquals("cus_AQsHpvKfKwJDrF", customer.getId()); assertEquals("abc123", customer.getDefaultSource()); assertNull(customer.getShippingInformation()); assertNotNull(customer.getSources()); assertEquals("/v1/customers/cus_AQsHpvKfKwJDrF/sources", customer.getUrl()); assertFalse(customer.getHasMore()); assertEquals(Integer.valueOf(0), customer.getTotalCount()); }