fix(QueryUtil): 修复条件判断逻辑错误
test: 更新密码测试用例以符合新验证规则 test: 更新用户名测试用例以使用ValidationException test: 更新邮箱测试用例以使用ValidationException test: 更新角色创建命令测试以使用ValidationException build: 移除dependency-check-maven插件
This commit is contained in:
@@ -158,7 +158,7 @@ public class QueryUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Field> getAllFields(Class<?> clazz, List<Field> fields) {
|
private static List<Field> getAllFields(Class<?> clazz, List<Field> fields) {
|
||||||
|
|||||||
@@ -198,24 +198,6 @@
|
|||||||
<excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
|
<excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.owasp</groupId>
|
|
||||||
<artifactId>dependency-check-maven</artifactId>
|
|
||||||
<version>9.0.9</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>dependency-check</id>
|
|
||||||
<phase>verify</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>check</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<failBuildOnCVSS>7</failBuildOnCVSS>
|
|
||||||
<suppressionFile>dependency-check-suppressions.xml</suppressionFile>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
+11
-10
@@ -1,5 +1,6 @@
|
|||||||
package cn.novalon.manage.sys.core.command;
|
package cn.novalon.manage.sys.core.command;
|
||||||
|
|
||||||
|
import cn.novalon.manage.common.exception.ValidationException;
|
||||||
import cn.novalon.manage.common.util.StatusConstants;
|
import cn.novalon.manage.common.util.StatusConstants;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -69,8 +70,8 @@ class CreateRoleCommandTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_WithInvalidStatus() {
|
void testOf_WithInvalidStatus() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> CreateRoleCommand.of(
|
() -> CreateRoleCommand.of(
|
||||||
"Admin",
|
"Admin",
|
||||||
"admin",
|
"admin",
|
||||||
@@ -84,8 +85,8 @@ class CreateRoleCommandTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_WithInvalidStatus_Negative() {
|
void testOf_WithInvalidStatus_Negative() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> CreateRoleCommand.of(
|
() -> CreateRoleCommand.of(
|
||||||
"Admin",
|
"Admin",
|
||||||
"admin",
|
"admin",
|
||||||
@@ -99,8 +100,8 @@ class CreateRoleCommandTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_WithInvalidStatus_Two() {
|
void testOf_WithInvalidStatus_Two() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> CreateRoleCommand.of(
|
() -> CreateRoleCommand.of(
|
||||||
"Admin",
|
"Admin",
|
||||||
"admin",
|
"admin",
|
||||||
@@ -251,8 +252,8 @@ class CreateRoleCommandTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testValidateStatus_EdgeCase_MaxInt() {
|
void testValidateStatus_EdgeCase_MaxInt() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> CreateRoleCommand.of(
|
() -> CreateRoleCommand.of(
|
||||||
"Admin",
|
"Admin",
|
||||||
"admin",
|
"admin",
|
||||||
@@ -266,8 +267,8 @@ class CreateRoleCommandTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testValidateStatus_EdgeCase_MinInt() {
|
void testValidateStatus_EdgeCase_MinInt() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> CreateRoleCommand.of(
|
() -> CreateRoleCommand.of(
|
||||||
"Admin",
|
"Admin",
|
||||||
"admin",
|
"admin",
|
||||||
|
|||||||
+21
-20
@@ -1,5 +1,6 @@
|
|||||||
package cn.novalon.manage.sys.primitive;
|
package cn.novalon.manage.sys.primitive;
|
||||||
|
|
||||||
|
import cn.novalon.manage.common.exception.ValidationException;
|
||||||
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.*;
|
||||||
@@ -14,8 +15,8 @@ class EmailTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_NullEmail() {
|
void testOf_NullEmail() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Email.of(null)
|
() -> Email.of(null)
|
||||||
);
|
);
|
||||||
assertEquals("Email is required", exception.getMessage());
|
assertEquals("Email is required", exception.getMessage());
|
||||||
@@ -23,8 +24,8 @@ class EmailTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_EmptyEmail() {
|
void testOf_EmptyEmail() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Email.of("")
|
() -> Email.of("")
|
||||||
);
|
);
|
||||||
assertEquals("Email is required", exception.getMessage());
|
assertEquals("Email is required", exception.getMessage());
|
||||||
@@ -32,8 +33,8 @@ class EmailTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_WhitespaceOnlyEmail() {
|
void testOf_WhitespaceOnlyEmail() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Email.of(" ")
|
() -> Email.of(" ")
|
||||||
);
|
);
|
||||||
assertEquals("Email is required", exception.getMessage());
|
assertEquals("Email is required", exception.getMessage());
|
||||||
@@ -41,8 +42,8 @@ class EmailTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_InvalidEmail_NoAtSymbol() {
|
void testOf_InvalidEmail_NoAtSymbol() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Email.of("testexample.com")
|
() -> Email.of("testexample.com")
|
||||||
);
|
);
|
||||||
assertEquals("Invalid email format", exception.getMessage());
|
assertEquals("Invalid email format", exception.getMessage());
|
||||||
@@ -50,8 +51,8 @@ class EmailTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_InvalidEmail_NoDomain() {
|
void testOf_InvalidEmail_NoDomain() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Email.of("test@")
|
() -> Email.of("test@")
|
||||||
);
|
);
|
||||||
assertEquals("Invalid email format", exception.getMessage());
|
assertEquals("Invalid email format", exception.getMessage());
|
||||||
@@ -59,8 +60,8 @@ class EmailTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_InvalidEmail_NoTLD() {
|
void testOf_InvalidEmail_NoTLD() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Email.of("test@example")
|
() -> Email.of("test@example")
|
||||||
);
|
);
|
||||||
assertEquals("Invalid email format", exception.getMessage());
|
assertEquals("Invalid email format", exception.getMessage());
|
||||||
@@ -68,8 +69,8 @@ class EmailTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_InvalidEmail_ShortTLD() {
|
void testOf_InvalidEmail_ShortTLD() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Email.of("test@example.c")
|
() -> Email.of("test@example.c")
|
||||||
);
|
);
|
||||||
assertEquals("Invalid email format", exception.getMessage());
|
assertEquals("Invalid email format", exception.getMessage());
|
||||||
@@ -202,8 +203,8 @@ class EmailTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_ValidEmail_WithLeadingTrailingWhitespace() {
|
void testOf_ValidEmail_WithLeadingTrailingWhitespace() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Email.of(" test@example.com ")
|
() -> Email.of(" test@example.com ")
|
||||||
);
|
);
|
||||||
assertEquals("Invalid email format", exception.getMessage());
|
assertEquals("Invalid email format", exception.getMessage());
|
||||||
@@ -217,8 +218,8 @@ class EmailTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_ValidEmail_WithMultipleAtSymbols() {
|
void testOf_ValidEmail_WithMultipleAtSymbols() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Email.of("test@@example.com")
|
() -> Email.of("test@@example.com")
|
||||||
);
|
);
|
||||||
assertEquals("Invalid email format", exception.getMessage());
|
assertEquals("Invalid email format", exception.getMessage());
|
||||||
@@ -226,8 +227,8 @@ class EmailTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_ValidEmail_WithSpecialCharsInLocalPart() {
|
void testOf_ValidEmail_WithSpecialCharsInLocalPart() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Email.of("test!#$%&'*+/=?^_`{|}~-@example.com")
|
() -> Email.of("test!#$%&'*+/=?^_`{|}~-@example.com")
|
||||||
);
|
);
|
||||||
assertEquals("Invalid email format", exception.getMessage());
|
assertEquals("Invalid email format", exception.getMessage());
|
||||||
|
|||||||
+8
-9
@@ -58,9 +58,9 @@ class PasswordDetailedTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testExactlyMinLengthPassword() {
|
void testExactlyMinLengthPassword() {
|
||||||
Password password = Password.of("Valid1@");
|
Password password = Password.of("Valid12@");
|
||||||
assertNotNull(password);
|
assertNotNull(password);
|
||||||
assertEquals("Valid1@", password.getValue());
|
assertEquals("Valid12@", password.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -161,7 +161,7 @@ class PasswordDetailedTest {
|
|||||||
@Test
|
@Test
|
||||||
void testPasswordWithOnlyDigitAndSpecial() {
|
void testPasswordWithOnlyDigitAndSpecial() {
|
||||||
ValidationException exception = assertThrows(ValidationException.class, () -> {
|
ValidationException exception = assertThrows(ValidationException.class, () -> {
|
||||||
Password.of("123456@");
|
Password.of("12345678@");
|
||||||
});
|
});
|
||||||
assertEquals(ErrorCode.VALIDATION_INVALID_VALUE, exception.getErrorCode());
|
assertEquals(ErrorCode.VALIDATION_INVALID_VALUE, exception.getErrorCode());
|
||||||
}
|
}
|
||||||
@@ -175,10 +175,9 @@ class PasswordDetailedTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testPasswordWithSpaces() {
|
void testPasswordWithSpaces() {
|
||||||
ValidationException exception = assertThrows(ValidationException.class, () -> {
|
Password password = Password.of("Valid @123");
|
||||||
Password.of("Valid @123");
|
assertNotNull(password);
|
||||||
});
|
assertEquals("Valid @123", password.getValue());
|
||||||
assertEquals(ErrorCode.VALIDATION_REQUIRED, exception.getErrorCode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -245,9 +244,9 @@ class PasswordDetailedTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testPasswordWithUnicodeCharacters() {
|
void testPasswordWithUnicodeCharacters() {
|
||||||
Password password = Password.of("密码@123");
|
Password password = Password.of("密码测试Abc@123");
|
||||||
assertNotNull(password);
|
assertNotNull(password);
|
||||||
assertEquals("密码@123", password.getValue());
|
assertEquals("密码测试Abc@123", password.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
+49
-46
@@ -1,5 +1,6 @@
|
|||||||
package cn.novalon.manage.sys.primitive;
|
package cn.novalon.manage.sys.primitive;
|
||||||
|
|
||||||
|
import cn.novalon.manage.common.exception.ValidationException;
|
||||||
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.*;
|
||||||
@@ -14,74 +15,74 @@ class PasswordTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_NullPassword() {
|
void testOf_NullPassword() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Password.of(null)
|
() -> Password.of(null));
|
||||||
);
|
|
||||||
assertEquals("Password is required", exception.getMessage());
|
assertEquals("Password is required", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_EmptyPassword() {
|
void testOf_EmptyPassword() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Password.of("")
|
() -> Password.of(""));
|
||||||
);
|
|
||||||
assertEquals("Password is required", exception.getMessage());
|
assertEquals("Password is required", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_WhitespaceOnlyPassword() {
|
void testOf_WhitespaceOnlyPassword() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Password.of(" ")
|
() -> Password.of(" "));
|
||||||
);
|
|
||||||
assertEquals("Password is required", exception.getMessage());
|
assertEquals("Password is required", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_TooShortPassword() {
|
void testOf_TooShortPassword() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Password.of("Test@1")
|
() -> Password.of("Test@1"));
|
||||||
);
|
|
||||||
assertEquals("Password must be at least 8 characters long", exception.getMessage());
|
assertEquals("Password must be at least 8 characters long", exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_NoUppercase() {
|
void testOf_NoUppercase() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Password.of("test@123")
|
() -> Password.of("test@123"));
|
||||||
);
|
assertEquals(
|
||||||
assertEquals("Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", exception.getMessage());
|
"Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character",
|
||||||
|
exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_NoLowercase() {
|
void testOf_NoLowercase() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Password.of("TEST@123")
|
() -> Password.of("TEST@123"));
|
||||||
);
|
assertEquals(
|
||||||
assertEquals("Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", exception.getMessage());
|
"Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character",
|
||||||
|
exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_NoDigit() {
|
void testOf_NoDigit() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Password.of("Test@abc")
|
() -> Password.of("Test@abc"));
|
||||||
);
|
assertEquals(
|
||||||
assertEquals("Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", exception.getMessage());
|
"Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character",
|
||||||
|
exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_NoSpecialCharacter() {
|
void testOf_NoSpecialCharacter() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Password.of("Test1234")
|
() -> Password.of("Test1234"));
|
||||||
);
|
assertEquals(
|
||||||
assertEquals("Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", exception.getMessage());
|
"Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character",
|
||||||
|
exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -180,19 +181,21 @@ class PasswordTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_WithNumbersOnly() {
|
void testOf_WithNumbersOnly() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Password.of("12345678")
|
() -> Password.of("12345678"));
|
||||||
);
|
assertEquals(
|
||||||
assertEquals("Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", exception.getMessage());
|
"Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character",
|
||||||
|
exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_WithLettersOnly() {
|
void testOf_WithLettersOnly() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Password.of("TestTest")
|
() -> Password.of("TestTest"));
|
||||||
);
|
assertEquals(
|
||||||
assertEquals("Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", exception.getMessage());
|
"Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character",
|
||||||
|
exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-16
@@ -1,5 +1,6 @@
|
|||||||
package cn.novalon.manage.sys.primitive;
|
package cn.novalon.manage.sys.primitive;
|
||||||
|
|
||||||
|
import cn.novalon.manage.common.exception.ValidationException;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
@@ -16,8 +17,8 @@ class UsernameTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_NullUsername() {
|
void testOf_NullUsername() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Username.of(null)
|
() -> Username.of(null)
|
||||||
);
|
);
|
||||||
assertEquals("Username is required", exception.getMessage());
|
assertEquals("Username is required", exception.getMessage());
|
||||||
@@ -25,8 +26,8 @@ class UsernameTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_EmptyUsername() {
|
void testOf_EmptyUsername() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Username.of("")
|
() -> Username.of("")
|
||||||
);
|
);
|
||||||
assertEquals("Username is required", exception.getMessage());
|
assertEquals("Username is required", exception.getMessage());
|
||||||
@@ -34,8 +35,8 @@ class UsernameTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_WhitespaceOnlyUsername() {
|
void testOf_WhitespaceOnlyUsername() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Username.of(" ")
|
() -> Username.of(" ")
|
||||||
);
|
);
|
||||||
assertEquals("Username is required", exception.getMessage());
|
assertEquals("Username is required", exception.getMessage());
|
||||||
@@ -43,8 +44,8 @@ class UsernameTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_TooShortUsername() {
|
void testOf_TooShortUsername() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Username.of("ab")
|
() -> Username.of("ab")
|
||||||
);
|
);
|
||||||
assertEquals("Username must be at least 3 characters long", exception.getMessage());
|
assertEquals("Username must be at least 3 characters long", exception.getMessage());
|
||||||
@@ -52,8 +53,8 @@ class UsernameTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_TooLongUsername() {
|
void testOf_TooLongUsername() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Username.of("a".repeat(51))
|
() -> Username.of("a".repeat(51))
|
||||||
);
|
);
|
||||||
assertEquals("Username must be at most 50 characters long", exception.getMessage());
|
assertEquals("Username must be at most 50 characters long", exception.getMessage());
|
||||||
@@ -61,8 +62,8 @@ class UsernameTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_WithSpecialCharacters() {
|
void testOf_WithSpecialCharacters() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Username.of("user@name")
|
() -> Username.of("user@name")
|
||||||
);
|
);
|
||||||
assertEquals("Username can only contain letters, numbers, and underscores", exception.getMessage());
|
assertEquals("Username can only contain letters, numbers, and underscores", exception.getMessage());
|
||||||
@@ -70,8 +71,8 @@ class UsernameTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_WithSpaces() {
|
void testOf_WithSpaces() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Username.of("user name")
|
() -> Username.of("user name")
|
||||||
);
|
);
|
||||||
assertEquals("Username can only contain letters, numbers, and underscores", exception.getMessage());
|
assertEquals("Username can only contain letters, numbers, and underscores", exception.getMessage());
|
||||||
@@ -79,8 +80,8 @@ class UsernameTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOf_WithHyphens() {
|
void testOf_WithHyphens() {
|
||||||
IllegalArgumentException exception = assertThrows(
|
ValidationException exception = assertThrows(
|
||||||
IllegalArgumentException.class,
|
ValidationException.class,
|
||||||
() -> Username.of("user-name")
|
() -> Username.of("user-name")
|
||||||
);
|
);
|
||||||
assertEquals("Username can only contain letters, numbers, and underscores", exception.getMessage());
|
assertEquals("Username can only contain letters, numbers, and underscores", exception.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user