Skip to content

Update testing for PasswordGen function #3163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 23, 2022
37 changes: 37 additions & 0 deletions src/test/java/com/thealgorithms/others/PasswordGenTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}