CardholderNameEditText extends ErrorEditText { @Override public boolean isValid() { return isOptional() || !getText().toString().trim().isEmpty(); } CardholderNameEditText(Context context);  CardholderNameEditText(Context context, AttributeSet attrs);  CardholderNameEditText(Context context, AttributeSet attrs, int defStyle); @Override boolean isValid(); @Override String getErrorMessage();  }
@Test public void invalidIfEmpty() { assertFalse(mView.isValid()); }
@Test public void validIfNotEmpty() { mView.setText("John Doe"); assertTrue(mView.isValid()); }
@Test public void validIfEmptyAndOptional() { mView.setOptional(true); assertTrue(mView.isValid()); }