### Question:
CardMultilineWidget extends LinearLayout { @Nullable public Card getCard() { if (validateAllFields()) { String cardNumber = mCardNumberEditText.getCardNumber(); int[] cardDate = mExpiryDateEditText.getValidDateFields(); String cvcValue = mCvcEditText.getText().toString(); Card card = new Card(cardNumber, cardDate[0], cardDate[1], cvcValue); if (mShouldShowPostalCode) { card.setAddressZip(mPostalCodeEditText.getText().toString()); } return card.addLoggingToken(CARD_MULTILINE_TOKEN); } return null; } CardMultilineWidget(Context context);  CardMultilineWidget(Context context, AttributeSet attrs);  CardMultilineWidget(Context context, AttributeSet attrs, int defStyleAttr); @VisibleForTesting  CardMultilineWidget(Context context, boolean shouldShowPostalCode); void clear(); void setCardInputListener(@Nullable CardInputListener cardInputListener); @Nullable Card getCard(); boolean validateAllFields(); @Override void onWindowFocusChanged(boolean hasWindowFocus); void setShouldShowPostalCode(boolean shouldShowPostalCode); @Override boolean isEnabled(); @Override void setEnabled(boolean enabled);  }### Answer:
@Test public void getCard_whenInputIsValidVisaWithZip_returnsCardObjectWithLoggingToken() { assertTrue(Calendar.getInstance().get(Calendar.YEAR) < 2050); mFullGroup.cardNumberEditText.setText(VALID_VISA_WITH_SPACES); mFullGroup.expiryDateEditText.append("12"); mFullGroup.expiryDateEditText.append("50"); mFullGroup.cvcEditText.append("123"); mFullGroup.postalCodeEditText.append("12345"); Card card = mCardMultilineWidget.getCard(); assertNotNull(card); assertEquals(VALID_VISA_NO_SPACES, card.getNumber()); assertNotNull(card.getExpMonth()); assertNotNull(card.getExpYear()); assertEquals(12, card.getExpMonth().intValue()); assertEquals(2050, card.getExpYear().intValue()); assertEquals("123", card.getCVC()); assertEquals("12345", card.getAddressZip()); assertTrue(card.validateCard()); assertArrayEquals(EXPECTED_LOGGING_ARRAY, card.getLoggingTokens().toArray()); }
@Test public void getCard_whenInputIsValidVisaButInputHasNoZip_returnsNull() { assertTrue(Calendar.getInstance().get(Calendar.YEAR) < 2050); mFullGroup.cardNumberEditText.setText(VALID_VISA_WITH_SPACES); mFullGroup.expiryDateEditText.append("12"); mFullGroup.expiryDateEditText.append("50"); mFullGroup.cvcEditText.append("123"); Card card = mCardMultilineWidget.getCard(); assertNull(card); }
@Test public void getCard_whenInputIsValidVisaAndNoZipRequired_returnsFullCardAndExpectedLogging() { assertTrue(Calendar.getInstance().get(Calendar.YEAR) < 2050); mNoZipGroup.cardNumberEditText.setText(VALID_VISA_WITH_SPACES); mNoZipGroup.expiryDateEditText.append("12"); mNoZipGroup.expiryDateEditText.append("50"); mNoZipGroup.cvcEditText.append("123"); Card card = mNoZipCardMultilineWidget.getCard(); assertNotNull(card); assertEquals(VALID_VISA_NO_SPACES, card.getNumber()); assertNotNull(card.getExpMonth()); assertNotNull(card.getExpYear()); assertEquals(12, card.getExpMonth().intValue()); assertEquals(2050, card.getExpYear().intValue()); assertEquals("123", card.getCVC()); assertNull(card.getAddressZip()); assertTrue(card.validateCard()); assertArrayEquals(EXPECTED_LOGGING_ARRAY, card.getLoggingTokens().toArray()); }