Length implements Validation { @Override public String getErrorMessage(final Context context) { if (mMinLength != -1 && mMaxLength != -1) { return context.getString(R.string.formvalidations_length_range, mMinLength, mMaxLength); } else if (mMinLength == -1 && mMaxLength != -1) { return context.getString(R.string.formvalidations_length_max, mMaxLength); } return context.getString(R.string.formvalidations_length_min, mMinLength); } private  Length(final int minLength, final int maxLength); static Validation min(final int minLength); static Validation max(final int maxLength); static Validation range(final int minLength, final int maxLength); @Override String getErrorMessage(final Context context); @Override boolean isValid(final String text);  }
@Test public void testGetErrorMessage() throws Exception { final Validation minValidation = Length.min(2); final String minValidationErrorMessage = minValidation.getErrorMessage(mActivity); assertNotNull(minValidationErrorMessage); assertTrue(minValidationErrorMessage.contains("2")); final Validation maxValidation = Length.max(5); final String maxValidationErrorMessage = maxValidation.getErrorMessage(mActivity); assertNotNull(maxValidationErrorMessage); assertTrue(maxValidationErrorMessage.contains("5")); final Validation rangeValidation = Length.range(2, 5); final String rangeValidationErrorMessage = rangeValidation.getErrorMessage(mActivity); assertNotNull(rangeValidationErrorMessage); assertTrue(rangeValidationErrorMessage.contains("2")); assertTrue(rangeValidationErrorMessage.contains("5")); }