CardEditText extends ErrorEditText implements TextWatcher { @Override public boolean isValid() { return isOptional() || mCardType.validate(getText().toString()); } 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 isValid_returnsFalseForInvalidCardNumber() { assertFalse(mView.isValid()); }
@Test public void isValid_returnsTrueForValidCardNumber() { type("4111111111111111"); assertTrue(mView.isValid()); }
@Test public void isValid_returnsTrueForInvalidCardNumberIfOptional() { mView.setOptional(true); assertTrue(mView.isValid()); }