StringUtil implements Serializable { public boolean validatePassword(String password, String[] invalidValues) { if (password == null) { return false; } password = password.trim(); if (password.length() < MIN_PASSWORD_LENGTH) { return false; } boolean hasAlpha = false; boolean hasNum = false; for (int i = 0; i < password.length(); i++) { char ch = password.charAt(i); if (Character.isDigit(ch)) { hasNum = true; } else if (Character.isLetter(ch)) { hasAlpha = true; } } if (!hasAlpha || !hasNum) { return false; } for (int i = 0; invalidValues != null && i < invalidValues.length; i++) { if (password.equalsIgnoreCase(invalidValues[i])) { return false; } } return true; } 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 testNullValidatePassword(){ String password=null; String[] invalidValues={"aa","bb","aa12345dd"}; boolean value=stringUtil.validatePassword(password, invalidValues); Assert.assertFalse(value); }
@Test public void testValidatePassword(){ String password="aa1234ddas12"; String[] invalidValues={"aa","bb","aa12345dd"}; boolean value=stringUtil.validatePassword(password, invalidValues); Assert.assertTrue(password.length() >= 8); Assert.assertTrue(value); }
@Test public void testNotValidatePassword(){ String password="aassasavcvcvc"; String[] invalidValues={"aa","bb","aa12345dd"}; boolean value=stringUtil.validatePassword(password, invalidValues); Assert.assertTrue(password.length() >= 8); Assert.assertFalse(value); }