5
我有一個代碼在驗證器中有android.util.Patterns.EMAIL_ADDRESS。它在針對設備運行時運行良好,但是當我在單元測試中運行此代碼時,它將返回null。 另外,我嘗試複製並粘貼模式中的內部代碼,如下例所示。android.util.Patterns.EMAIL在單元測試中返回null
validateEmail1 works // whyyy ???
validateEmail2返回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();
}