Skip to content

Commit c0b2c56

Browse files
authored
Add tests for PasswordGen (TheAlgorithms#3163)
1 parent 2a2c575 commit c0b2c56

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.thealgorithms.others;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
8+
public class PasswordGenTest {
9+
@Test
10+
public void failGenerationWithSameMinMaxLengthTest() {
11+
int length = 10;
12+
assertThrows(IllegalArgumentException.class, ()-> {
13+
PasswordGen.generatePassword(length, length);
14+
});
15+
}
16+
17+
@Test
18+
public void generateOneCharacterPassword() {
19+
String tempPassword = PasswordGen.generatePassword(1, 2);
20+
assertTrue(tempPassword.length()==1);
21+
}
22+
23+
@Test
24+
public void failGenerationWithMinLengthSmallerThanMaxLengthTest() {
25+
int minLength = 10;
26+
int maxLength = 5;
27+
assertThrows(IllegalArgumentException.class, ()-> {
28+
PasswordGen.generatePassword(minLength, maxLength);
29+
});
30+
}
31+
32+
@Test
33+
public void generatePasswordNonEmptyTest() {
34+
String tempPassword = PasswordGen.generatePassword(8, 16);
35+
assertTrue(tempPassword.length()!=0);
36+
}
37+
}

0 commit comments

Comments
 (0)