@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 getSourceType_whenSourceThatIsNotCard_returnsSourceType() { CustomerSource alipaySource = CustomerSource.fromString(EXAMPLE_ALIPAY_SOURCE); assertNotNull(alipaySource); assertEquals(Source.ALIPAY, alipaySource.getSourceType()); } }
CustomerSource applePayCard = CustomerSource.fromString(JSON_APPLE_PAY_CARD); assertNotNull(applePayCard); sourcesArray.put(applePayCard.toJson());
@Test public void fromJson_whenSource_createsCustomerSourceData() { CustomerSource sourceData = CustomerSource.fromString(EXAMPLE_JSON_SOURCE_WITHOUT_NULLS); assertNotNull(sourceData); assertNotNull(sourceData.asSource()); assertEquals("src_19t3xKBZqEXluyI4uz2dxAfQ", sourceData.getId()); }
@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()); }
@Test public void setCustomerSource_withNonCardSource_setsNoData() { CustomerSource customerSource = CustomerSource.fromString(EXAMPLE_JSON_SOURCE_BITCOIN); assertNotNull(customerSource); assertNotNull(customerSource.asSource()); mMaskedCardView.setCustomerSource(customerSource); assertNull(mMaskedCardView.getCardBrand()); assertNull(mMaskedCardView.getLast4()); assertFalse(mMaskedCardView.isSelected()); }
@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 setCustomerSource_withCardSource_setsCorrectData() { CustomerSource customerSource = CustomerSource.fromString(EXAMPLE_JSON_CARD_SOURCE); assertNotNull(customerSource); assertNotNull(customerSource.asSource()); mMaskedCardView.setCustomerSource(customerSource); assertEquals(Card.VISA, mMaskedCardView.getCardBrand()); assertEquals("4242", mMaskedCardView.getLast4()); assertFalse(mMaskedCardView.isSelected()); }
@Test public void setSelected_changesCheckMarkVisibility() { CustomerSource customerSource = CustomerSource.fromString(JSON_CARD); assertNotNull(customerSource); mMaskedCardView.setCustomerSource(customerSource); assertFalse(mMaskedCardView.isSelected()); assertEquals(View.INVISIBLE, mSelectedImageView.getVisibility()); mMaskedCardView.setSelected(true); assertTrue(mMaskedCardView.isSelected()); assertEquals(View.VISIBLE, mSelectedImageView.getVisibility()); }
@Test public void setCustomerSource_withCardObject_setsCorrectData() { CustomerSource customerSource = CustomerSource.fromString(JSON_CARD); assertNotNull(customerSource); assertNotNull(customerSource.asCard()); assertNull(customerSource.asSource()); mMaskedCardView.setCustomerSource(customerSource); assertEquals(Card.MASTERCARD, mMaskedCardView.getCardBrand()); assertEquals("5555", mMaskedCardView.getLast4()); assertFalse(mMaskedCardView.isSelected()); }
@Test public void toggleSelected_switchesState() { CustomerSource customerSource = CustomerSource.fromString(JSON_CARD); assertNotNull(customerSource); mMaskedCardView.setCustomerSource(customerSource); assertFalse(mMaskedCardView.isSelected()); mMaskedCardView.toggleSelected(); assertTrue(mMaskedCardView.isSelected()); assertEquals(View.VISIBLE, mSelectedImageView.getVisibility()); mMaskedCardView.toggleSelected(); assertFalse(mMaskedCardView.isSelected()); assertEquals(View.INVISIBLE, mSelectedImageView.getVisibility()); }