CardEditText extends ErrorEditText implements TextWatcher { public void setOnCardTypeChangedListener(OnCardTypeChangedListener listener) { mOnCardTypeChangedListener = listener; } CardEditText(Context context);  CardEditText(Context context, AttributeSet attrs);  CardEditText(Context context, AttributeSet attrs, int defStyle); void displayCardTypeIcon(boolean display); CardType getCardType(); void setMask(boolean mask); void setOnCardTypeChangedListener(OnCardTypeChangedListener listener); @Override void afterTextChanged(Editable editable); @Override boolean isValid(); @Override String getErrorMessage(); @Override void beforeTextChanged(CharSequence s, int start, int count, int after);  }
@Test public void callsCardTypeChangedListenerWhenSetAndCardTypeChanges() { CardEditText.OnCardTypeChangedListener listener = mock(CardEditText.OnCardTypeChangedListener.class); mView.setOnCardTypeChangedListener(listener); type("4"); verify(listener).onCardTypeChanged(CardType.VISA); }
@Test public void doesNotCallCardTypeChangedListenerWhenSetAndCardTypeDoesNotChange() { CardEditText.OnCardTypeChangedListener listener = mock(CardEditText.OnCardTypeChangedListener.class); mView.setOnCardTypeChangedListener(listener); type("4"); type("111"); verify(listener).onCardTypeChanged(CardType.VISA); }
@Test public void callsCardTypeChangedListenerWhenEditTextChangesFromEmptyToUnknown() { CardEditText.OnCardTypeChangedListener listener = mock(CardEditText.OnCardTypeChangedListener.class); mView.setOnCardTypeChangedListener(listener); type("1"); verify(listener).onCardTypeChanged(CardType.UNKNOWN); }
@Test public void callsCardTypeChangeListenerWhenEditTextChangesFromUnknownToEmpty() { CardEditText.OnCardTypeChangedListener listener = mock(CardEditText.OnCardTypeChangedListener.class); mView.setOnCardTypeChangedListener(listener); type("1"); mView.getText().clear(); verify(listener).onCardTypeChanged(CardType.UNKNOWN); verify(listener).onCardTypeChanged(CardType.EMPTY); }