### Question:
CardNumberEditText extends StripeEditText { @Nullable public String getCardNumber() { return mIsCardNumberValid ? StripeTextUtils.removeSpacesAndHyphens(getText().toString()) : null; } 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 getCardNumber_whenValidCard_returnsCardNumberWithoutSpaces() { mCardNumberEditText.setText(VALID_VISA_WITH_SPACES); assertEquals(VALID_VISA_NO_SPACES, mCardNumberEditText.getCardNumber()); mCardNumberEditText.setText(VALID_AMEX_WITH_SPACES); assertEquals(VALID_AMEX_NO_SPACES, mCardNumberEditText.getCardNumber()); mCardNumberEditText.setText(VALID_DINERS_CLUB_WITH_SPACES); assertEquals(VALID_DINERS_CLUB_NO_SPACES, mCardNumberEditText.getCardNumber()); }
@Test public void getCardNumber_whenIncompleteCard_returnsNull() { mCardNumberEditText.setText( VALID_DINERS_CLUB_WITH_SPACES .substring(0, VALID_DINERS_CLUB_WITH_SPACES.length() - 2)); assertNull(mCardNumberEditText.getCardNumber()); }
@Test public void getCardNumber_whenInvalidCardNumber_returnsNull() { String almostVisa = VALID_VISA_WITH_SPACES.substring(0, VALID_VISA_WITH_SPACES.length() - 1); almostVisa += "3"; mCardNumberEditText.setText(almostVisa); assertNull(mCardNumberEditText.getCardNumber()); }
@Test public void getCardNumber_whenValidNumberIsChangedToInvalid_returnsNull() { mCardNumberEditText.setText(VALID_AMEX_WITH_SPACES); ViewTestUtils.sendDeleteKeyEvent(mCardNumberEditText); assertNull(mCardNumberEditText.getCardNumber()); }