SupportedCardTypesView extends TextView { public void setSelected(@Nullable CardType... cardTypes) { if (cardTypes == null) { cardTypes = new CardType[]{}; } SpannableString spannableString = new SpannableString(new String(new char[mSupportedCardTypes.size()])); PaddedImageSpan span; for (int i = 0; i < mSupportedCardTypes.size(); i++) { span = new PaddedImageSpan(getContext(), mSupportedCardTypes.get(i).getFrontResource()); span.setDisabled(!Arrays.asList(cardTypes).contains(mSupportedCardTypes.get(i))); spannableString.setSpan(span, i, i + 1, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE); } setText(spannableString); } 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 setSelected_withoutSettingSupportedCardTypes_doesNothing() { SupportedCardTypesView supportedCardTypesView = new SupportedCardTypesView(RuntimeEnvironment.application); supportedCardTypesView.setSelected(CardType.VISA); assertEquals("", supportedCardTypesView.getText().toString()); }