test: 修改测试用例以覆盖 BaseValidator#ruleFor

This commit is contained in:
zhouxy108 2025-06-01 08:48:23 +08:00
parent 3ef2ebac2f
commit c27525a637

View File

@ -46,21 +46,21 @@ public class ObjectPropertyValidatorTests {
void notNull_validInput() { void notNull_validInput() {
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() { IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{ {
ruleForBool(ExampleCommand::getBoolProperty) ruleFor(ExampleCommand::getBoolProperty)
.notNull(); .notNull();
ruleForInt(ExampleCommand::getIntProperty) ruleFor(ExampleCommand::getIntProperty)
.notNull("The intProperty cannot be null"); .notNull("The intProperty cannot be null");
ruleForLong(ExampleCommand::getLongProperty) ruleFor(ExampleCommand::getLongProperty)
.notNull(() -> ExampleException.withMessage("The longProperty cannot be null")); .notNull(() -> ExampleException.withMessage("The longProperty cannot be null"));
ruleForDouble(ExampleCommand::getDoubleProperty) ruleFor(ExampleCommand::getDoubleProperty)
.notNull(d -> ExampleException.withMessage("The doubleProperty cannot be null, but it was %s", d)); .notNull(d -> ExampleException.withMessage("The doubleProperty cannot be null, but it was %s", d));
ruleForString(ExampleCommand::getStringProperty) ruleFor(ExampleCommand::getStringProperty)
.notNull(); .notNull();
ruleForComparable(ExampleCommand::getDateTimeProperty) ruleFor(ExampleCommand::getDateTimeProperty)
.notNull("The dateTimeProperty cannot be null"); .notNull("The dateTimeProperty cannot be null");
ruleFor(ExampleCommand::getObjectProperty) ruleFor(ExampleCommand::getObjectProperty)
.notNull(() -> ExampleException.withMessage("The objectProperty cannot be null")); .notNull(() -> ExampleException.withMessage("The objectProperty cannot be null"));
ruleForCollection(ExampleCommand::getStringListProperty) ruleFor(ExampleCommand::getStringListProperty)
.notNull(d -> ExampleException.withMessage("The stringListProperty cannot be null, but it was %s", d)); .notNull(d -> ExampleException.withMessage("The stringListProperty cannot be null, but it was %s", d));
} }
}; };
@ -134,21 +134,21 @@ public class ObjectPropertyValidatorTests {
void isNull_validInput() { void isNull_validInput() {
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() { IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{ {
ruleForBool(ExampleCommand::getBoolProperty) ruleFor(ExampleCommand::getBoolProperty)
.isNull(); .isNull();
ruleForInt(ExampleCommand::getIntProperty) ruleFor(ExampleCommand::getIntProperty)
.isNull("The intProperty should be null"); .isNull("The intProperty should be null");
ruleForLong(ExampleCommand::getLongProperty) ruleFor(ExampleCommand::getLongProperty)
.isNull(() -> ExampleException.withMessage("The longProperty should be null")); .isNull(() -> ExampleException.withMessage("The longProperty should be null"));
ruleForDouble(ExampleCommand::getDoubleProperty) ruleFor(ExampleCommand::getDoubleProperty)
.isNull(d -> ExampleException.withMessage("The doubleProperty should be null, but it was %s", d)); .isNull(d -> ExampleException.withMessage("The doubleProperty should be null, but it was %s", d));
ruleForString(ExampleCommand::getStringProperty) ruleFor(ExampleCommand::getStringProperty)
.isNull(); .isNull();
ruleForComparable(ExampleCommand::getDateTimeProperty) ruleFor(ExampleCommand::getDateTimeProperty)
.isNull("The dateTimeProperty should be null"); .isNull("The dateTimeProperty should be null");
ruleFor(ExampleCommand::getObjectProperty) ruleFor(ExampleCommand::getObjectProperty)
.isNull(() -> ExampleException.withMessage("The objectProperty should be null")); .isNull(() -> ExampleException.withMessage("The objectProperty should be null"));
ruleForCollection(ExampleCommand::getStringListProperty) ruleFor(ExampleCommand::getStringListProperty)
.isNull(d -> ExampleException.withMessage("The stringListProperty should be null, but it was %s", d)); .isNull(d -> ExampleException.withMessage("The stringListProperty should be null, but it was %s", d));
} }
}; };