From c0b2c5662812741345b076f76ae236a1e40cb056 Mon Sep 17 00:00:00 2001 From: Hai Nguyen <88832724+ntquanghai@users.noreply.github.com> Date: Thu, 23 Jun 2022 13:23:11 +0700 Subject: [PATCH] Add tests for PasswordGen (#3163) --- .../thealgorithms/others/PasswordGenTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/test/java/com/thealgorithms/others/PasswordGenTest.java diff --git a/src/test/java/com/thealgorithms/others/PasswordGenTest.java b/src/test/java/com/thealgorithms/others/PasswordGenTest.java new file mode 100644 index 000000000..31076898f --- /dev/null +++ b/src/test/java/com/thealgorithms/others/PasswordGenTest.java @@ -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); + } +}