Compare commits

...

6 Commits

Author SHA1 Message Date
e38be765a7 refactor!: 修改字符串校验逻辑
`StringPropertyValidator` 内置的校验规则中,除了 `notEmpty` 和 `notBlank` 之外,属性值为 null 时不做校验。
2025-05-20 18:00:19 +08:00
bce648dc51 test: 完善单元测试 2025-05-20 17:41:23 +08:00
ad74a0bcd0 test: 完成 ComparablePropertyValidator 单元测试 2025-05-20 11:36:24 +08:00
dcf620b63e refactor: 修改 BaseComparablePropertyValidator#inRange 默认提示语 2025-05-20 11:36:21 +08:00
358cdaf1ad test: 完善单元测试 2025-05-20 11:36:17 +08:00
07483627a8 refactor!: StringPropertyValidator#length 使用闭区间
`StringPropertyValidator#length` 校验字符串长度在区间内时,要求字符串长度大于等于最小长度(min),小于等于最大长度(max)。
2025-05-20 11:08:52 +08:00
16 changed files with 4947 additions and 40 deletions

View File

@@ -33,12 +33,7 @@
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

View File

@@ -33,7 +33,7 @@ class BaseComparablePropertyValidator<TObj,
public TPropertyValidator inRange(Range<TProperty> range) {
withRule(value -> value != null && range.contains(value),
convertExceptionCreator("The value is not in " + range.toString()));
convertExceptionCreator("The value is not in the interval " + range.toString()));
return thisObject();
}

View File

@@ -22,8 +22,6 @@ import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import com.google.common.base.Strings;
import xyz.zhouxy.plusone.commons.constant.PatternConsts;
import xyz.zhouxy.plusone.commons.util.AssertTools;
import xyz.zhouxy.plusone.commons.util.RegexTools;
@@ -61,7 +59,7 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
public <E extends RuntimeException> StringPropertyValidator<DTO> matches(
Pattern regex,
Function<String, E> exceptionCreator) {
withRule(input -> RegexTools.matches(input, regex), exceptionCreator);
withRule(input -> (input == null || RegexTools.matches(input, regex)), exceptionCreator);
return this;
}
@@ -103,7 +101,7 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesOne(
List<Pattern> regexs,
Function<String, E> exceptionCreator) {
withRule(input -> RegexTools.matchesOne(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
withRule(input -> input == null || RegexTools.matchesOne(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
return this;
}
@@ -145,7 +143,7 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
public <E extends RuntimeException> StringPropertyValidator<DTO> matchesAll(
Collection<Pattern> regexs,
Function<String, E> exceptionCreator) {
withRule(input -> RegexTools.matchesAll(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
withRule(input -> input == null || RegexTools.matchesAll(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
return this;
}
@@ -158,7 +156,7 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
// ================================
public StringPropertyValidator<DTO> notBlank() {
return notBlank("This String argument must have text; it must not be null, empty, or blank");
return notBlank("The value must have text; it must not be null, empty, or blank.");
}
public StringPropertyValidator<DTO> notBlank(String errMsg) {
@@ -209,6 +207,10 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
// #region - notEmpty
// ================================
public StringPropertyValidator<DTO> notEmpty() {
return notEmpty("The value must not be empty.");
}
public StringPropertyValidator<DTO> notEmpty(String errMsg) {
return notEmpty(convertExceptionCreator(errMsg));
}
@@ -227,28 +229,6 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
// #endregion - notEmpty
// ================================
// ================================
// #region - isNullOrEmpty
// ================================
public StringPropertyValidator<DTO> isNullOrEmpty(String errMsg) {
return isNullOrEmpty(convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringPropertyValidator<DTO> isNullOrEmpty(Supplier<E> exceptionCreator) {
return isNullOrEmpty(convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringPropertyValidator<DTO> isNullOrEmpty(
Function<String, E> exceptionCreator) {
withRule(Strings::isNullOrEmpty, exceptionCreator);
return this;
}
// ================================
// #endregion - isNullOrEmpty
// ================================
// ================================
// #region - length
// ================================
@@ -266,16 +246,16 @@ public class StringPropertyValidator<DTO> extends BaseComparablePropertyValidato
Function<String, E> exceptionCreator) {
AssertTools.checkArgument(length >= 0,
"The required length must be greater than or equal to 0.");
withRule(s -> s != null && s.length() == length, exceptionCreator);
withRule(s -> s == null || s.length() == length, exceptionCreator);
return this;
}
static boolean length(String str, int min, int max) {
if (str == null) {
return false;
return true;
}
final int len = str.length();
return len >= min && len < max;
return len >= min && len <= max;
}
public StringPropertyValidator<DTO> length(int min, int max, String errMsg) {

View File

@@ -0,0 +1,121 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.zhouxy.plusone.example;
import java.time.LocalDateTime;
import java.util.List;
/**
* 接口入参的 DTO 示例
*/
public class ExampleCommand {
private Boolean boolProperty;
private Integer intProperty;
private Long longProperty;
private Double doubleProperty;
private String stringProperty;
private LocalDateTime dateTimeProperty;
private Foo objectProperty;
private List<String> stringListProperty;
public ExampleCommand() {
}
public ExampleCommand(Boolean boolProperty, Integer intProperty, Long longProperty, Double doubleProperty,
String stringProperty, LocalDateTime dateTimeProperty, Foo objectProperty,
List<String> stringListProperty) {
this.boolProperty = boolProperty;
this.intProperty = intProperty;
this.longProperty = longProperty;
this.doubleProperty = doubleProperty;
this.stringProperty = stringProperty;
this.dateTimeProperty = dateTimeProperty;
this.objectProperty = objectProperty;
this.stringListProperty = stringListProperty;
}
public Boolean getBoolProperty() {
return boolProperty;
}
public void setBoolProperty(Boolean boolProperty) {
this.boolProperty = boolProperty;
}
public Integer getIntProperty() {
return intProperty;
}
public void setIntProperty(Integer intProperty) {
this.intProperty = intProperty;
}
public Long getLongProperty() {
return longProperty;
}
public void setLongProperty(Long longProperty) {
this.longProperty = longProperty;
}
public Double getDoubleProperty() {
return doubleProperty;
}
public void setDoubleProperty(Double doubleProperty) {
this.doubleProperty = doubleProperty;
}
public String getStringProperty() {
return stringProperty;
}
public void setStringProperty(String stringProperty) {
this.stringProperty = stringProperty;
}
public LocalDateTime getDateTimeProperty() {
return dateTimeProperty;
}
public void setDateTimeProperty(LocalDateTime dateTimeProperty) {
this.dateTimeProperty = dateTimeProperty;
}
public Foo getObjectProperty() {
return objectProperty;
}
public void setObjectProperty(Foo objectProperty) {
this.objectProperty = objectProperty;
}
public List<String> getStringListProperty() {
return stringListProperty;
}
public void setStringListProperty(List<String> stringListProperty) {
this.stringListProperty = stringListProperty;
}
@Override
public String toString() {
return "ExampleCommand [boolProperty=" + boolProperty + ", intProperty=" + intProperty + ", longProperty="
+ longProperty + ", doubleProperty=" + doubleProperty + ", stringProperty=" + stringProperty
+ ", dateTimeProperty=" + dateTimeProperty + ", objectProperty=" + objectProperty
+ ", stringListProperty=" + stringListProperty + "]";
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.zhouxy.plusone.example;
public class Foo {
private Integer intProperty;
private String stringProperty;
public Foo() {
}
public Foo(Integer intProperty, String stringProperty) {
this.intProperty = intProperty;
this.stringProperty = stringProperty;
}
public Integer getIntProperty() {
return intProperty;
}
public void setIntProperty(Integer intProperty) {
this.intProperty = intProperty;
}
public String getStringProperty() {
return stringProperty;
}
public void setStringProperty(String stringProperty) {
this.stringProperty = stringProperty;
}
@Override
public String toString() {
return "Foo [intProperty=" + intProperty + ", stringProperty=" + stringProperty + "]";
}
}

View File

@@ -0,0 +1,384 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.zhouxy.plusone.example.validator;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import xyz.zhouxy.plusone.example.ExampleCommand;
import xyz.zhouxy.plusone.validator.BaseValidator;
public class BoolPropertyValidatorTests {
// ================================
// #region - isTrueValue
// ================================
@Test
void isTrueValue_trueProperty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty).isTrueValue();
ruleForBool(ExampleCommand::getBoolProperty)
.isTrueValue("The boolProperty should be true.");
ruleForBool(ExampleCommand::getBoolProperty)
.isTrueValue(() -> ExampleException.withMessage("The boolProperty should be true."));
ruleForBool(ExampleCommand::getBoolProperty)
.isTrueValue(property -> ExampleException.withMessage(
"The boolProperty should be true, but it is `%s`", property));
}
};
ExampleCommand command = exampleCommandWithBoolProperty(true);
assertDoesNotThrow(() -> validator.validate(command));
}
@Test
void isTrueValue_default_falseProperty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty).isTrueValue();
}
};
ExampleCommand command = exampleCommandWithBoolProperty(false);
IllegalArgumentException exception = assertThrows(
IllegalArgumentException.class,
() -> validator.validate(command));
assertEquals("The value must be true.", exception.getMessage());
}
@Test
void isTrueValue_message_falseProperty() {
final String message = "The boolProperty should be true.";
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.isTrueValue(message);
}
};
ExampleCommand command = exampleCommandWithBoolProperty(false);
IllegalArgumentException exception = assertThrows(
IllegalArgumentException.class,
() -> validator.validate(command));
assertEquals(message, exception.getMessage());
}
@Test
void isTrueValue_exceptionSupplier_falseProperty() {
final String message = "The boolProperty should be true.";
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.isTrueValue(() -> ExampleException.withMessage(message));
}
};
ExampleCommand command = exampleCommandWithBoolProperty(false);
ExampleException exception = assertThrows(
ExampleException.class,
() -> validator.validate(command));
assertEquals(message, exception.getMessage());
}
@Test
void isTrueValue_exceptionFunction_falseProperty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.isTrueValue(property -> ExampleException.withMessage(
"The boolProperty should be true, but it is `%s`", property));
}
};
ExampleCommand command = exampleCommandWithBoolProperty(false);
ExampleException exception = assertThrows(
ExampleException.class,
() -> validator.validate(command));
assertEquals("The boolProperty should be true, but it is `false`", exception.getMessage());
}
@Test
void isTrueValue_default_nullProperty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty).isTrueValue();
}
};
ExampleCommand command = exampleCommandWithBoolProperty(null);
IllegalArgumentException exception = assertThrows(
IllegalArgumentException.class,
() -> validator.validate(command));
assertEquals("The value must be true.", exception.getMessage());
}
@Test
void isTrueValue_message_nullProperty() {
final String message = "The boolProperty should be true.";
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.isTrueValue(message);
}
};
ExampleCommand command = exampleCommandWithBoolProperty(null);
IllegalArgumentException exception = assertThrows(
IllegalArgumentException.class,
() -> validator.validate(command));
assertEquals(message, exception.getMessage());
}
@Test
void isTrueValue_exceptionSupplier_nullProperty() {
final String message = "The boolProperty should be true.";
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.isTrueValue(() -> ExampleException.withMessage(message));
}
};
ExampleCommand command = exampleCommandWithBoolProperty(null);
ExampleException exception = assertThrows(
ExampleException.class,
() -> validator.validate(command));
assertEquals(message, exception.getMessage());
}
@Test
void isTrueValue_exceptionFunction_nullProperty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.isTrueValue(property -> ExampleException.withMessage(
"The boolProperty should be true, but it is `%s`", property));
}
};
ExampleCommand command = exampleCommandWithBoolProperty(null);
ExampleException exception = assertThrows(
ExampleException.class,
() -> validator.validate(command));
assertEquals("The boolProperty should be true, but it is `null`", exception.getMessage());
}
// ================================
// #endregion - isTrueValue
// ================================
// ================================
// #region - isFalseValue
// ================================
@Test
void isFalseValue_falseProperty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty).isFalseValue();
ruleForBool(ExampleCommand::getBoolProperty)
.isFalseValue("The boolProperty should be false.");
ruleForBool(ExampleCommand::getBoolProperty)
.isFalseValue(() -> ExampleException.withMessage("The boolProperty should be false."));
ruleForBool(ExampleCommand::getBoolProperty)
.isFalseValue(property -> ExampleException.withMessage(
"The boolProperty should be false, but it is `%s`", property));
}
};
ExampleCommand command = exampleCommandWithBoolProperty(false);
assertDoesNotThrow(() -> validator.validate(command));
}
@Test
void isFalseValue_default_trueProperty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty).isFalseValue();
}
};
ExampleCommand command = exampleCommandWithBoolProperty(true);
IllegalArgumentException exception = assertThrows(
IllegalArgumentException.class,
() -> validator.validate(command));
assertEquals("The value must be false.", exception.getMessage());
}
@Test
void isFalseValue_message_trueProperty() {
final String message = "The boolProperty should be false.";
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.isFalseValue(message);
}
};
ExampleCommand command = exampleCommandWithBoolProperty(true);
IllegalArgumentException exception = assertThrows(
IllegalArgumentException.class,
() -> validator.validate(command));
assertEquals(message, exception.getMessage());
}
@Test
void isFalseValue_exceptionSupplier_trueProperty() {
final String message = "The boolProperty should be false.";
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.isFalseValue(() -> ExampleException.withMessage(message));
}
};
ExampleCommand command = exampleCommandWithBoolProperty(true);
ExampleException exception = assertThrows(
ExampleException.class,
() -> validator.validate(command));
assertEquals(message, exception.getMessage());
}
@Test
void isFalseValue_exceptionFunction_trueProperty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.isFalseValue(property -> ExampleException.withMessage(
"The boolProperty should be false, but it is `%s`", property));
}
};
ExampleCommand command = exampleCommandWithBoolProperty(true);
ExampleException exception = assertThrows(
ExampleException.class,
() -> validator.validate(command));
assertEquals("The boolProperty should be false, but it is `true`", exception.getMessage());
}
@Test
void isFalseValue_default_nullProperty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty).isFalseValue();
}
};
ExampleCommand command = exampleCommandWithBoolProperty(null);
IllegalArgumentException exception = assertThrows(
IllegalArgumentException.class,
() -> validator.validate(command));
assertEquals("The value must be false.", exception.getMessage());
}
@Test
void isFalseValue_message_nullProperty() {
final String message = "The boolProperty should be false.";
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.isFalseValue(message);
}
};
ExampleCommand command = exampleCommandWithBoolProperty(null);
IllegalArgumentException exception = assertThrows(
IllegalArgumentException.class,
() -> validator.validate(command));
assertEquals(message, exception.getMessage());
}
@Test
void isFalseValue_exceptionSupplier_nullProperty() {
final String message = "The boolProperty should be false.";
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.isFalseValue(() -> ExampleException.withMessage(message));
}
};
ExampleCommand command = exampleCommandWithBoolProperty(null);
ExampleException exception = assertThrows(
ExampleException.class,
() -> validator.validate(command));
assertEquals(message, exception.getMessage());
}
@Test
void isFalseValue_exceptionFunction_nullProperty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.isFalseValue(property -> ExampleException.withMessage(
"The boolProperty should be false, but it is `%s`", property));
}
};
ExampleCommand command = exampleCommandWithBoolProperty(null);
ExampleException exception = assertThrows(
ExampleException.class,
() -> validator.validate(command));
assertEquals("The boolProperty should be false, but it is `null`", exception.getMessage());
}
// ================================
// #endregion - isFalseValue
// ================================
static ExampleCommand exampleCommandWithBoolProperty(Boolean boolProperty) {
ExampleCommand exampleCommand = new ExampleCommand();
exampleCommand.setBoolProperty(boolProperty);
return exampleCommand;
}
}

View File

@@ -0,0 +1,245 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.zhouxy.plusone.example.validator;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.Test;
import com.google.common.collect.Lists;
import xyz.zhouxy.plusone.example.ExampleCommand;
import xyz.zhouxy.plusone.validator.BaseValidator;
public class CollectionPropertyValidatorTests {
static final String MESSAGE_NOT_EMPTY = "The stringListProperty should not be empty.";
static final String MESSAGE_EMPTY = "The stringListProperty should be empty.";
// ================================
// #region - notEmpty
// ================================
@Test
void notEmpty_stringListIsNotEmpty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForCollection(ExampleCommand::getStringListProperty).notEmpty(MESSAGE_NOT_EMPTY);
ruleForCollection(ExampleCommand::getStringListProperty)
.notEmpty(() -> ExampleException.withMessage(MESSAGE_NOT_EMPTY));
ruleForCollection(ExampleCommand::getStringListProperty)
.notEmpty(strList -> ExampleException.withMessage(
"The stringListProperty should not be empty, but it is %s.", strList));
}
};
ExampleCommand command = exampleCommandWithStringListProperty(Lists.newArrayList("A", "B", "C"));
assertDoesNotThrow(() -> validator.validate(command));
}
@Test
void notEmpty_message_stringListIsEmpty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForCollection(ExampleCommand::getStringListProperty).notEmpty(MESSAGE_NOT_EMPTY);
}
};
ExampleCommand command = exampleCommandWithStringListProperty(Collections.emptyList());
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_NOT_EMPTY, e.getMessage());
}
@Test
void notEmpty_exceptionSupplier_stringListIsEmpty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForCollection(ExampleCommand::getStringListProperty)
.notEmpty(() -> ExampleException.withMessage(MESSAGE_NOT_EMPTY));
}
};
ExampleCommand command = exampleCommandWithStringListProperty(Collections.emptyList());
ExampleException e = assertThrows(ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_NOT_EMPTY, e.getMessage());
}
@Test
void notEmpty_exceptionFunction_stringListIsEmpty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForCollection(ExampleCommand::getStringListProperty)
.notEmpty(strList -> ExampleException.withMessage(
"The stringListProperty should not be empty, but it is %s.", strList));
}
};
ExampleCommand command = exampleCommandWithStringListProperty(Collections.emptyList());
ExampleException e = assertThrows(ExampleException.class, () -> validator.validate(command));
assertEquals("The stringListProperty should not be empty, but it is [].", e.getMessage());
}
@Test
void notEmpty_message_stringListIsNull() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForCollection(ExampleCommand::getStringListProperty).notEmpty(MESSAGE_NOT_EMPTY);
}
};
ExampleCommand command = exampleCommandWithStringListProperty(null);
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_NOT_EMPTY, e.getMessage());
}
@Test
void notEmpty_exceptionSupplier_stringListIsNull() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForCollection(ExampleCommand::getStringListProperty)
.notEmpty(() -> ExampleException.withMessage(MESSAGE_NOT_EMPTY));
}
};
ExampleCommand command = exampleCommandWithStringListProperty(null);
ExampleException e = assertThrows(ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_NOT_EMPTY, e.getMessage());
}
@Test
void notEmpty_exceptionFunction_stringListIsNull() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForCollection(ExampleCommand::getStringListProperty)
.notEmpty(strList -> ExampleException.withMessage(
"The stringListProperty should not be empty, but it is %s.", strList));
}
};
ExampleCommand command = exampleCommandWithStringListProperty(null);
ExampleException e = assertThrows(ExampleException.class, () -> validator.validate(command));
assertEquals("The stringListProperty should not be empty, but it is null.", e.getMessage());
}
// ================================
// #endregion - notEmpty
// ================================
// ================================
// #region - isEmpty
// ================================
@Test
void isEmpty_stringListIsEmpty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForCollection(ExampleCommand::getStringListProperty).isEmpty(MESSAGE_EMPTY);
ruleForCollection(ExampleCommand::getStringListProperty)
.isEmpty(() -> ExampleException.withMessage(MESSAGE_EMPTY));
ruleForCollection(ExampleCommand::getStringListProperty)
.isEmpty(strList -> ExampleException.withMessage(
"The stringListProperty should be empty, but it is %s.", strList));
}
};
ExampleCommand command = exampleCommandWithStringListProperty(Collections.emptyList());
assertDoesNotThrow(() -> validator.validate(command));
}
@Test
void isEmpty_stringListIsNull() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForCollection(ExampleCommand::getStringListProperty).isEmpty(MESSAGE_EMPTY);
ruleForCollection(ExampleCommand::getStringListProperty)
.isEmpty(() -> ExampleException.withMessage(MESSAGE_EMPTY));
ruleForCollection(ExampleCommand::getStringListProperty)
.isEmpty(strList -> ExampleException.withMessage(
"The stringListProperty should be empty, but it is %s.", strList));
}
};
ExampleCommand command = exampleCommandWithStringListProperty(null);
assertDoesNotThrow(() -> validator.validate(command));
}
@Test
void isEmpty_message_stringListIsNotEmpty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForCollection(ExampleCommand::getStringListProperty).isEmpty(MESSAGE_EMPTY);
}
};
ExampleCommand command = exampleCommandWithStringListProperty(Lists.newArrayList("A", "B", "C"));
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_EMPTY, e.getMessage());
}
@Test
void isEmpty_exceptionSupplier_stringListIsNotEmpty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForCollection(ExampleCommand::getStringListProperty)
.isEmpty(() -> ExampleException.withMessage(MESSAGE_EMPTY));
}
};
ExampleCommand command = exampleCommandWithStringListProperty(Lists.newArrayList("A", "B", "C"));
ExampleException e = assertThrows(ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_EMPTY, e.getMessage());
}
@Test
void isEmpty_exceptionFunction_stringListIsNotEmpty() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForCollection(ExampleCommand::getStringListProperty)
.isEmpty(strList -> ExampleException.withMessage(
"The stringListProperty should be empty, but it is %s.", strList));
}
};
ExampleCommand command = exampleCommandWithStringListProperty(Lists.newArrayList("A", "B", "C"));
ExampleException e = assertThrows(ExampleException.class, () -> validator.validate(command));
assertEquals("The stringListProperty should be empty, but it is [A, B, C].", e.getMessage());
}
// ================================
// #endregion - isEmpty
// ================================
static ExampleCommand exampleCommandWithStringListProperty(List<String> property) {
ExampleCommand exampleCommand = new ExampleCommand();
exampleCommand.setStringListProperty(property);
return exampleCommand;
}
}

View File

@@ -0,0 +1,249 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.zhouxy.plusone.example.validator;
import static org.junit.jupiter.api.Assertions.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.chrono.ChronoLocalDateTime;
import org.junit.jupiter.api.Test;
import com.google.common.collect.Range;
import xyz.zhouxy.plusone.example.ExampleCommand;
import xyz.zhouxy.plusone.validator.BaseValidator;
public class ComparablePropertyValidatorTests {
static final LocalDateTime MIN = LocalDate.of(2025, 5, 1).atStartOfDay();
static final LocalDateTime MAX = LocalDate.of(2025, 5, 31).atStartOfDay();
static final Range<ChronoLocalDateTime<?>> DATE_TIME_RANGE = Range.closedOpen(MIN, MAX);
static final String MESSAGE = String.format("The value should in the interval [%s,%s)", MIN, MAX);
// ================================
// #region - in the interval
// ================================
@Test
void inRange_valueIsInTheInterval() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForComparable(ExampleCommand::getDateTimeProperty)
.inRange(DATE_TIME_RANGE);
ruleForComparable(ExampleCommand::getDateTimeProperty)
.inRange(DATE_TIME_RANGE, MESSAGE);
ruleForComparable(ExampleCommand::getDateTimeProperty)
.inRange(DATE_TIME_RANGE, () -> ExampleException.withMessage(MESSAGE));
ruleForComparable(ExampleCommand::getDateTimeProperty)
.inRange(DATE_TIME_RANGE, property -> ExampleException.withMessage(
"The dateTimeProperty should in the interval [%s,%s), but it is %s", MIN, MAX, property));
ruleForInt(ExampleCommand::getIntProperty)
.inRange(Range.closed(18, 60));
ruleForLong(ExampleCommand::getLongProperty)
.inRange(Range.closed(10000000000L, 20000000000L));
}
};
ExampleCommand command = exampleCommandWithComparableProperty(18, 10000000000L, MIN);
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - in the interval
// ================================
// ================================
// #region - not in the interval
// ================================
@Test
void inRange_default_valueIsNotInTheInterval() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForComparable(ExampleCommand::getDateTimeProperty)
.inRange(DATE_TIME_RANGE);
}
};
ExampleCommand command = exampleCommandWithComparableProperty(18, 10000000000L, MAX);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class,
() -> validator.validate(command));
final String expected = String.format("The value is not in the interval %s", DATE_TIME_RANGE);
assertEquals(expected, e.getMessage());
}
@Test
void inRange_message_valueIsNotInTheInterval() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForComparable(ExampleCommand::getDateTimeProperty)
.inRange(DATE_TIME_RANGE, MESSAGE);
}
};
ExampleCommand command = exampleCommandWithComparableProperty(18, 10000000000L, MAX);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class,
() -> validator.validate(command));
assertEquals(MESSAGE, e.getMessage());
}
@Test
void inRange_exceptionSupplier_valueIsNotInTheInterval() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForComparable(ExampleCommand::getDateTimeProperty)
.inRange(DATE_TIME_RANGE, () -> ExampleException.withMessage(MESSAGE));
}
};
ExampleCommand command = exampleCommandWithComparableProperty(18, 10000000000L, MAX);
ExampleException e = assertThrows(
ExampleException.class,
() -> validator.validate(command));
assertEquals(MESSAGE, e.getMessage());
}
@Test
void inRange_exceptionFunction_valueIsNotInTheInterval() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForComparable(ExampleCommand::getDateTimeProperty)
.inRange(DATE_TIME_RANGE, property -> ExampleException.withMessage(
"The dateTimeProperty should in the interval [%s,%s), but it is %s", MIN, MAX, property));
}
};
ExampleCommand command = exampleCommandWithComparableProperty(18, 10000000000L, MAX);
ExampleException e = assertThrows(
ExampleException.class,
() -> validator.validate(command));
final String expected = String.format("The dateTimeProperty should in the interval [%s,%s), but it is %s", MIN, MAX, MAX);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - not in the interval
// ================================
// ================================
// #region - null
// ================================
@Test
void inRange_default_valueIsNull() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForComparable(ExampleCommand::getDateTimeProperty)
.inRange(DATE_TIME_RANGE);
}
};
ExampleCommand command = exampleCommandWithComparableProperty(null, null, null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class,
() -> validator.validate(command));
final String expected = String.format("The value is not in the interval %s", DATE_TIME_RANGE);
assertEquals(expected, e.getMessage());
}
@Test
void inRange_message_valueIsNull() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForComparable(ExampleCommand::getDateTimeProperty)
.inRange(DATE_TIME_RANGE, MESSAGE);
}
};
ExampleCommand command = exampleCommandWithComparableProperty(null, null, null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class,
() -> validator.validate(command));
assertEquals(MESSAGE, e.getMessage());
}
@Test
void inRange_exceptionSupplier_valueIsNull() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForComparable(ExampleCommand::getDateTimeProperty)
.inRange(DATE_TIME_RANGE, () -> ExampleException.withMessage(MESSAGE));
}
};
ExampleCommand command = exampleCommandWithComparableProperty(null, null, null);
ExampleException e = assertThrows(
ExampleException.class,
() -> validator.validate(command));
assertEquals(MESSAGE, e.getMessage());
}
@Test
void inRange_exceptionFunction_valueIsNull() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForComparable(ExampleCommand::getDateTimeProperty)
.inRange(DATE_TIME_RANGE, property -> ExampleException.withMessage(
"The dateTimeProperty should in the interval [%s,%s), but it is %s", MIN, MAX, property));
}
};
ExampleCommand command = exampleCommandWithComparableProperty(null, null, null);
ExampleException e = assertThrows(
ExampleException.class,
() -> validator.validate(command));
final String expected = String.format("The dateTimeProperty should in the interval [%s,%s), but it is null", MIN, MAX);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - null
// ================================
static ExampleCommand exampleCommandWithComparableProperty(
Integer intProperty,
Long longProperty,
LocalDateTime dateTimeProperty) {
ExampleCommand exampleCommand = new ExampleCommand();
exampleCommand.setIntProperty(intProperty);
exampleCommand.setLongProperty(longProperty);
exampleCommand.setDateTimeProperty(dateTimeProperty);
return exampleCommand;
}
}

View File

@@ -0,0 +1,772 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.zhouxy.plusone.example.validator;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import xyz.zhouxy.plusone.example.ExampleCommand;
import xyz.zhouxy.plusone.validator.BaseValidator;
public class DoublePropertyValidatorTests {
static final double MIN = 1.0;
static final double MAX = 5.0;
static final String MESSAGE_GT = "The value should be greater than " + MIN;
static final String MESSAGE_GE = "The value should be greater than or equal to " + MIN;
static final String MESSAGE_LT = "The value should be less than " + MAX;
static final String MESSAGE_LE = "The value should be less than or equal to " + MAX;
// ================================
// #region - gt_validValue
// ================================
@ParameterizedTest
@ValueSource(doubles = { MIN + 0.000000000000001, Double.MAX_VALUE })
void gt_all_validValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.gt(MIN);
ruleForDouble(ExampleCommand::getDoubleProperty)
.gt(MIN, MESSAGE_GT);
ruleForDouble(ExampleCommand::getDoubleProperty)
.gt(MIN, () -> ExampleException.withMessage(MESSAGE_GT));
ruleForDouble(ExampleCommand::getDoubleProperty)
.gt(MIN, property -> ExampleException.withMessage(
"The doubleProperty should be greater than %s, but it is %s", MIN, property));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - gt_validValue
// ================================
// ================================
// #region - gt_invalidValue
// ================================
@ParameterizedTest
@ValueSource(doubles = { MIN, MIN - 0.000000000000001, Double.MIN_VALUE })
void gt_default_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.gt(MIN);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be greater than " + MIN, e.getMessage());
}
@ParameterizedTest
@ValueSource(doubles = { MIN, MIN - 0.000000000000001, Double.MIN_VALUE })
void gt_message_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.gt(MIN, MESSAGE_GT);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GT, e.getMessage());
}
@ParameterizedTest
@ValueSource(doubles = { MIN, MIN - 0.000000000000001, Double.MIN_VALUE })
void gt_exceptionSupplier_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.gt(MIN, () -> ExampleException.withMessage(MESSAGE_GT));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GT, e.getMessage());
}
@ParameterizedTest
@ValueSource(doubles = { MIN, MIN - 0.000000000000001, Double.MIN_VALUE })
void gt_exceptionFunction_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.gt(MIN, property -> ExampleException.withMessage(
"The doubleProperty should be greater than %s, but it is %s", MIN, property));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The doubleProperty should be greater than %s, but it is %s", MIN, value);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - gt_invalidValue
// ================================
// ================================
// #region - gt_null
// ================================
@Test
void gt_default_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.gt(MIN);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be greater than " + MIN, e.getMessage());
}
@Test
void gt_message_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.gt(MIN, MESSAGE_GT);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GT, e.getMessage());
}
@Test
void gt_exceptionSupplier_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.gt(MIN, () -> ExampleException.withMessage(MESSAGE_GT));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GT, e.getMessage());
}
@Test
void gt_exceptionFunction_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.gt(MIN, property -> ExampleException.withMessage(
"The doubleProperty should be greater than %s, but it is %s", MIN, property));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The doubleProperty should be greater than %s, but it is null", MIN);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - gt_null
// ================================
// ================================
// #region - ge_validValue
// ================================
@ParameterizedTest
@ValueSource(doubles = { MIN, MIN + 0.000000000000001, Double.MAX_VALUE })
void ge_all_validValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.ge(MIN);
ruleForDouble(ExampleCommand::getDoubleProperty)
.ge(MIN, MESSAGE_GE);
ruleForDouble(ExampleCommand::getDoubleProperty)
.ge(MIN, () -> ExampleException.withMessage(MESSAGE_GE));
ruleForDouble(ExampleCommand::getDoubleProperty)
.ge(MIN, property -> ExampleException.withMessage(
"The doubleProperty should be greater than or equal to %s, but it is %s", MIN, property));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - ge_validValue
// ================================
// ================================
// #region - ge_invalidValue
// ================================
@ParameterizedTest
@ValueSource(doubles = { MIN - 0.000000000000001, Double.MIN_VALUE })
void ge_default_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.ge(MIN);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be greater than or equal to " + MIN, e.getMessage());
}
@ParameterizedTest
@ValueSource(doubles = { MIN - 0.000000000000001, Double.MIN_VALUE })
void ge_message_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.ge(MIN, MESSAGE_GE);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GE, e.getMessage());
}
@ParameterizedTest
@ValueSource(doubles = { MIN - 0.000000000000001, Double.MIN_VALUE })
void ge_exceptionSupplier_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.ge(MIN, () -> ExampleException.withMessage(MESSAGE_GE));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GE, e.getMessage());
}
@ParameterizedTest
@ValueSource(doubles = { MIN - 0.000000000000001, Double.MIN_VALUE })
void ge_exceptionFunction_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.ge(MIN, property -> ExampleException.withMessage(
"The doubleProperty should be greater than or equal to %s, but it is %s", MIN, property));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The doubleProperty should be greater than or equal to %s, but it is %s", MIN, value);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - ge_invalidValue
// ================================
// ================================
// #region - ge_null
// ================================
@Test
void ge_default_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.ge(MIN);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be greater than or equal to " + MIN, e.getMessage());
}
@Test
void ge_message_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.ge(MIN, MESSAGE_GE);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GE, e.getMessage());
}
@Test
void ge_exceptionSupplier_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.ge(MIN, () -> ExampleException.withMessage(MESSAGE_GE));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GE, e.getMessage());
}
@Test
void ge_exceptionFunction_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.ge(MIN, property -> ExampleException.withMessage(
"The doubleProperty should be greater than or equal to %s, but it is %s", MIN, property));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The doubleProperty should be greater than or equal to %s, but it is null", MIN);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - ge_null
// ================================
// ================================
// #region - lt_validValue
// ================================
@ParameterizedTest
@ValueSource(doubles = { MAX - 0.000000000000001, Double.MIN_VALUE })
void lt_all_validValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.lt(MAX);
ruleForDouble(ExampleCommand::getDoubleProperty)
.lt(MAX, MESSAGE_LT);
ruleForDouble(ExampleCommand::getDoubleProperty)
.lt(MAX, () -> ExampleException.withMessage(MESSAGE_LT));
ruleForDouble(ExampleCommand::getDoubleProperty)
.lt(MAX, property -> ExampleException.withMessage(
"The doubleProperty should be less than %s, but it is %s", MAX, property));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - lt_validValue
// ================================
// ================================
// #region - lt_invalidValue
// ================================
@ParameterizedTest
@ValueSource(doubles = { MAX, MAX + 0.000000000000001, Double.MAX_VALUE })
void lt_default_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.lt(MAX);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be less than " + MAX, e.getMessage());
}
@ParameterizedTest
@ValueSource(doubles = { MAX, MAX + 0.000000000000001, Double.MAX_VALUE })
void lt_message_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.lt(MAX, MESSAGE_LT);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LT, e.getMessage());
}
@ParameterizedTest
@ValueSource(doubles = { MAX, MAX + 0.000000000000001, Double.MAX_VALUE })
void lt_exceptionSupplier_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.lt(MAX, () -> ExampleException.withMessage(MESSAGE_LT));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LT, e.getMessage());
}
@ParameterizedTest
@ValueSource(doubles = { MAX, MAX + 0.000000000000001, Double.MAX_VALUE })
void lt_exceptionFunction_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.lt(MAX, property -> ExampleException.withMessage(
"The doubleProperty should be less than %s, but it is %s", MAX, property));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The doubleProperty should be less than %s, but it is %s", MAX, value);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - lt_invalidValue
// ================================
// ================================
// #region - lt_null
// ================================
@Test
void lt_default_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.lt(MAX);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be less than " + MAX, e.getMessage());
}
@Test
void lt_message_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.lt(MAX, MESSAGE_LT);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LT, e.getMessage());
}
@Test
void lt_exceptionSupplier_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.lt(MAX, () -> ExampleException.withMessage(MESSAGE_LT));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LT, e.getMessage());
}
@Test
void lt_exceptionFunction_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.lt(MAX, property -> ExampleException.withMessage(
"The doubleProperty should be less than %s, but it is %s", MAX, property));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The doubleProperty should be less than %s, but it is null", MAX);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - lt_null
// ================================
// ================================
// #region - le_validValue
// ================================
@ParameterizedTest
@ValueSource(doubles = { MAX, MAX - 0.000000000000001, Double.MIN_VALUE })
void le_all_validValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.le(MAX);
ruleForDouble(ExampleCommand::getDoubleProperty)
.le(MAX, MESSAGE_LE);
ruleForDouble(ExampleCommand::getDoubleProperty)
.le(MAX, () -> ExampleException.withMessage(MESSAGE_LE));
ruleForDouble(ExampleCommand::getDoubleProperty)
.le(MAX, property -> ExampleException.withMessage(
"The doubleProperty should be less than or equal to %s, but it is %s", MAX, property));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - le_validValue
// ================================
// ================================
// #region - le_invalidValue
// ================================
@ParameterizedTest
@ValueSource(doubles = { MAX + 0.000000000000001, Double.MAX_VALUE })
void le_default_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.le(MAX);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be less than or equal to " + MAX, e.getMessage());
}
@ParameterizedTest
@ValueSource(doubles = { MAX + 0.000000000000001, Double.MAX_VALUE })
void le_message_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.le(MAX, MESSAGE_LE);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LE, e.getMessage());
}
@ParameterizedTest
@ValueSource(doubles = { MAX + 0.000000000000001, Double.MAX_VALUE })
void le_exceptionSupplier_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.le(MAX, () -> ExampleException.withMessage(MESSAGE_LE));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LE, e.getMessage());
}
@ParameterizedTest
@ValueSource(doubles = { MAX + 0.000000000000001, Double.MAX_VALUE })
void le_exceptionFunction_invalidValue(double value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.le(MAX, property -> ExampleException.withMessage(
"The doubleProperty should be less than or equal to %s, but it is %s", MAX, property));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The doubleProperty should be less than or equal to %s, but it is %s", MAX, value);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - le_invalidValue
// ================================
// ================================
// #region - le_null
// ================================
@Test
void le_default_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.le(MAX);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be less than or equal to " + MAX, e.getMessage());
}
@Test
void le_message_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.le(MAX, MESSAGE_LE);
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LE, e.getMessage());
}
@Test
void le_exceptionSupplier_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.le(MAX, () -> ExampleException.withMessage(MESSAGE_LE));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LE, e.getMessage());
}
@Test
void le_exceptionFunction_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForDouble(ExampleCommand::getDoubleProperty)
.le(MAX, property -> ExampleException.withMessage(
"The doubleProperty should be less than or equal to %s, but it is %s", MAX, property));
}
};
ExampleCommand command = exampleCommandWithDoubleProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The doubleProperty should be less than or equal to %s, but it is null", MAX);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - le_null
// ================================
static ExampleCommand exampleCommandWithDoubleProperty(Double doubleProperty) {
ExampleCommand exampleCommand = new ExampleCommand();
exampleCommand.setDoubleProperty(doubleProperty);
return exampleCommand;
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.zhouxy.plusone.example.validator;
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
public class ExampleException extends RuntimeException {
private ExampleException(String message) {
super(message);
}
@StaticFactoryMethod
public static ExampleException withMessage(String message) {
return new ExampleException(message);
}
@StaticFactoryMethod
public static ExampleException withMessage(String format, Object... args) {
return new ExampleException(String.format(format, args));
}
}

View File

@@ -0,0 +1,771 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.zhouxy.plusone.example.validator;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import xyz.zhouxy.plusone.example.ExampleCommand;
import xyz.zhouxy.plusone.validator.BaseValidator;
public class IntPropertyValidatorTests {
static final int MIN = 0;
static final int MAX = 5;
static final String MESSAGE_GT = "The value should be greater than " + MIN;
static final String MESSAGE_GE = "The value should be greater than or equal to " + MIN;
static final String MESSAGE_LT = "The value should be less than " + MAX;
static final String MESSAGE_LE = "The value should be less than or equal to " + MAX;
// ================================
// #region - gt_validValue
// ================================
@ParameterizedTest
@ValueSource(ints = { MIN + 1, Integer.MAX_VALUE })
void gt_all_validValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.gt(MIN);
ruleForInt(ExampleCommand::getIntProperty)
.gt(MIN, MESSAGE_GT);
ruleForInt(ExampleCommand::getIntProperty)
.gt(MIN, () -> ExampleException.withMessage(MESSAGE_GT));
ruleForInt(ExampleCommand::getIntProperty)
.gt(MIN, property -> ExampleException.withMessage(
"The intProperty should be greater than %d, but it is %d", MIN, property));
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - gt_validValue
// ================================
// ================================
// #region - gt_invalidValue
// ================================
@ParameterizedTest
@ValueSource(ints = { MIN, MIN - 1, Integer.MIN_VALUE })
void gt_default_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.gt(MIN);
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be greater than " + MIN, e.getMessage());
}
@ParameterizedTest
@ValueSource(ints = { MIN, MIN - 1, Integer.MIN_VALUE })
void gt_message_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.gt(MIN, MESSAGE_GT);
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GT, e.getMessage());
}
@ParameterizedTest
@ValueSource(ints = { MIN, MIN - 1, Integer.MIN_VALUE })
void gt_exceptionSupplier_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.gt(MIN, () -> ExampleException.withMessage(MESSAGE_GT));
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GT, e.getMessage());
}
@ParameterizedTest
@ValueSource(ints = { MIN, MIN - 1, Integer.MIN_VALUE })
void gt_exceptionFunction_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.gt(MIN, property -> ExampleException.withMessage(
"The intProperty should be greater than %d, but it is %d", MIN, property));
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The intProperty should be greater than %d, but it is %d", MIN, value);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - gt_invalidValue
// ================================
// ================================
// #region - gt_null
// ================================
@Test
void gt_default_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.gt(MIN);
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be greater than " + MIN, e.getMessage());
}
@Test
void gt_message_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.gt(MIN, MESSAGE_GT);
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GT, e.getMessage());
}
@Test
void gt_exceptionSupplier_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.gt(MIN, () -> ExampleException.withMessage(MESSAGE_GT));
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GT, e.getMessage());
}
@Test
void gt_exceptionFunction_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.gt(MIN, property -> ExampleException.withMessage(
"The intProperty should be greater than %d, but it is %d", MIN, property));
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The intProperty should be greater than %d, but it is null", MIN);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - gt_null
// ================================
// ================================
// #region - ge_validValue
// ================================
@ParameterizedTest
@ValueSource(ints = { MIN, MIN + 1, Integer.MAX_VALUE })
void ge_all_validValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.ge(MIN);
ruleForInt(ExampleCommand::getIntProperty)
.ge(MIN, MESSAGE_GE);
ruleForInt(ExampleCommand::getIntProperty)
.ge(MIN, () -> ExampleException.withMessage(MESSAGE_GE));
ruleForInt(ExampleCommand::getIntProperty)
.ge(MIN, property -> ExampleException.withMessage(
"The intProperty should be greater than or equal to %d, but it is %d", MIN, property));
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - ge_validValue
// ================================
// ================================
// #region - ge_invalidValue
// ================================
@ParameterizedTest
@ValueSource(ints = { MIN - 1, Integer.MIN_VALUE })
void ge_default_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.ge(MIN);
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be greater than or equal to " + MIN, e.getMessage());
}
@ParameterizedTest
@ValueSource(ints = { MIN - 1, Integer.MIN_VALUE })
void ge_message_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.ge(MIN, MESSAGE_GE);
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GE, e.getMessage());
}
@ParameterizedTest
@ValueSource(ints = { MIN - 1, Integer.MIN_VALUE })
void ge_exceptionSupplier_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.ge(MIN, () -> ExampleException.withMessage(MESSAGE_GE));
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GE, e.getMessage());
}
@ParameterizedTest
@ValueSource(ints = { MIN - 1, Integer.MIN_VALUE })
void ge_exceptionFunction_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.ge(MIN, property -> ExampleException.withMessage(
"The intProperty should be greater than or equal to %d, but it is %d", MIN, property));
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The intProperty should be greater than or equal to %d, but it is %d", MIN, value);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - ge_invalidValue
// ================================
// ================================
// #region - ge_null
// ================================
@Test
void ge_default_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.ge(MIN);
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be greater than or equal to " + MIN, e.getMessage());
}
@Test
void ge_message_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.ge(MIN, MESSAGE_GE);
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GE, e.getMessage());
}
@Test
void ge_exceptionSupplier_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.ge(MIN, () -> ExampleException.withMessage(MESSAGE_GE));
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GE, e.getMessage());
}
@Test
void ge_exceptionFunction_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.ge(MIN, property -> ExampleException.withMessage(
"The intProperty should be greater than or equal to %d, but it is %d", MIN, property));
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The intProperty should be greater than or equal to %d, but it is null", MIN);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - ge_null
// ================================
// ================================
// #region - lt_validValue
// ================================
@ParameterizedTest
@ValueSource(ints = { MAX - 1, Integer.MIN_VALUE })
void lt_all_validValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.lt(MAX);
ruleForInt(ExampleCommand::getIntProperty)
.lt(MAX, MESSAGE_LT);
ruleForInt(ExampleCommand::getIntProperty)
.lt(MAX, () -> ExampleException.withMessage(MESSAGE_LT));
ruleForInt(ExampleCommand::getIntProperty)
.lt(MAX, property -> ExampleException.withMessage(
"The intProperty should be less than %d, but it is %d", MAX, property));
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - lt_validValue
// ================================
// ================================
// #region - lt_invalidValue
// ================================
@ParameterizedTest
@ValueSource(ints = { MAX, MAX + 1, Integer.MAX_VALUE })
void lt_default_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.lt(MAX);
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be less than " + MAX, e.getMessage());
}
@ParameterizedTest
@ValueSource(ints = { MAX, MAX + 1, Integer.MAX_VALUE })
void lt_message_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.lt(MAX, MESSAGE_LT);
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LT, e.getMessage());
}
@ParameterizedTest
@ValueSource(ints = { MAX, MAX + 1, Integer.MAX_VALUE })
void lt_exceptionSupplier_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.lt(MAX, () -> ExampleException.withMessage(MESSAGE_LT));
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LT, e.getMessage());
}
@ParameterizedTest
@ValueSource(ints = { MAX, MAX + 1, Integer.MAX_VALUE })
void lt_exceptionFunction_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.lt(MAX, property -> ExampleException.withMessage(
"The intProperty should be less than %d, but it is %d", MAX, property));
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The intProperty should be less than %d, but it is %d", MAX, value);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - lt_invalidValue
// ================================
// ================================
// #region - lt_null
// ================================
@Test
void lt_default_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.lt(MAX);
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be less than " + MAX, e.getMessage());
}
@Test
void lt_message_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.lt(MAX, MESSAGE_LT);
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LT, e.getMessage());
}
@Test
void lt_exceptionSupplier_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.lt(MAX, () -> ExampleException.withMessage(MESSAGE_LT));
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LT, e.getMessage());
}
@Test
void lt_exceptionFunction_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.lt(MAX, property -> ExampleException.withMessage(
"The intProperty should be less than %d, but it is %d", MAX, property));
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The intProperty should be less than %d, but it is null", MAX);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - lt_null
// ================================
// ================================
// #region - le_validValue
// ================================
@ParameterizedTest
@ValueSource(ints = { MAX, MAX - 1, Integer.MIN_VALUE })
void le_all_validValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.le(MAX);
ruleForInt(ExampleCommand::getIntProperty)
.le(MAX, MESSAGE_LE);
ruleForInt(ExampleCommand::getIntProperty)
.le(MAX, () -> ExampleException.withMessage(MESSAGE_LE));
ruleForInt(ExampleCommand::getIntProperty)
.le(MAX, property -> ExampleException.withMessage(
"The intProperty should be less than or equal to %d, but it is %d", MAX, property));
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - le_validValue
// ================================
// ================================
// #region - le_invalidValue
// ================================
@ParameterizedTest
@ValueSource(ints = { MAX + 1, Integer.MAX_VALUE })
void le_default_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.le(MAX);
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be less than or equal to " + MAX, e.getMessage());
}
@ParameterizedTest
@ValueSource(ints = { MAX + 1, Integer.MAX_VALUE })
void le_message_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.le(MAX, MESSAGE_LE);
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LE, e.getMessage());
}
@ParameterizedTest
@ValueSource(ints = { MAX + 1, Integer.MAX_VALUE })
void le_exceptionSupplier_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.le(MAX, () -> ExampleException.withMessage(MESSAGE_LE));
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LE, e.getMessage());
}
@ParameterizedTest
@ValueSource(ints = { MAX + 1, Integer.MAX_VALUE })
void le_exceptionFunction_invalidValue(int value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.le(MAX, property -> ExampleException.withMessage(
"The intProperty should be less than or equal to %d, but it is %d", MAX, property));
}
};
ExampleCommand command = exampleCommandWithIntProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The intProperty should be less than or equal to %d, but it is %d", MAX, value);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - le_invalidValue
// ================================
// ================================
// #region - le_null
// ================================
@Test
void le_default_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.le(MAX);
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be less than or equal to " + MAX, e.getMessage());
}
@Test
void le_message_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.le(MAX, MESSAGE_LE);
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LE, e.getMessage());
}
@Test
void le_exceptionSupplier_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.le(MAX, () -> ExampleException.withMessage(MESSAGE_LE));
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LE, e.getMessage());
}
@Test
void le_exceptionFunction_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForInt(ExampleCommand::getIntProperty)
.le(MAX, property -> ExampleException.withMessage(
"The intProperty should be less than or equal to %d, but it is %d", MAX, property));
}
};
ExampleCommand command = exampleCommandWithIntProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The intProperty should be less than or equal to %d, but it is null", MAX);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - le_null
// ================================
static ExampleCommand exampleCommandWithIntProperty(Integer intProperty) {
ExampleCommand exampleCommand = new ExampleCommand();
exampleCommand.setIntProperty(intProperty);
return exampleCommand;
}
}

View File

@@ -0,0 +1,772 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.zhouxy.plusone.example.validator;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import xyz.zhouxy.plusone.example.ExampleCommand;
import xyz.zhouxy.plusone.validator.BaseValidator;
public class LongPropertyValidatorTests {
static final long MIN = 10000000000L;
static final long MAX = 10000000008L;
static final String MESSAGE_GT = "The value should be greater than " + MIN;
static final String MESSAGE_GE = "The value should be greater than or equal to " + MIN;
static final String MESSAGE_LT = "The value should be less than " + MAX;
static final String MESSAGE_LE = "The value should be less than or equal to " + MAX;
// ================================
// #region - gt_validValue
// ================================
@ParameterizedTest
@ValueSource(longs = { MIN + 1, Long.MAX_VALUE })
void gt_all_validValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.gt(MIN);
ruleForLong(ExampleCommand::getLongProperty)
.gt(MIN, MESSAGE_GT);
ruleForLong(ExampleCommand::getLongProperty)
.gt(MIN, () -> ExampleException.withMessage(MESSAGE_GT));
ruleForLong(ExampleCommand::getLongProperty)
.gt(MIN, property -> ExampleException.withMessage(
"The longProperty should be greater than %d, but it is %d", MIN, property));
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - gt_validValue
// ================================
// ================================
// #region - gt_invalidValue
// ================================
@ParameterizedTest
@ValueSource(longs = { MIN, MIN - 1, Long.MIN_VALUE })
void gt_default_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.gt(MIN);
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be greater than " + MIN, e.getMessage());
}
@ParameterizedTest
@ValueSource(longs = { MIN, MIN - 1, Long.MIN_VALUE })
void gt_message_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.gt(MIN, MESSAGE_GT);
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GT, e.getMessage());
}
@ParameterizedTest
@ValueSource(longs = { MIN, MIN - 1, Long.MIN_VALUE })
void gt_exceptionSupplier_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.gt(MIN, () -> ExampleException.withMessage(MESSAGE_GT));
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GT, e.getMessage());
}
@ParameterizedTest
@ValueSource(longs = { MIN, MIN - 1, Long.MIN_VALUE })
void gt_exceptionFunction_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.gt(MIN, property -> ExampleException.withMessage(
"The longProperty should be greater than %d, but it is %d", MIN, property));
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The longProperty should be greater than %d, but it is %d", MIN, value);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - gt_invalidValue
// ================================
// ================================
// #region - gt_null
// ================================
@Test
void gt_default_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.gt(MIN);
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be greater than " + MIN, e.getMessage());
}
@Test
void gt_message_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.gt(MIN, MESSAGE_GT);
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GT, e.getMessage());
}
@Test
void gt_exceptionSupplier_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.gt(MIN, () -> ExampleException.withMessage(MESSAGE_GT));
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GT, e.getMessage());
}
@Test
void gt_exceptionFunction_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.gt(MIN, property -> ExampleException.withMessage(
"The longProperty should be greater than %d, but it is %d", MIN, property));
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The longProperty should be greater than %d, but it is null", MIN);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - gt_null
// ================================
// ================================
// #region - ge_validValue
// ================================
@ParameterizedTest
@ValueSource(longs = { MIN, MIN + 1, Long.MAX_VALUE })
void ge_all_validValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.ge(MIN);
ruleForLong(ExampleCommand::getLongProperty)
.ge(MIN, MESSAGE_GE);
ruleForLong(ExampleCommand::getLongProperty)
.ge(MIN, () -> ExampleException.withMessage(MESSAGE_GE));
ruleForLong(ExampleCommand::getLongProperty)
.ge(MIN, property -> ExampleException.withMessage(
"The longProperty should be greater than or equal to %d, but it is %d", MIN, property));
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - ge_validValue
// ================================
// ================================
// #region - ge_invalidValue
// ================================
@ParameterizedTest
@ValueSource(longs = { MIN - 1, Long.MIN_VALUE })
void ge_default_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.ge(MIN);
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be greater than or equal to " + MIN, e.getMessage());
}
@ParameterizedTest
@ValueSource(longs = { MIN - 1, Long.MIN_VALUE })
void ge_message_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.ge(MIN, MESSAGE_GE);
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GE, e.getMessage());
}
@ParameterizedTest
@ValueSource(longs = { MIN - 1, Long.MIN_VALUE })
void ge_exceptionSupplier_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.ge(MIN, () -> ExampleException.withMessage(MESSAGE_GE));
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GE, e.getMessage());
}
@ParameterizedTest
@ValueSource(longs = { MIN - 1, Long.MIN_VALUE })
void ge_exceptionFunction_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.ge(MIN, property -> ExampleException.withMessage(
"The longProperty should be greater than or equal to %d, but it is %d", MIN, property));
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The longProperty should be greater than or equal to %d, but it is %d", MIN, value);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - ge_invalidValue
// ================================
// ================================
// #region - ge_null
// ================================
@Test
void ge_default_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.ge(MIN);
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be greater than or equal to " + MIN, e.getMessage());
}
@Test
void ge_message_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.ge(MIN, MESSAGE_GE);
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GE, e.getMessage());
}
@Test
void ge_exceptionSupplier_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.ge(MIN, () -> ExampleException.withMessage(MESSAGE_GE));
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_GE, e.getMessage());
}
@Test
void ge_exceptionFunction_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.ge(MIN, property -> ExampleException.withMessage(
"The longProperty should be greater than or equal to %d, but it is %d", MIN, property));
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The longProperty should be greater than or equal to %d, but it is null", MIN);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - ge_null
// ================================
// ================================
// #region - lt_validValue
// ================================
@ParameterizedTest
@ValueSource(longs = { MAX - 1, Long.MIN_VALUE })
void lt_all_validValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.lt(MAX);
ruleForLong(ExampleCommand::getLongProperty)
.lt(MAX, MESSAGE_LT);
ruleForLong(ExampleCommand::getLongProperty)
.lt(MAX, () -> ExampleException.withMessage(MESSAGE_LT));
ruleForLong(ExampleCommand::getLongProperty)
.lt(MAX, property -> ExampleException.withMessage(
"The longProperty should be less than %d, but it is %d", MAX, property));
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - lt_validValue
// ================================
// ================================
// #region - lt_invalidValue
// ================================
@ParameterizedTest
@ValueSource(longs = { MAX, MAX + 1, Long.MAX_VALUE })
void lt_default_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.lt(MAX);
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be less than " + MAX, e.getMessage());
}
@ParameterizedTest
@ValueSource(longs = { MAX, MAX + 1, Long.MAX_VALUE })
void lt_message_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.lt(MAX, MESSAGE_LT);
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LT, e.getMessage());
}
@ParameterizedTest
@ValueSource(longs = { MAX, MAX + 1, Long.MAX_VALUE })
void lt_exceptionSupplier_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.lt(MAX, () -> ExampleException.withMessage(MESSAGE_LT));
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LT, e.getMessage());
}
@ParameterizedTest
@ValueSource(longs = { MAX, MAX + 1, Long.MAX_VALUE })
void lt_exceptionFunction_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.lt(MAX, property -> ExampleException.withMessage(
"The longProperty should be less than %d, but it is %d", MAX, property));
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The longProperty should be less than %d, but it is %d", MAX, value);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - lt_invalidValue
// ================================
// ================================
// #region - lt_null
// ================================
@Test
void lt_default_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.lt(MAX);
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be less than " + MAX, e.getMessage());
}
@Test
void lt_message_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.lt(MAX, MESSAGE_LT);
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LT, e.getMessage());
}
@Test
void lt_exceptionSupplier_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.lt(MAX, () -> ExampleException.withMessage(MESSAGE_LT));
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LT, e.getMessage());
}
@Test
void lt_exceptionFunction_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.lt(MAX, property -> ExampleException.withMessage(
"The longProperty should be less than %d, but it is %d", MAX, property));
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The longProperty should be less than %d, but it is null", MAX);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - lt_null
// ================================
// ================================
// #region - le_validValue
// ================================
@ParameterizedTest
@ValueSource(longs = { MAX, MAX - 1, Long.MIN_VALUE })
void le_all_validValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.le(MAX);
ruleForLong(ExampleCommand::getLongProperty)
.le(MAX, MESSAGE_LE);
ruleForLong(ExampleCommand::getLongProperty)
.le(MAX, () -> ExampleException.withMessage(MESSAGE_LE));
ruleForLong(ExampleCommand::getLongProperty)
.le(MAX, property -> ExampleException.withMessage(
"The longProperty should be less than or equal to %d, but it is %d", MAX, property));
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - le_validValue
// ================================
// ================================
// #region - le_invalidValue
// ================================
@ParameterizedTest
@ValueSource(longs = { MAX + 1, Long.MAX_VALUE })
void le_default_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.le(MAX);
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be less than or equal to " + MAX, e.getMessage());
}
@ParameterizedTest
@ValueSource(longs = { MAX + 1, Long.MAX_VALUE })
void le_message_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.le(MAX, MESSAGE_LE);
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LE, e.getMessage());
}
@ParameterizedTest
@ValueSource(longs = { MAX + 1, Long.MAX_VALUE })
void le_exceptionSupplier_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.le(MAX, () -> ExampleException.withMessage(MESSAGE_LE));
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LE, e.getMessage());
}
@ParameterizedTest
@ValueSource(longs = { MAX + 1, Long.MAX_VALUE })
void le_exceptionFunction_invalidValue(long value) {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.le(MAX, property -> ExampleException.withMessage(
"The longProperty should be less than or equal to %d, but it is %d", MAX, property));
}
};
ExampleCommand command = exampleCommandWithLongProperty(value);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The longProperty should be less than or equal to %d, but it is %d", MAX, value);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - le_invalidValue
// ================================
// ================================
// #region - le_null
// ================================
@Test
void le_default_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.le(MAX);
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals("The value should be less than or equal to " + MAX, e.getMessage());
}
@Test
void le_message_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.le(MAX, MESSAGE_LE);
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
IllegalArgumentException e = assertThrows(
IllegalArgumentException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LE, e.getMessage());
}
@Test
void le_exceptionSupplier_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.le(MAX, () -> ExampleException.withMessage(MESSAGE_LE));
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
assertEquals(MESSAGE_LE, e.getMessage());
}
@Test
void le_exceptionFunction_null() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForLong(ExampleCommand::getLongProperty)
.le(MAX, property -> ExampleException.withMessage(
"The longProperty should be less than or equal to %d, but it is %d", MAX, property));
}
};
ExampleCommand command = exampleCommandWithLongProperty(null);
ExampleException e = assertThrows(
ExampleException.class, () -> validator.validate(command));
final String expected = String.format("The longProperty should be less than or equal to %d, but it is null", MAX);
assertEquals(expected, e.getMessage());
}
// ================================
// #endregion - le_null
// ================================
static ExampleCommand exampleCommandWithLongProperty(Long longProperty) {
ExampleCommand exampleCommand = new ExampleCommand();
exampleCommand.setLongProperty(longProperty);
return exampleCommand;
}
}

View File

@@ -0,0 +1,338 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.zhouxy.plusone.example.validator;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.util.Objects;
import org.junit.jupiter.api.Test;
import com.google.common.collect.Lists;
import xyz.zhouxy.plusone.commons.collection.CollectionTools;
import xyz.zhouxy.plusone.commons.util.DateTimeTools;
import xyz.zhouxy.plusone.commons.util.StringTools;
import xyz.zhouxy.plusone.example.ExampleCommand;
import xyz.zhouxy.plusone.example.Foo;
import xyz.zhouxy.plusone.validator.BaseValidator;
public class ObjectPropertyValidatorTests {
// ================================
// #region - withRule
// ================================
@Test
void withRule() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleFor(ExampleCommand::getBoolProperty)
.notNull("The boolProperty cannot be null.")
.withRule(Boolean.TRUE::equals, "The boolProperty should be true.");
ruleFor(ExampleCommand::getIntProperty)
.withRule(intProperty -> intProperty > 0, "The intProperty should be greater than 0.");
ruleFor(ExampleCommand::getLongProperty)
.withRule(longProperty -> longProperty > 0L,
() -> ExampleException.withMessage("The longProperty should be greater than 0."));
ruleFor(ExampleCommand::getDoubleProperty)
.withRule(doubleProperty -> doubleProperty > 0.00,
doubleProperty -> ExampleException.withMessage("The doubleProperty should be greater than 0, but it was: %s", doubleProperty));
ruleFor(ExampleCommand::getStringProperty)
.notNull()
.withRule(stringProperty -> stringProperty.length() > 2,
() -> ExampleException.withMessage("The length of stringProperty should be greater than 2."));
ruleFor(ExampleCommand::getDateTimeProperty)
.withRule(DateTimeTools::isFuture,
() -> new DateTimeException("The dateTimeProperty should be a future time."));
ruleFor(ExampleCommand::getObjectProperty)
.notNull("The objectProperty cannot be null.");
ruleFor(ExampleCommand::getStringListProperty)
.withRule(CollectionTools::isNotEmpty, "The stringListProperty cannot be empty.");
withRule(command -> {
Foo objectProperty = command.getObjectProperty();
if (!Objects.equals(command.getIntProperty(), objectProperty.getIntProperty())) {
throw ExampleException.withMessage("intProperty invalid.");
}
});
}
};
ExampleCommand command = new ExampleCommand(
true,
Integer.MAX_VALUE,
Long.MAX_VALUE,
Double.MAX_VALUE,
"StringValue",
LocalDateTime.now().plusDays(1),
new Foo(Integer.MAX_VALUE, "StringValue"),
Lists.newArrayList("ABC", "DEF"));
assertDoesNotThrow(() -> validator.validate(command));
}
// ================================
// #endregion - withRule
// ================================
// ================================
// #region - notNull
// ================================
@Test
void notNull_validInput() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.notNull();
ruleForInt(ExampleCommand::getIntProperty)
.notNull("The intProperty cannot be null");
ruleForLong(ExampleCommand::getLongProperty)
.notNull(() -> ExampleException.withMessage("The longProperty cannot be null"));
ruleForDouble(ExampleCommand::getDoubleProperty)
.notNull(d -> ExampleException.withMessage("The doubleProperty cannot be null, but it was %s", d));
ruleForString(ExampleCommand::getStringProperty)
.notNull();
ruleForComparable(ExampleCommand::getDateTimeProperty)
.notNull("The dateTimeProperty cannot be null");
ruleFor(ExampleCommand::getObjectProperty)
.notNull(() -> ExampleException.withMessage("The objectProperty cannot be null"));
ruleForCollection(ExampleCommand::getStringListProperty)
.notNull(d -> ExampleException.withMessage("The stringListProperty cannot be null, but it was %s", d));
}
};
ExampleCommand command = new ExampleCommand(
true,
Integer.MAX_VALUE,
Long.MAX_VALUE,
Double.MAX_VALUE,
"StringValue",
LocalDateTime.now().plusDays(1),
new Foo(Integer.MAX_VALUE, "StringValue"),
Lists.newArrayList("ABC", "DEF"));
assertDoesNotThrow(() -> validator.validate(command));
}
@Test
void notNull_invalidInput() {
ExampleCommand command = new ExampleCommand();
BaseValidator<ExampleCommand> defaultRule = new BaseValidator<ExampleCommand>() {
{
ruleFor(ExampleCommand::getObjectProperty)
.notNull();
}
};
IllegalArgumentException eWithDefaultMessage = assertThrows(
IllegalArgumentException.class, () -> defaultRule.validate(command));
assertEquals("Value could not be null.", eWithDefaultMessage.getMessage());
BaseValidator<ExampleCommand> ruleWithMessage = new BaseValidator<ExampleCommand>() {
{
ruleFor(ExampleCommand::getObjectProperty)
.notNull("The objectProperty could not be null.");
}
};
IllegalArgumentException eWithSpecifiedMessage = assertThrows(
IllegalArgumentException.class, () -> ruleWithMessage.validate(command));
assertEquals("The objectProperty could not be null.", eWithSpecifiedMessage.getMessage());
BaseValidator<ExampleCommand> ruleWithExceptionSupplier = new BaseValidator<ExampleCommand>() {
{
ruleFor(ExampleCommand::getObjectProperty)
.notNull(() -> ExampleException.withMessage("The objectProperty could not be null."));
}
};
ExampleException specifiedException = assertThrows(
ExampleException.class, () -> ruleWithExceptionSupplier.validate(command));
assertEquals("The objectProperty could not be null.", specifiedException.getMessage());
BaseValidator<ExampleCommand> ruleWithExceptionFunction = new BaseValidator<ExampleCommand>() {
{
ruleFor(ExampleCommand::getObjectProperty)
.notNull(str -> ExampleException.withMessage("The objectProperty could not be null, but is was " + str));
}
};
ExampleException specifiedException2 = assertThrows(
ExampleException.class, () -> ruleWithExceptionFunction.validate(command));
assertEquals("The objectProperty could not be null, but is was null", specifiedException2.getMessage());
}
// ================================
// #endregion - notNull
// ================================
// ================================
// #region - isNull
// ================================
@Test
void isNull_validInput() {
BaseValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForBool(ExampleCommand::getBoolProperty)
.isNull("The boolProperty should be null");
ruleForInt(ExampleCommand::getIntProperty)
.isNull("The intProperty should be null");
ruleForLong(ExampleCommand::getLongProperty)
.isNull(() -> ExampleException.withMessage("The longProperty should be null"));
ruleForDouble(ExampleCommand::getDoubleProperty)
.isNull(d -> ExampleException.withMessage("The doubleProperty should be null, but it was %s", d));
ruleForString(ExampleCommand::getStringProperty)
.isNull("The stringProperty should be null");
ruleForComparable(ExampleCommand::getDateTimeProperty)
.isNull("The dateTimeProperty should be null");
ruleFor(ExampleCommand::getObjectProperty)
.isNull(() -> ExampleException.withMessage("The objectProperty should be null"));
ruleForCollection(ExampleCommand::getStringListProperty)
.isNull(d -> ExampleException.withMessage("The stringListProperty should be null, but it was %s", d));
}
};
ExampleCommand command = new ExampleCommand();
assertDoesNotThrow(() -> validator.validate(command));
}
@Test
void isNull_invalidInput() {
ExampleCommand command = new ExampleCommand();
command.setObjectProperty(new Foo(Integer.MAX_VALUE, "StringValue"));
BaseValidator<ExampleCommand> ruleWithMessage = new BaseValidator<ExampleCommand>() {
{
ruleFor(ExampleCommand::getObjectProperty)
.isNull("The objectProperty should be null.");
}
};
IllegalArgumentException eWithSpecifiedMessage = assertThrows(
IllegalArgumentException.class, () -> ruleWithMessage.validate(command));
assertEquals("The objectProperty should be null.", eWithSpecifiedMessage.getMessage());
BaseValidator<ExampleCommand> ruleWithExceptionSupplier = new BaseValidator<ExampleCommand>() {
{
ruleFor(ExampleCommand::getObjectProperty)
.isNull(() -> ExampleException.withMessage("The objectProperty should be null."));
}
};
ExampleException specifiedException = assertThrows(
ExampleException.class, () -> ruleWithExceptionSupplier.validate(command));
assertEquals("The objectProperty should be null.", specifiedException.getMessage());
BaseValidator<ExampleCommand> ruleWithExceptionFunction = new BaseValidator<ExampleCommand>() {
{
ruleFor(ExampleCommand::getObjectProperty)
.isNull(str -> ExampleException.withMessage("The objectProperty should be null, but is was " + str));
}
};
ExampleException specifiedException2 = assertThrows(
ExampleException.class, () -> ruleWithExceptionFunction.validate(command));
assertEquals("The objectProperty should be null, but is was " + command.getObjectProperty(), specifiedException2.getMessage());
}
// ================================
// #endregion - isNull
// ================================
// ================================
// #region - equalsThat
// ================================
@Test
void equalsThat() {
}
@Test
void equalsThat2() {
}
@Test
void equalsThat3() {
}
@Test
void equalsThat4() {
}
// ================================
// #endregion - equalsThat
// ================================
// ================================
// #region - must
// ================================
@Test
void must() {
}
@Test
void must2() {
}
@Test
void must3() {
}
@Test
void must4() {
}
@Test
void must5() {
}
@Test
void must6() {
}
@Test
void must7() {
}
@Test
void must8() {
}
// ================================
// #endregion - must
// ================================
}

View File

@@ -1,4 +1,4 @@
package xyz.zhouxy.plusone.validator.test;
package xyz.zhouxy.plusone.example.validator;
import static xyz.zhouxy.plusone.commons.constant.PatternConsts.*;

View File

@@ -1,4 +1,4 @@
package xyz.zhouxy.plusone.validator.map.test;
package xyz.zhouxy.plusone.map.validator;
import static org.junit.jupiter.api.Assertions.*;