You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
968 B

  1. import org.junit.jupiter.api.BeforeAll;
  2. import org.junit.jupiter.api.Test;
  3. import java.util.regex.Pattern;
  4. import static org.junit.jupiter.api.Assertions.*;
  5. class PasswordGeneratorTest {
  6. static PasswordGenerator passwordGenerator;
  7. @BeforeAll
  8. static void init() {
  9. passwordGenerator = new PasswordGenerator();
  10. }
  11. @Test
  12. void generateRandomPassword() {
  13. assertNotSame("", passwordGenerator.generateRandomPassword());
  14. assertEquals(passwordGenerator.generateRandomPassword().length(), passwordGenerator.getLength());
  15. // test length requirement
  16. passwordGenerator.setLength(33);
  17. assertEquals(passwordGenerator.getLength(), 33);
  18. assertEquals(passwordGenerator.generateRandomPassword().length(), passwordGenerator.getLength());
  19. // test lowercase requirement
  20. assertTrue(Pattern.compile("^(?=.*[a-z]).+$").matcher(passwordGenerator.generateRandomPassword()).matches());
  21. }
  22. }