### Question:
CardNumberEditText extends StripeEditText { public boolean isCardNumberValid() { return mIsCardNumberValid; } CardNumberEditText(Context context);  CardNumberEditText(Context context, AttributeSet attrs);  CardNumberEditText(Context context, AttributeSet attrs, int defStyleAttr); @NonNull @Card.CardBrand String getCardBrand(); @Nullable String getCardNumber(); int getLengthMax(); boolean isCardNumberValid();  }### Answer:
@Test public void setText_whenTextIsValidCommonLengthNumber_changesCardValidState() { mCardNumberEditText.setText(VALID_VISA_WITH_SPACES); assertTrue(mCardNumberEditText.isCardNumberValid()); verify(mCardNumberCompleteListener, times(1)).onCardNumberComplete(); }
@Test public void setText_whenTextIsSpacelessValidNumber_changesToSpaceNumberAndValidates() { mCardNumberEditText.setText(VALID_VISA_NO_SPACES); assertTrue(mCardNumberEditText.isCardNumberValid()); verify(mCardNumberCompleteListener, times(1)).onCardNumberComplete(); }
@Test public void setText_whenTextIsValidAmExDinersClubLengthNumber_changesCardValidState() { mCardNumberEditText.setText(VALID_AMEX_WITH_SPACES); assertTrue(mCardNumberEditText.isCardNumberValid()); verify(mCardNumberCompleteListener, times(1)).onCardNumberComplete(); }
@Test public void setText_whenTextChangesFromValidToInvalid_changesCardValidState() { mCardNumberEditText.setText(VALID_VISA_WITH_SPACES); reset(mCardNumberCompleteListener); String mutable = mCardNumberEditText.getText().toString(); mutable = mutable.substring(0, 18); mCardNumberEditText.setText(mutable); assertFalse(mCardNumberEditText.isCardNumberValid()); verifyZeroInteractions(mCardNumberCompleteListener); }
@Test public void setText_whenTextIsInvalidCommonLengthNumber_doesNotNotifyListener() { String almostValid = VALID_VISA_WITH_SPACES.substring(0, 18) + "3"; mCardNumberEditText.setText(almostValid); assertFalse(mCardNumberEditText.isCardNumberValid()); verifyZeroInteractions(mCardNumberCompleteListener); }