mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 14:34:05 +08:00
Add tests for PasswordGen (#3163)
This commit is contained in:
37
src/test/java/com/thealgorithms/others/PasswordGenTest.java
Normal file
37
src/test/java/com/thealgorithms/others/PasswordGenTest.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.thealgorithms.others;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
public class PasswordGenTest {
|
||||
@Test
|
||||
public void failGenerationWithSameMinMaxLengthTest() {
|
||||
int length = 10;
|
||||
assertThrows(IllegalArgumentException.class, ()-> {
|
||||
PasswordGen.generatePassword(length, length);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateOneCharacterPassword() {
|
||||
String tempPassword = PasswordGen.generatePassword(1, 2);
|
||||
assertTrue(tempPassword.length()==1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failGenerationWithMinLengthSmallerThanMaxLengthTest() {
|
||||
int minLength = 10;
|
||||
int maxLength = 5;
|
||||
assertThrows(IllegalArgumentException.class, ()-> {
|
||||
PasswordGen.generatePassword(minLength, maxLength);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatePasswordNonEmptyTest() {
|
||||
String tempPassword = PasswordGen.generatePassword(8, 16);
|
||||
assertTrue(tempPassword.length()!=0);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user