From 3d6a0bd7b8bcfc8eff87d03275c70f4f363fbcee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Tue, 24 Mar 2026 15:15:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(QueryUtil):=20=E4=BF=AE=E5=A4=8D=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test: 更新密码测试用例以符合新验证规则 test: 更新用户名测试用例以使用ValidationException test: 更新邮箱测试用例以使用ValidationException test: 更新角色创建命令测试以使用ValidationException build: 移除dependency-check-maven插件 --- .../cn/novalon/manage/db/dao/QueryUtil.java | 2 +- novalon-manage-api/manage-sys/pom.xml | 18 ---- .../core/command/CreateRoleCommandTest.java | 21 ++-- .../manage/sys/primitive/EmailTest.java | 41 ++++---- .../sys/primitive/PasswordDetailedTest.java | 17 ++-- .../manage/sys/primitive/PasswordTest.java | 95 ++++++++++--------- .../manage/sys/primitive/UsernameTest.java | 33 +++---- 7 files changed, 107 insertions(+), 120 deletions(-) diff --git a/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/dao/QueryUtil.java b/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/dao/QueryUtil.java index 7107003..fbd4e08 100644 --- a/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/dao/QueryUtil.java +++ b/novalon-manage-api/manage-db/src/main/java/cn/novalon/manage/db/dao/QueryUtil.java @@ -158,7 +158,7 @@ public class QueryUtil { return false; } } - return false; + return true; } private static List getAllFields(Class clazz, List fields) { diff --git a/novalon-manage-api/manage-sys/pom.xml b/novalon-manage-api/manage-sys/pom.xml index dcea54d..91ff9fb 100644 --- a/novalon-manage-api/manage-sys/pom.xml +++ b/novalon-manage-api/manage-sys/pom.xml @@ -198,24 +198,6 @@ spotbugs-exclude.xml - - org.owasp - dependency-check-maven - 9.0.9 - - - dependency-check - verify - - check - - - - - 7 - dependency-check-suppressions.xml - - \ No newline at end of file diff --git a/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/core/command/CreateRoleCommandTest.java b/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/core/command/CreateRoleCommandTest.java index e0e996a..4f29a3c 100644 --- a/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/core/command/CreateRoleCommandTest.java +++ b/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/core/command/CreateRoleCommandTest.java @@ -1,5 +1,6 @@ package cn.novalon.manage.sys.core.command; +import cn.novalon.manage.common.exception.ValidationException; import cn.novalon.manage.common.util.StatusConstants; import org.junit.jupiter.api.Test; @@ -69,8 +70,8 @@ class CreateRoleCommandTest { @Test void testOf_WithInvalidStatus() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> CreateRoleCommand.of( "Admin", "admin", @@ -84,8 +85,8 @@ class CreateRoleCommandTest { @Test void testOf_WithInvalidStatus_Negative() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> CreateRoleCommand.of( "Admin", "admin", @@ -99,8 +100,8 @@ class CreateRoleCommandTest { @Test void testOf_WithInvalidStatus_Two() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> CreateRoleCommand.of( "Admin", "admin", @@ -251,8 +252,8 @@ class CreateRoleCommandTest { @Test void testValidateStatus_EdgeCase_MaxInt() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> CreateRoleCommand.of( "Admin", "admin", @@ -266,8 +267,8 @@ class CreateRoleCommandTest { @Test void testValidateStatus_EdgeCase_MinInt() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> CreateRoleCommand.of( "Admin", "admin", diff --git a/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/EmailTest.java b/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/EmailTest.java index 9c42975..ebb2eb9 100644 --- a/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/EmailTest.java +++ b/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/EmailTest.java @@ -1,5 +1,6 @@ package cn.novalon.manage.sys.primitive; +import cn.novalon.manage.common.exception.ValidationException; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -14,8 +15,8 @@ class EmailTest { @Test void testOf_NullEmail() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Email.of(null) ); assertEquals("Email is required", exception.getMessage()); @@ -23,8 +24,8 @@ class EmailTest { @Test void testOf_EmptyEmail() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Email.of("") ); assertEquals("Email is required", exception.getMessage()); @@ -32,8 +33,8 @@ class EmailTest { @Test void testOf_WhitespaceOnlyEmail() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Email.of(" ") ); assertEquals("Email is required", exception.getMessage()); @@ -41,8 +42,8 @@ class EmailTest { @Test void testOf_InvalidEmail_NoAtSymbol() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Email.of("testexample.com") ); assertEquals("Invalid email format", exception.getMessage()); @@ -50,8 +51,8 @@ class EmailTest { @Test void testOf_InvalidEmail_NoDomain() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Email.of("test@") ); assertEquals("Invalid email format", exception.getMessage()); @@ -59,8 +60,8 @@ class EmailTest { @Test void testOf_InvalidEmail_NoTLD() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Email.of("test@example") ); assertEquals("Invalid email format", exception.getMessage()); @@ -68,8 +69,8 @@ class EmailTest { @Test void testOf_InvalidEmail_ShortTLD() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Email.of("test@example.c") ); assertEquals("Invalid email format", exception.getMessage()); @@ -202,8 +203,8 @@ class EmailTest { @Test void testOf_ValidEmail_WithLeadingTrailingWhitespace() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Email.of(" test@example.com ") ); assertEquals("Invalid email format", exception.getMessage()); @@ -217,8 +218,8 @@ class EmailTest { @Test void testOf_ValidEmail_WithMultipleAtSymbols() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Email.of("test@@example.com") ); assertEquals("Invalid email format", exception.getMessage()); @@ -226,8 +227,8 @@ class EmailTest { @Test void testOf_ValidEmail_WithSpecialCharsInLocalPart() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Email.of("test!#$%&'*+/=?^_`{|}~-@example.com") ); assertEquals("Invalid email format", exception.getMessage()); diff --git a/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/PasswordDetailedTest.java b/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/PasswordDetailedTest.java index b0f2d6a..8cfa57f 100644 --- a/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/PasswordDetailedTest.java +++ b/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/PasswordDetailedTest.java @@ -58,9 +58,9 @@ class PasswordDetailedTest { @Test void testExactlyMinLengthPassword() { - Password password = Password.of("Valid1@"); + Password password = Password.of("Valid12@"); assertNotNull(password); - assertEquals("Valid1@", password.getValue()); + assertEquals("Valid12@", password.getValue()); } @Test @@ -161,7 +161,7 @@ class PasswordDetailedTest { @Test void testPasswordWithOnlyDigitAndSpecial() { ValidationException exception = assertThrows(ValidationException.class, () -> { - Password.of("123456@"); + Password.of("12345678@"); }); assertEquals(ErrorCode.VALIDATION_INVALID_VALUE, exception.getErrorCode()); } @@ -175,10 +175,9 @@ class PasswordDetailedTest { @Test void testPasswordWithSpaces() { - ValidationException exception = assertThrows(ValidationException.class, () -> { - Password.of("Valid @123"); - }); - assertEquals(ErrorCode.VALIDATION_REQUIRED, exception.getErrorCode()); + Password password = Password.of("Valid @123"); + assertNotNull(password); + assertEquals("Valid @123", password.getValue()); } @Test @@ -245,9 +244,9 @@ class PasswordDetailedTest { @Test void testPasswordWithUnicodeCharacters() { - Password password = Password.of("密码@123"); + Password password = Password.of("密码测试Abc@123"); assertNotNull(password); - assertEquals("密码@123", password.getValue()); + assertEquals("密码测试Abc@123", password.getValue()); } @Test diff --git a/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/PasswordTest.java b/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/PasswordTest.java index 48eb1db..d4ebab1 100644 --- a/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/PasswordTest.java +++ b/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/PasswordTest.java @@ -1,5 +1,6 @@ package cn.novalon.manage.sys.primitive; +import cn.novalon.manage.common.exception.ValidationException; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -14,74 +15,74 @@ class PasswordTest { @Test void testOf_NullPassword() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, - () -> Password.of(null) - ); + ValidationException exception = assertThrows( + ValidationException.class, + () -> Password.of(null)); assertEquals("Password is required", exception.getMessage()); } @Test void testOf_EmptyPassword() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, - () -> Password.of("") - ); + ValidationException exception = assertThrows( + ValidationException.class, + () -> Password.of("")); assertEquals("Password is required", exception.getMessage()); } @Test void testOf_WhitespaceOnlyPassword() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, - () -> Password.of(" ") - ); + ValidationException exception = assertThrows( + ValidationException.class, + () -> Password.of(" ")); assertEquals("Password is required", exception.getMessage()); } @Test void testOf_TooShortPassword() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, - () -> Password.of("Test@1") - ); + ValidationException exception = assertThrows( + ValidationException.class, + () -> Password.of("Test@1")); assertEquals("Password must be at least 8 characters long", exception.getMessage()); } @Test void testOf_NoUppercase() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, - () -> Password.of("test@123") - ); - assertEquals("Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", exception.getMessage()); + ValidationException exception = assertThrows( + ValidationException.class, + () -> Password.of("test@123")); + assertEquals( + "Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", + exception.getMessage()); } @Test void testOf_NoLowercase() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, - () -> Password.of("TEST@123") - ); - assertEquals("Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", exception.getMessage()); + ValidationException exception = assertThrows( + ValidationException.class, + () -> Password.of("TEST@123")); + assertEquals( + "Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", + exception.getMessage()); } @Test void testOf_NoDigit() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, - () -> Password.of("Test@abc") - ); - assertEquals("Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", exception.getMessage()); + ValidationException exception = assertThrows( + ValidationException.class, + () -> Password.of("Test@abc")); + assertEquals( + "Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", + exception.getMessage()); } @Test void testOf_NoSpecialCharacter() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, - () -> Password.of("Test1234") - ); - assertEquals("Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", exception.getMessage()); + ValidationException exception = assertThrows( + ValidationException.class, + () -> Password.of("Test1234")); + assertEquals( + "Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", + exception.getMessage()); } @Test @@ -180,19 +181,21 @@ class PasswordTest { @Test void testOf_WithNumbersOnly() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, - () -> Password.of("12345678") - ); - assertEquals("Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", exception.getMessage()); + ValidationException exception = assertThrows( + ValidationException.class, + () -> Password.of("12345678")); + assertEquals( + "Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", + exception.getMessage()); } @Test void testOf_WithLettersOnly() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, - () -> Password.of("TestTest") - ); - assertEquals("Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", exception.getMessage()); + ValidationException exception = assertThrows( + ValidationException.class, + () -> Password.of("TestTest")); + assertEquals( + "Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character", + exception.getMessage()); } } diff --git a/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/UsernameTest.java b/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/UsernameTest.java index 8ba547a..1847962 100644 --- a/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/UsernameTest.java +++ b/novalon-manage-api/manage-sys/src/test/java/cn/novalon/manage/sys/primitive/UsernameTest.java @@ -1,5 +1,6 @@ package cn.novalon.manage.sys.primitive; +import cn.novalon.manage.common.exception.ValidationException; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -16,8 +17,8 @@ class UsernameTest { @Test void testOf_NullUsername() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Username.of(null) ); assertEquals("Username is required", exception.getMessage()); @@ -25,8 +26,8 @@ class UsernameTest { @Test void testOf_EmptyUsername() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Username.of("") ); assertEquals("Username is required", exception.getMessage()); @@ -34,8 +35,8 @@ class UsernameTest { @Test void testOf_WhitespaceOnlyUsername() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Username.of(" ") ); assertEquals("Username is required", exception.getMessage()); @@ -43,8 +44,8 @@ class UsernameTest { @Test void testOf_TooShortUsername() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Username.of("ab") ); assertEquals("Username must be at least 3 characters long", exception.getMessage()); @@ -52,8 +53,8 @@ class UsernameTest { @Test void testOf_TooLongUsername() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Username.of("a".repeat(51)) ); assertEquals("Username must be at most 50 characters long", exception.getMessage()); @@ -61,8 +62,8 @@ class UsernameTest { @Test void testOf_WithSpecialCharacters() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Username.of("user@name") ); assertEquals("Username can only contain letters, numbers, and underscores", exception.getMessage()); @@ -70,8 +71,8 @@ class UsernameTest { @Test void testOf_WithSpaces() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Username.of("user name") ); assertEquals("Username can only contain letters, numbers, and underscores", exception.getMessage()); @@ -79,8 +80,8 @@ class UsernameTest { @Test void testOf_WithHyphens() { - IllegalArgumentException exception = assertThrows( - IllegalArgumentException.class, + ValidationException exception = assertThrows( + ValidationException.class, () -> Username.of("user-name") ); assertEquals("Username can only contain letters, numbers, and underscores", exception.getMessage());