mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-03-08 04:50:45 +08:00
Merge pull request #155 from nagisa77/codex/fix-test-case-exceptions
Fix PasswordValidator tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.openisle.service;
|
package com.openisle.service;
|
||||||
|
|
||||||
import com.openisle.model.PasswordStrength;
|
import com.openisle.model.PasswordStrength;
|
||||||
|
import com.openisle.exception.FieldException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
@@ -11,7 +12,7 @@ class PasswordValidatorTest {
|
|||||||
void lowStrengthRequiresSixChars() {
|
void lowStrengthRequiresSixChars() {
|
||||||
PasswordValidator validator = new PasswordValidator(PasswordStrength.LOW);
|
PasswordValidator validator = new PasswordValidator(PasswordStrength.LOW);
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("12345"));
|
assertThrows(FieldException.class, () -> validator.validate("12345"));
|
||||||
assertDoesNotThrow(() -> validator.validate("123456"));
|
assertDoesNotThrow(() -> validator.validate("123456"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,9 +20,9 @@ class PasswordValidatorTest {
|
|||||||
void mediumStrengthRules() {
|
void mediumStrengthRules() {
|
||||||
PasswordValidator validator = new PasswordValidator(PasswordStrength.MEDIUM);
|
PasswordValidator validator = new PasswordValidator(PasswordStrength.MEDIUM);
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("abc123"));
|
assertThrows(FieldException.class, () -> validator.validate("abc123"));
|
||||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("abcdefgh"));
|
assertThrows(FieldException.class, () -> validator.validate("abcdefgh"));
|
||||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("12345678"));
|
assertThrows(FieldException.class, () -> validator.validate("12345678"));
|
||||||
assertDoesNotThrow(() -> validator.validate("abcd1234"));
|
assertDoesNotThrow(() -> validator.validate("abcd1234"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,11 +30,11 @@ class PasswordValidatorTest {
|
|||||||
void highStrengthRules() {
|
void highStrengthRules() {
|
||||||
PasswordValidator validator = new PasswordValidator(PasswordStrength.HIGH);
|
PasswordValidator validator = new PasswordValidator(PasswordStrength.HIGH);
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("Abc123$"));
|
assertThrows(FieldException.class, () -> validator.validate("Abc123$"));
|
||||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("abcd1234$xyz"));
|
assertThrows(FieldException.class, () -> validator.validate("abcd1234$xyz"));
|
||||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("ABCD1234$XYZ"));
|
assertThrows(FieldException.class, () -> validator.validate("ABCD1234$XYZ"));
|
||||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("AbcdABCDabcd"));
|
assertThrows(FieldException.class, () -> validator.validate("AbcdABCDabcd"));
|
||||||
assertThrows(IllegalArgumentException.class, () -> validator.validate("Abcd1234abcd"));
|
assertThrows(FieldException.class, () -> validator.validate("Abcd1234abcd"));
|
||||||
assertDoesNotThrow(() -> validator.validate("Abcd1234$xyz"));
|
assertDoesNotThrow(() -> validator.validate("Abcd1234$xyz"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user