/** * Set the card data displayed using a {@link CustomerSource} object. If the object * is not a {@link Source} object that represents a card and the object returns {@code null} * from its {@link CustomerSource#asCard()} method, then no values will be set on this control. * * @param customerSource the {@link CustomerSource} to be partially displayed */ void setCustomerSource(@NonNull CustomerSource customerSource) { Source source = customerSource.asSource(); if (source != null && source.getSourceTypeModel() != null && Source.CARD.equals(source.getType()) && source.getSourceTypeModel() instanceof SourceCardData) { SourceCardData sourceCardData = (SourceCardData) source.getSourceTypeModel(); setSourceCardData(sourceCardData); return; } Card card = customerSource.asCard(); if (card != null) { setCard(card); } }
@Test public void setCard_setsCorrectData() { Card card = new Card(CardInputTestActivity.VALID_AMEX_NO_SPACES, 12, 50, "1234"); mMaskedCardView.setCard(card); assertEquals("0005", mMaskedCardView.getLast4()); assertEquals(Card.AMERICAN_EXPRESS, mMaskedCardView.getCardBrand()); assertFalse(mMaskedCardView.isSelected()); }