From 1d4eadaefeb24a25deaab14c948fc42d15700152 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Wed, 19 Jul 2023 10:34:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95=E7=B1=BB?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/validator/test/BaseValidatorTest.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/test/java/xyz/zhouxy/plusone/validator/test/BaseValidatorTest.java b/src/test/java/xyz/zhouxy/plusone/validator/test/BaseValidatorTest.java index 6cc351b..d6e2927 100644 --- a/src/test/java/xyz/zhouxy/plusone/validator/test/BaseValidatorTest.java +++ b/src/test/java/xyz/zhouxy/plusone/validator/test/BaseValidatorTest.java @@ -4,9 +4,12 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; import xyz.zhouxy.plusone.commons.constant.PatternConsts; +import xyz.zhouxy.plusone.commons.function.Predicates; +import xyz.zhouxy.plusone.commons.util.RegexUtil; import xyz.zhouxy.plusone.validator.BaseValidator; import xyz.zhouxy.plusone.validator.ValidateUtil; @@ -28,9 +31,11 @@ class RegisterCommandValidator extends BaseValidator { private RegisterCommandValidator() { ruleForString(RegisterCommand::getUsername) - .notNull("用户名不能为空") - .matches(PatternConsts.USERNAME, - username -> new IllegalArgumentException(String.format("用户名\"%s\"不符合规范", username))); + .isTrue(Predicates.of(Objects::nonNull) + .and(StringUtils::isNotEmpty) + .and(StringUtils::isNotBlank) + .and(username -> RegexUtil.matches(username, PatternConsts.USERNAME)), + username -> new IllegalArgumentException(String.format("用户名【%s】不符合规范", username))); ruleForString(RegisterCommand::getAccount) .notNull("请输入邮箱地址或手机号") .matchesOne(Arrays.asList(PatternConsts.EMAIL, PatternConsts.MOBILE_PHONE), "请输入邮箱地址或手机号");