refactor!: BasePropertyValidatorequalsThat 重命名为 equalTo

This commit is contained in:
zhouxy108 2025-05-28 11:51:14 +08:00
parent f21e9727fa
commit 0e9dbf9bd9
2 changed files with 26 additions and 26 deletions

View File

@ -122,31 +122,31 @@ public abstract class BasePropertyValidator<T, TProperty, TPropertyValidator ext
// ================================
// ================================
// #region - equals
// #region - equalTo
// ================================
public TPropertyValidator equalsThat(Object that) {
return equalsThat(that,
public TPropertyValidator equalTo(Object that) {
return equalTo(that,
value -> 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 <E extends RuntimeException> TPropertyValidator equalsThat(
public <E extends RuntimeException> TPropertyValidator equalTo(
Object that, Supplier<E> exceptionCreator) {
return equalsThat(that, convertExceptionCreator(exceptionCreator));
return equalTo(that, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> TPropertyValidator equalsThat(
public <E extends RuntimeException> TPropertyValidator equalTo(
Object that, Function<TProperty, E> exceptionCreator) {
withRule(value -> Objects.equals(value, that), exceptionCreator);
return thisObject();
}
// ================================
// #endregion - equals
// #endregion - equalTo
// ================================
// ================================

View File

@ -318,19 +318,19 @@ public class ObjectPropertyValidatorTests {
// ================================
// ================================
// #region - equalsThat
// #region - equalTo
// ================================
@Test
void equalsThat_validInput() {
void equalTo_validInput() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
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<ExampleCommand> defaultRule = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty).equalsThat("Foo");
ruleForString(ExampleCommand::getStringProperty).equalTo("Foo");
}
};
IllegalArgumentException eWithDefaultMessage = assertThrows(
@ -356,7 +356,7 @@ public class ObjectPropertyValidatorTests {
BaseValidator<ExampleCommand> ruleWithMessage = new BaseValidator<ExampleCommand>() {
{
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<ExampleCommand> ruleWithExceptionSupplier = new BaseValidator<ExampleCommand>() {
{
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<ExampleCommand> ruleWithExceptionFunction = new BaseValidator<ExampleCommand>() {
{
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<ExampleCommand> defaultRule = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty).equalsThat("Foo");
ruleForString(ExampleCommand::getStringProperty).equalTo("Foo");
}
};
IllegalArgumentException eWithDefaultMessage = assertThrows(
@ -400,7 +400,7 @@ public class ObjectPropertyValidatorTests {
BaseValidator<ExampleCommand> ruleWithMessage = new BaseValidator<ExampleCommand>() {
{
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<ExampleCommand> ruleWithExceptionSupplier = new BaseValidator<ExampleCommand>() {
{
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<ExampleCommand> ruleWithExceptionFunction = new BaseValidator<ExampleCommand>() {
{
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
// ================================
// ================================