StringUtil implements Serializable { public boolean validateString(String regExStr, String str) { try { return regExPatternMatch(regExStr, str); } catch (Throwable t) { logger.info("Error validating string. str=" + str, t); return false; } } StringUtil(); boolean isEmpty(String str); boolean isEmptyOrWildcardAsterisk(String str); boolean equals(String str1, String str2); String toCamelCaseAllWords(String str); boolean validatePassword(String password, String[] invalidValues); boolean validateEmail(String emailAddress); boolean regExPatternMatch(String expression, String inputStr); boolean validateString(String regExStr, String str); String normalizeEmail(String email); String[] split(String value); String[] split(String value, String delimiter); static String trim(String str); boolean isValidName(String name); boolean isEmpty(List<?> list); String getValidUserName(String str); static final public int MIN_PASSWORD_LENGTH; static final public String VALIDATION_NAME; static final public String VALIDATION_TEXT; static final public String VALIDATION_LOGINID; static final public String VALIDATION_ALPHA; static final public String VALIDATION_IP_ADDRESS; static final public String WILDCARD_ASTERISK; }
@Test public void testValidateString(){ String regExStr = "^[\\w]([\\-\\.\\w])+[\\w]+@[\\w]+[\\w\\-]+[\\w]*\\.([\\w]+[\\w\\-]+[\\w]*(\\.[a-z][a-z|0-9]*)?)$"; String str="test.test@gmail.com"; boolean value = stringUtil.validateString(regExStr, str); Assert.assertTrue(value); }
@Test public void testNotValidateString(){ String regExStr = "^[\\w]([\\-\\.\\w])+[\\w]+[\\w]*\\.([\\w]+[\\w\\-]+[\\w]*(\\.[a-z][a-z|0-9]*)?)$"; String str="test.test@gmail.com"; boolean value = stringUtil.validateString(regExStr, str); Assert.assertFalse(value); }