SupportedCardTypesView extends TextView { public void setSupportedCardTypes(@Nullable CardType... cardTypes) { if (cardTypes == null) { cardTypes = new CardType[]{}; } mSupportedCardTypes.clear(); mSupportedCardTypes.addAll(Arrays.asList(cardTypes)); setSelected(cardTypes); } SupportedCardTypesView(Context context);  SupportedCardTypesView(Context context, AttributeSet attrs);  SupportedCardTypesView(Context context, AttributeSet attrs, int defStyleAttr); @TargetApi(Build.VERSION_CODES.LOLLIPOP)  SupportedCardTypesView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes); void setSupportedCardTypes(@Nullable CardType... cardTypes); void setSelected(@Nullable CardType... cardTypes);  }
@Test public void setSupportedCardTypes_addsAllCardTypes() { SupportedCardTypesView supportedCardTypesView = new SupportedCardTypesView(RuntimeEnvironment.application); supportedCardTypesView.setSupportedCardTypes(CardType.VISA, CardType.MASTERCARD, CardType.DISCOVER, CardType.AMEX, CardType.DINERS_CLUB, CardType.JCB, CardType.MAESTRO, CardType.UNIONPAY, CardType.HIPER, CardType.HIPERCARD); List<PaddedImageSpan> allSpans = Arrays.asList(new SpannableString(supportedCardTypesView.getText()) .getSpans(0, supportedCardTypesView.length(), PaddedImageSpan.class)); assertEquals(CardType.VISA.getFrontResource(), allSpans.get(0).getResourceId()); assertEquals(CardType.MASTERCARD.getFrontResource(), allSpans.get(1).getResourceId()); assertEquals(CardType.DISCOVER.getFrontResource(), allSpans.get(2).getResourceId()); assertEquals(CardType.AMEX.getFrontResource(), allSpans.get(3).getResourceId()); assertEquals(CardType.DINERS_CLUB.getFrontResource(), allSpans.get(4).getResourceId()); assertEquals(CardType.JCB.getFrontResource(), allSpans.get(5).getResourceId()); assertEquals(CardType.MAESTRO.getFrontResource(), allSpans.get(6).getResourceId()); assertEquals(CardType.UNIONPAY.getFrontResource(), allSpans.get(7).getResourceId()); assertEquals(CardType.HIPER.getFrontResource(), allSpans.get(8).getResourceId()); assertEquals(CardType.HIPERCARD.getFrontResource(), allSpans.get(9).getResourceId()); }
@Test public void setSupportedCardTypes_handlesNull() { SupportedCardTypesView supportedCardTypesView = new SupportedCardTypesView(RuntimeEnvironment.application); supportedCardTypesView.setSupportedCardTypes((CardType[]) null); List<PaddedImageSpan> allSpans = Arrays.asList(new SpannableString(supportedCardTypesView.getText()) .getSpans(0, supportedCardTypesView.length(), PaddedImageSpan.class)); assertEquals(0, allSpans.size()); }