SecurePasswordHelper { public String createSecurePassword() { return createSecurePassword(null, null, null, null, null, null); }  String createSecurePassword(); String createSecurePassword(Integer length, Integer minLowercaseLetters, Integer minUppercaseLetters, Integer minDigits, Integer minPunctuation, Integer minWhitespace); final static int DEFAULT_SECURE_PASSWORD_LENGTH; final static int DEFAULT_SECURE_PASSWORD_MIN_LOWERCASE_LETTERS; final static int DEFAULT_SECURE_PASSWORD_MIN_UPPERCASE_LETTERS; final static int DEFAULT_SECURE_PASSWORD_MIN_DIGITS; final static int DEFAULT_SECURE_PASSWORD_MIN_PUNCTUATION; final static int DEFAULT_SECURE_PASSWORD_MIN_WHITESPACE; }
@Test public void testCreateSecurePassword() throws Exception { String password1 = securePasswordHelper.createSecurePassword(); Assert.assertNotNull(password1); Assert.assertEquals(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_LENGTH, password1.length()); String password2 = securePasswordHelper.createSecurePassword(); Assert.assertNotNull(password2); Assert.assertEquals(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_LENGTH, password2.length()); Assert.assertFalse((password1.equals(password2))); }
@Test public void testCreateSecurePasswordWithRules() throws Exception { String password; password = securePasswordHelper.createSecurePassword(null, null, null, null, null, null); Assert.assertNotNull(password); Assert.assertEquals(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_LENGTH, password.length()); assertMinLowercaseLetters(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_LOWERCASE_LETTERS, password); assertMinUppercaseLetters(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_UPPERCASE_LETTERS, password); assertMinDigits(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_DIGITS, password); assertMinPunctuation(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_PUNCTUATION, password); assertMinWhitespace(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_WHITESPACE, password); password = securePasswordHelper.createSecurePassword(10, null, null, null, null, null); Assert.assertNotNull(password); Assert.assertEquals(10, password.length()); assertMinLowercaseLetters(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_LOWERCASE_LETTERS, password); assertMinUppercaseLetters(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_UPPERCASE_LETTERS, password); assertMinDigits(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_DIGITS, password); assertMinPunctuation(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_PUNCTUATION, password); assertMinWhitespace(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_WHITESPACE, password); password = securePasswordHelper.createSecurePassword(0, null, null, null, null, null); Assert.assertNotNull(password); Assert.assertEquals(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_LENGTH, password.length()); assertMinLowercaseLetters(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_LOWERCASE_LETTERS, password); assertMinUppercaseLetters(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_UPPERCASE_LETTERS, password); assertMinDigits(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_DIGITS, password); assertMinPunctuation(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_PUNCTUATION, password); assertMinWhitespace(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_WHITESPACE, password); password = securePasswordHelper.createSecurePassword(-20, null, null, null, null, null); Assert.assertNotNull(password); Assert.assertEquals(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_LENGTH, password.length()); assertMinLowercaseLetters(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_LOWERCASE_LETTERS, password); assertMinUppercaseLetters(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_UPPERCASE_LETTERS, password); assertMinDigits(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_DIGITS, password); assertMinPunctuation(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_PUNCTUATION, password); assertMinWhitespace(SecurePasswordHelper.DEFAULT_SECURE_PASSWORD_MIN_WHITESPACE, password); password = securePasswordHelper.createSecurePassword(100, 30, 20, 10, 5, 2); Assert.assertNotNull(password); Assert.assertEquals(100, password.length()); assertMinLowercaseLetters(30, password); assertMinUppercaseLetters(20, password); assertMinDigits(10, password); assertMinPunctuation(5, password); assertMinWhitespace(2, password); password = securePasswordHelper.createSecurePassword(100, 20, 20, 20, 20, 0); Assert.assertNotNull(password); Assert.assertEquals(100, password.length()); assertMinLowercaseLetters(20, password); assertMinUppercaseLetters(20, password); assertMinDigits(20, password); assertMinPunctuation(20, password); assertMinWhitespace(0, password); }