Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathPasswordGenTest.java
More file actions
Latest commit
53 lines (43 loc) · 2.04 KB
/
Copy pathPasswordGenTest.java
File metadata and controls
53 lines (43 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
packagecom.thealgorithms.others;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.api.Assertions.assertThrows;
importstaticorg.junit.jupiter.api.Assertions.assertTrue;
importorg.junit.jupiter.api.Test;
publicclassPasswordGenTest {
@Test
publicvoidfailGenerationWithSameMinMaxLengthTest() {
intlength = 10;
assertThrows(IllegalArgumentException.class, () -> PasswordGen.generatePassword(length, length));
}
@Test
publicvoidgenerateOneCharacterPassword() {
StringtempPassword = PasswordGen.generatePassword(1, 2);
assertEquals(1, tempPassword.length());
}
@Test
publicvoidfailGenerationWithMinLengthSmallerThanMaxLengthTest() {
intminLength = 10;
intmaxLength = 5;
assertThrows(IllegalArgumentException.class, () -> PasswordGen.generatePassword(minLength, maxLength));
}
@Test
publicvoidgeneratePasswordNonEmptyTest() {
StringtempPassword = PasswordGen.generatePassword(8, 16);
assertTrue(tempPassword.length() != 0);
}
@Test
publicvoidtestGeneratePasswordWithMinGreaterThanMax() {
Exceptionexception = assertThrows(IllegalArgumentException.class, () -> PasswordGen.generatePassword(12, 8));
assertEquals("Incorrect length parameters: minLength must be <= maxLength and both must be > 0", exception.getMessage());
}
@Test
publicvoidtestGeneratePasswordWithNegativeLength() {
Exceptionexception = assertThrows(IllegalArgumentException.class, () -> PasswordGen.generatePassword(-5, 10));
assertEquals("Incorrect length parameters: minLength must be <= maxLength and both must be > 0", exception.getMessage());
}
@Test
publicvoidtestGeneratePasswordWithZeroLength() {
Exceptionexception = assertThrows(IllegalArgumentException.class, () -> PasswordGen.generatePassword(0, 0));
assertEquals("Incorrect length parameters: minLength must be <= maxLength and both must be > 0", exception.getMessage());
}
}