Browse Source

refactor PasswordGeneratorTest

feature-password-generator
binsky 3 years ago
parent
commit
bb0e14c26f
  1. 7
      src/test/java/PasswordGeneratorTest.java

7
src/test/java/PasswordGeneratorTest.java

@ -15,16 +15,17 @@ class PasswordGeneratorTest {
} }
@Test @Test
void generateRandomPassword() {
void testGeneratedPasswordLength() {
assertNotSame("", passwordGenerator.generateRandomPassword()); assertNotSame("", passwordGenerator.generateRandomPassword());
assertEquals(passwordGenerator.generateRandomPassword().length(), passwordGenerator.getLength()); assertEquals(passwordGenerator.generateRandomPassword().length(), passwordGenerator.getLength());
// test length requirement
passwordGenerator.setLength(33); passwordGenerator.setLength(33);
assertEquals(passwordGenerator.getLength(), 33); assertEquals(passwordGenerator.getLength(), 33);
assertEquals(passwordGenerator.generateRandomPassword().length(), passwordGenerator.getLength()); assertEquals(passwordGenerator.generateRandomPassword().length(), passwordGenerator.getLength());
}
// test lowercase requirement
@Test
void testPasswordLowercaseRequirement() {
assertTrue(Pattern.compile("^(?=.*[a-z]).+$").matcher(passwordGenerator.generateRandomPassword()).matches()); assertTrue(Pattern.compile("^(?=.*[a-z]).+$").matcher(passwordGenerator.generateRandomPassword()).matches());
} }
} }
Loading…
Cancel
Save