MobileNumberEditText extends ErrorEditText { @Override public boolean isValid() { return isOptional() || getText().toString().length() >= 8; } MobileNumberEditText(Context context);  MobileNumberEditText(Context context, AttributeSet attrs);  MobileNumberEditText(Context context, AttributeSet attrs, int defStyle); String getMobileNumber(); @Override boolean isValid(); @Override String getErrorMessage();  }
@Test public void invalidIfEmpty() { assertFalse(mView.isValid()); }
@Test public void invalidIfFewerThan8Characters() { mView.setText("123"); assertFalse(mView.isValid()); }
@Test public void validIfMoreThan8Characters() { mView.setText("12341234"); assertTrue(mView.isValid()); }
@Test public void validIfEmptyAndOptional() { mView.setOptional(true); assertTrue(mView.isValid()); }