fix(QueryUtil): 修复条件判断逻辑错误

test: 更新密码测试用例以符合新验证规则
test: 更新用户名测试用例以使用ValidationException
test: 更新邮箱测试用例以使用ValidationException
test: 更新角色创建命令测试以使用ValidationException
build: 移除dependency-check-maven插件
This commit is contained in:
张翔
2026-03-24 15:15:20 +08:00
parent f6916fb5b9
commit 3d6a0bd7b8
7 changed files with 107 additions and 120 deletions
@@ -158,7 +158,7 @@ public class QueryUtil {
return false;
}
}
return false;
return true;
}
private static List<Field> getAllFields(Class<?> clazz, List<Field> fields) {
-18
View File
@@ -198,24 +198,6 @@
<excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
</configuration>
</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>
</build>
</project>
@@ -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",
@@ -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());
@@ -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
@@ -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());
}
}
@@ -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());