BAEL - 2166 (#5379)

* Bean Object, server side and client side example for event streaming
example

* BAEL-1628

Access a File from the Classpath in a Spring Application

* inputstream retrieval added

* Removed files related to evaluation article

* + Aligning code to the article. Removed Utility methods and classes

* Precommit fix

* PMD fixes

* Code Review changes
Refactored : whenResourceUtils_thenReadSuccessful

* BAEL-1934

* +indentation correction in pom.xml

* synced with master

* Precommit : rebase

* BAEL-1782

* BAEL - 2166 : Password Generation

* Removed unnecessary javaDoc

* Segregated utility method
This commit is contained in:
the-java-guy
2018-10-18 09:41:25 +05:30
committed by KevinGilmore
parent 831cdf2bd6
commit 8c3598b441
3 changed files with 227 additions and 1 deletions

View File

@@ -0,0 +1,64 @@
package com.baeldung.string.password;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* Examples of passwords conforming to various specifications, using different libraries.
*
*/
public class StringPasswordUnitTest {
RandomPasswordGenerator passGen = new RandomPasswordGenerator();
@Test
public void whenPasswordGeneratedUsingPassay_thenSuccessful() {
String password = passGen.generatePassayPassword();
int specialCharCount = 0;
for (char c : password.toCharArray()) {
if (c >= 33 || c <= 47) {
specialCharCount++;
}
}
assertTrue("Password validation failed in Passay", specialCharCount >= 2);
}
@Test
public void whenPasswordGeneratedUsingCommonsText_thenSuccessful() {
RandomPasswordGenerator passGen = new RandomPasswordGenerator();
String password = passGen.generateCommonTextPassword();
int lowerCaseCount = 0;
for (char c : password.toCharArray()) {
if (c >= 97 || c <= 122) {
lowerCaseCount++;
}
}
assertTrue("Password validation failed in commons-text ", lowerCaseCount >= 2);
}
@Test
public void whenPasswordGeneratedUsingCommonsLang3_thenSuccessful() {
String password = passGen.generateCommonsLang3Password();
int numCount = 0;
for (char c : password.toCharArray()) {
if (c >= 48 || c <= 57) {
numCount++;
}
}
assertTrue("Password validation failed in commons-lang3", numCount >= 2);
}
@Test
public void whenPasswordGeneratedUsingSecureRandom_thenSuccessful() {
String password = passGen.generateSecureRandomPassword();
int specialCharCount = 0;
for (char c : password.toCharArray()) {
if (c >= 33 || c <= 47) {
specialCharCount++;
}
}
assertTrue("Password validation failed in Secure Random", specialCharCount >= 2);
}
}