I have a code that has android.util.Patterns.EMAIL_ADDRESS in the validator. It works fine when it works with the device, but when I run this code in unit test, it returns null. In addition, I tried to copy and paste the internal code into the templates in the following example.
validateEmail1 works // whyyy ???
validateEmail2 returns null
private static final Pattern EMAIL = Pattern.compile( "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + "\\@" + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + "(" + "\\." + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + ")+" ); public boolean validateEmail1(String email) { return EMAIL.matcher(email).matches(); } public boolean validateEmail2(String email) { return Patterns.EMAIL_ADDRESS.matcher(email).matches(); }
source share