|
|
@ -1,6 +1,8 @@ |
|
|
|
import org.junit.jupiter.api.BeforeAll; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
|
class PasswordGeneratorTest { |
|
|
@ -14,6 +16,15 @@ class PasswordGeneratorTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
void generateRandomPassword() { |
|
|
|
assertSame("", passwordGenerator.generateRandomPassword()); |
|
|
|
assertNotSame("", passwordGenerator.generateRandomPassword()); |
|
|
|
assertEquals(passwordGenerator.generateRandomPassword().length(), passwordGenerator.getLength()); |
|
|
|
|
|
|
|
// test length requirement |
|
|
|
passwordGenerator.setLength(33); |
|
|
|
assertEquals(passwordGenerator.getLength(), 33); |
|
|
|
assertEquals(passwordGenerator.generateRandomPassword().length(), passwordGenerator.getLength()); |
|
|
|
|
|
|
|
// test lowercase requirement |
|
|
|
assertTrue(Pattern.compile("^(?=.*[a-z]).+$").matcher(passwordGenerator.generateRandomPassword()).matches()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |