1
1
package com .thealgorithms .others ;
2
2
3
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
3
4
import static org .junit .jupiter .api .Assertions .assertThrows ;
4
5
import static org .junit .jupiter .api .Assertions .assertTrue ;
5
6
@@ -10,7 +11,7 @@ public class PasswordGenTest {
10
11
@ Test
11
12
public void failGenerationWithSameMinMaxLengthTest () {
12
13
int length = 10 ;
13
- assertThrows (IllegalArgumentException .class , () -> { PasswordGen .generatePassword (length , length ); } );
14
+ assertThrows (IllegalArgumentException .class , () -> PasswordGen .generatePassword (length , length ));
14
15
}
15
16
16
17
@ Test
@@ -23,12 +24,30 @@ public void generateOneCharacterPassword() {
23
24
public void failGenerationWithMinLengthSmallerThanMaxLengthTest () {
24
25
int minLength = 10 ;
25
26
int maxLength = 5 ;
26
- assertThrows (IllegalArgumentException .class , () -> { PasswordGen .generatePassword (minLength , maxLength ); } );
27
+ assertThrows (IllegalArgumentException .class , () -> PasswordGen .generatePassword (minLength , maxLength ));
27
28
}
28
29
29
30
@ Test
30
31
public void generatePasswordNonEmptyTest () {
31
32
String tempPassword = PasswordGen .generatePassword (8 , 16 );
32
33
assertTrue (tempPassword .length () != 0 );
33
34
}
35
+
36
+ @ Test
37
+ public void testGeneratePasswordWithMinGreaterThanMax () {
38
+ Exception exception = assertThrows (IllegalArgumentException .class , () -> PasswordGen .generatePassword (12 , 8 ));
39
+ assertEquals ("Incorrect length parameters: minLength must be <= maxLength and both must be > 0" , exception .getMessage ());
40
+ }
41
+
42
+ @ Test
43
+ public void testGeneratePasswordWithNegativeLength () {
44
+ Exception exception = assertThrows (IllegalArgumentException .class , () -> PasswordGen .generatePassword (-5 , 10 ));
45
+ assertEquals ("Incorrect length parameters: minLength must be <= maxLength and both must be > 0" , exception .getMessage ());
46
+ }
47
+
48
+ @ Test
49
+ public void testGeneratePasswordWithZeroLength () {
50
+ Exception exception = assertThrows (IllegalArgumentException .class , () -> PasswordGen .generatePassword (0 , 0 ));
51
+ assertEquals ("Incorrect length parameters: minLength must be <= maxLength and both must be > 0" , exception .getMessage ());
52
+ }
34
53
}
0 commit comments