diff --git a/pom.xml b/pom.xml index acf1209..e394e82 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ xyz.zhouxy.plusone plusone-validator - 0.1.0-SNAPSHOT + 0.1.1-SNAPSHOT plusone-validator http://zhouxy.xyz diff --git a/src/main/java/xyz/zhouxy/plusone/validator/BoolValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/BoolValidator.java index 37bc4ca..9912c37 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/BoolValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/BoolValidator.java @@ -50,7 +50,7 @@ public class BoolValidator extends PropertyValidator returnThis() { + protected BoolValidator thisObject() { return this; } } diff --git a/src/main/java/xyz/zhouxy/plusone/validator/CollectionValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/CollectionValidator.java index f033c92..5a79048 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/CollectionValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/CollectionValidator.java @@ -53,7 +53,7 @@ public class CollectionValidator extends PropertyValidator returnThis() { + protected CollectionValidator thisObject() { return this; } } diff --git a/src/main/java/xyz/zhouxy/plusone/validator/DoubleValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/DoubleValidator.java index 3ad5173..4174e79 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/DoubleValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/DoubleValidator.java @@ -29,7 +29,7 @@ public class DoubleValidator extends PropertyValidator returnThis() { + protected DoubleValidator thisObject() { return this; } } diff --git a/src/main/java/xyz/zhouxy/plusone/validator/IntValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/IntValidator.java index 980726f..29fc24f 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/IntValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/IntValidator.java @@ -29,7 +29,7 @@ public class IntValidator extends PropertyValidator returnThis() { + protected IntValidator thisObject() { return this; } } diff --git a/src/main/java/xyz/zhouxy/plusone/validator/ObjectValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/ObjectValidator.java index 8e9cbc4..6f2de5f 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/ObjectValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/ObjectValidator.java @@ -9,7 +9,7 @@ public class ObjectValidator extends PropertyValidator returnThis() { + protected ObjectValidator thisObject() { return this; } } diff --git a/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java index d1d8ec1..3ff1d79 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java @@ -47,7 +47,7 @@ abstract class PropertyValidator { public THIS notNull(Function exceptionCreator) { withRule(Objects::nonNull, exceptionCreator); - return returnThis(); + return thisObject(); } // ====== isNull ===== @@ -62,7 +62,7 @@ abstract class PropertyValidator { public THIS isNull(Function exceptionCreator) { withRule(Objects::isNull, exceptionCreator); - return returnThis(); + return thisObject(); } // ===== equals ===== @@ -83,7 +83,7 @@ abstract class PropertyValidator { public THIS equalsThat( Object that, Function exceptionCreator) { withRule(value -> Objects.equals(value, that), exceptionCreator); - return returnThis(); + return thisObject(); } // ===== state ===== @@ -106,7 +106,7 @@ abstract class PropertyValidator { Predicate condition, Function exceptionCreator) { withRule(condition, exceptionCreator); - return returnThis(); + return thisObject(); } // ======================================================================== @@ -125,5 +125,5 @@ abstract class PropertyValidator { return value -> exceptionSupplier.get(); } - protected abstract THIS returnThis(); + protected abstract THIS thisObject(); } diff --git a/src/main/java/xyz/zhouxy/plusone/validator/StringValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/StringValidator.java index ef9ecae..7e02756 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/StringValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/StringValidator.java @@ -173,7 +173,7 @@ public class StringValidator extends PropertyValidator returnThis() { + protected StringValidator thisObject() { return this; } } 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 8bb0f07..d9ffe81 100644 --- a/src/test/java/xyz/zhouxy/plusone/validator/test/BaseValidatorTest.java +++ b/src/test/java/xyz/zhouxy/plusone/validator/test/BaseValidatorTest.java @@ -8,15 +8,16 @@ import org.junit.Test; import xyz.zhouxy.plusone.constant.RegexConsts; import xyz.zhouxy.plusone.validator.BaseValidator; -import xyz.zhouxy.plusone.validator.IValidateRequired; +import xyz.zhouxy.plusone.validator.ValidateUtil; public class BaseValidatorTest { @Test - public void testRuleFor() { + public void testValidate() { RegisterCommand registerCommand = new RegisterCommand("zhouxy108", "luquanlion@outlook.com", "22336", "A1b2C3d4", "A1b2C3d4", Arrays.asList(new String[] { "admin", "editor" })); - registerCommand.validate(); + RegisterCommandValidator.INSTANCE.validate(registerCommand); + ValidateUtil.validate(registerCommand, RegisterCommandValidator.INSTANCE); System.out.println(registerCommand); } } @@ -50,7 +51,7 @@ class RegisterCommandValidator extends BaseValidator { /** * RegisterCommand */ -class RegisterCommand implements IValidateRequired { +class RegisterCommand { private String username; private String account; @@ -59,11 +60,6 @@ class RegisterCommand implements IValidateRequired { private String password2; private List roles; - @Override - public void validate() { - RegisterCommandValidator.INSTANCE.validate(this); - } - public RegisterCommand() { }