From 0e9dbf9bd981394cceda4af68bdf48a735b95a34 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Wed, 28 May 2025 11:51:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor!:=20`BasePropertyValidator`=20?= =?UTF-8?q?=E7=9A=84=20`equalsThat`=20=E9=87=8D=E5=91=BD=E5=90=8D=E4=B8=BA?= =?UTF-8?q?=20`equalTo`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../validator/BasePropertyValidator.java | 18 +++++----- .../ObjectPropertyValidatorTests.java | 34 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/plusone-validator/src/main/java/xyz/zhouxy/plusone/validator/BasePropertyValidator.java b/plusone-validator/src/main/java/xyz/zhouxy/plusone/validator/BasePropertyValidator.java index 8350810..3f511be 100644 --- a/plusone-validator/src/main/java/xyz/zhouxy/plusone/validator/BasePropertyValidator.java +++ b/plusone-validator/src/main/java/xyz/zhouxy/plusone/validator/BasePropertyValidator.java @@ -122,31 +122,31 @@ public abstract class BasePropertyValidator new IllegalArgumentException(String.format("The input must be equal to '%s'.", that))); } - public TPropertyValidator equalsThat(Object that, String errMsg) { - return equalsThat(that, convertExceptionCreator(errMsg)); + public TPropertyValidator equalTo(Object that, String errMsg) { + return equalTo(that, convertExceptionCreator(errMsg)); } - public TPropertyValidator equalsThat( + public TPropertyValidator equalTo( Object that, Supplier exceptionCreator) { - return equalsThat(that, convertExceptionCreator(exceptionCreator)); + return equalTo(that, convertExceptionCreator(exceptionCreator)); } - public TPropertyValidator equalsThat( + public TPropertyValidator equalTo( Object that, Function exceptionCreator) { withRule(value -> Objects.equals(value, that), exceptionCreator); return thisObject(); } // ================================ - // #endregion - equals + // #endregion - equalTo // ================================ // ================================ diff --git a/plusone-validator/src/test/java/xyz/zhouxy/plusone/example/validator/ObjectPropertyValidatorTests.java b/plusone-validator/src/test/java/xyz/zhouxy/plusone/example/validator/ObjectPropertyValidatorTests.java index 43c1684..35f066b 100644 --- a/plusone-validator/src/test/java/xyz/zhouxy/plusone/example/validator/ObjectPropertyValidatorTests.java +++ b/plusone-validator/src/test/java/xyz/zhouxy/plusone/example/validator/ObjectPropertyValidatorTests.java @@ -318,19 +318,19 @@ public class ObjectPropertyValidatorTests { // ================================ // ================================ - // #region - equalsThat + // #region - equalTo // ================================ @Test - void equalsThat_validInput() { + void equalTo_validInput() { BaseValidator validator = new BaseValidator() { { ruleForString(ExampleCommand::getStringProperty) - .equalsThat("Foo") - .equalsThat("Foo", "The stringProperty should be equal to 'Foo'.") - .equalsThat("Foo", () -> + .equalTo("Foo") + .equalTo("Foo", "The stringProperty should be equal to 'Foo'.") + .equalTo("Foo", () -> ExampleException.withMessage("The stringProperty should be equal to 'Foo'.")) - .equalsThat("Foo", str -> + .equalTo("Foo", str -> ExampleException.withMessage("The stringProperty should be equal to 'Foo', but is was '%s'.", str)); } }; @@ -341,13 +341,13 @@ public class ObjectPropertyValidatorTests { } @Test - void equalsThat_invalidInput() { + void equalTo_invalidInput() { ExampleCommand command = new ExampleCommand(); command.setStringProperty("Bar"); BaseValidator defaultRule = new BaseValidator() { { - ruleForString(ExampleCommand::getStringProperty).equalsThat("Foo"); + ruleForString(ExampleCommand::getStringProperty).equalTo("Foo"); } }; IllegalArgumentException eWithDefaultMessage = assertThrows( @@ -356,7 +356,7 @@ public class ObjectPropertyValidatorTests { BaseValidator ruleWithMessage = new BaseValidator() { { - ruleForString(ExampleCommand::getStringProperty).equalsThat("Foo", + ruleForString(ExampleCommand::getStringProperty).equalTo("Foo", "The stringProperty should be equal to 'Foo'."); } }; @@ -366,7 +366,7 @@ public class ObjectPropertyValidatorTests { BaseValidator ruleWithExceptionSupplier = new BaseValidator() { { - ruleForString(ExampleCommand::getStringProperty).equalsThat("Foo", + ruleForString(ExampleCommand::getStringProperty).equalTo("Foo", () -> ExampleException.withMessage("The stringProperty should be equal to 'Foo'.")); } }; @@ -376,7 +376,7 @@ public class ObjectPropertyValidatorTests { BaseValidator ruleWithExceptionFunction = new BaseValidator() { { - ruleForString(ExampleCommand::getStringProperty).equalsThat("Foo", + ruleForString(ExampleCommand::getStringProperty).equalTo("Foo", str -> ExampleException.withMessage("The stringProperty should be equal to 'Foo', but is was '%s'.", str)); } }; @@ -386,12 +386,12 @@ public class ObjectPropertyValidatorTests { } @Test - void equalsThat_nullInput() { + void equalTo_nullInput() { ExampleCommand command = new ExampleCommand(); BaseValidator defaultRule = new BaseValidator() { { - ruleForString(ExampleCommand::getStringProperty).equalsThat("Foo"); + ruleForString(ExampleCommand::getStringProperty).equalTo("Foo"); } }; IllegalArgumentException eWithDefaultMessage = assertThrows( @@ -400,7 +400,7 @@ public class ObjectPropertyValidatorTests { BaseValidator ruleWithMessage = new BaseValidator() { { - ruleForString(ExampleCommand::getStringProperty).equalsThat("Foo", + ruleForString(ExampleCommand::getStringProperty).equalTo("Foo", "The stringProperty should be equal to 'Foo'."); } }; @@ -410,7 +410,7 @@ public class ObjectPropertyValidatorTests { BaseValidator ruleWithExceptionSupplier = new BaseValidator() { { - ruleForString(ExampleCommand::getStringProperty).equalsThat("Foo", + ruleForString(ExampleCommand::getStringProperty).equalTo("Foo", () -> ExampleException.withMessage("The stringProperty should be equal to 'Foo'.")); } }; @@ -420,7 +420,7 @@ public class ObjectPropertyValidatorTests { BaseValidator ruleWithExceptionFunction = new BaseValidator() { { - ruleForString(ExampleCommand::getStringProperty).equalsThat("Foo", + ruleForString(ExampleCommand::getStringProperty).equalTo("Foo", str -> ExampleException.withMessage("The stringProperty should be equal to 'Foo', but is was '%s'.", str)); } }; @@ -430,7 +430,7 @@ public class ObjectPropertyValidatorTests { } // ================================ - // #endregion - equalsThat + // #endregion - equalTo // ================================ // ================================