修改方法名。

0.4.x 0.1.1-SNAPSHOT
ZhouXY108 2023-01-05 14:56:17 +08:00
parent 2768e4eb2b
commit 40f30f88a1
9 changed files with 17 additions and 21 deletions

View File

@ -6,7 +6,7 @@
<groupId>xyz.zhouxy.plusone</groupId>
<artifactId>plusone-validator</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.1-SNAPSHOT</version>
<name>plusone-validator</name>
<url>http://zhouxy.xyz</url>

View File

@ -50,7 +50,7 @@ public class BoolValidator<DTO> extends PropertyValidator<DTO, Boolean, BoolVali
}
@Override
protected BoolValidator<DTO> returnThis() {
protected BoolValidator<DTO> thisObject() {
return this;
}
}

View File

@ -53,7 +53,7 @@ public class CollectionValidator<DTO, T> extends PropertyValidator<DTO, Collecti
}
@Override
protected CollectionValidator<DTO, T> returnThis() {
protected CollectionValidator<DTO, T> thisObject() {
return this;
}
}

View File

@ -29,7 +29,7 @@ public class DoubleValidator<DTO> extends PropertyValidator<DTO, Double, DoubleV
}
@Override
protected DoubleValidator<DTO> returnThis() {
protected DoubleValidator<DTO> thisObject() {
return this;
}
}

View File

@ -29,7 +29,7 @@ public class IntValidator<DTO> extends PropertyValidator<DTO, Integer, IntValida
}
@Override
protected IntValidator<DTO> returnThis() {
protected IntValidator<DTO> thisObject() {
return this;
}
}

View File

@ -9,7 +9,7 @@ public class ObjectValidator<DTO, T> extends PropertyValidator<DTO, T, ObjectVal
}
@Override
protected ObjectValidator<DTO, T> returnThis() {
protected ObjectValidator<DTO, T> thisObject() {
return this;
}
}

View File

@ -47,7 +47,7 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
public <E extends RuntimeException> THIS notNull(Function<PROPERTY, E> exceptionCreator) {
withRule(Objects::nonNull, exceptionCreator);
return returnThis();
return thisObject();
}
// ====== isNull =====
@ -62,7 +62,7 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
public <E extends RuntimeException> THIS isNull(Function<PROPERTY, E> exceptionCreator) {
withRule(Objects::isNull, exceptionCreator);
return returnThis();
return thisObject();
}
// ===== equals =====
@ -83,7 +83,7 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
public <E extends RuntimeException> THIS equalsThat(
Object that, Function<PROPERTY, E> exceptionCreator) {
withRule(value -> Objects.equals(value, that), exceptionCreator);
return returnThis();
return thisObject();
}
// ===== state =====
@ -106,7 +106,7 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
Predicate<PROPERTY> condition,
Function<PROPERTY, E> exceptionCreator) {
withRule(condition, exceptionCreator);
return returnThis();
return thisObject();
}
// ========================================================================
@ -125,5 +125,5 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
return value -> exceptionSupplier.get();
}
protected abstract THIS returnThis();
protected abstract THIS thisObject();
}

View File

@ -173,7 +173,7 @@ public class StringValidator<DTO> extends PropertyValidator<DTO, String, StringV
}
@Override
protected StringValidator<DTO> returnThis() {
protected StringValidator<DTO> thisObject() {
return this;
}
}

View File

@ -8,15 +8,16 @@ import org.junit.Test;
import xyz.zhouxy.plusone.constant.RegexConsts;
import xyz.zhouxy.plusone.validator.BaseValidator;
import xyz.zhouxy.plusone.validator.IValidateRequired;
import xyz.zhouxy.plusone.validator.ValidateUtil;
public class BaseValidatorTest {
@Test
public void testRuleFor() {
public void testValidate() {
RegisterCommand registerCommand = new RegisterCommand("zhouxy108", "luquanlion@outlook.com", "22336", "A1b2C3d4",
"A1b2C3d4",
Arrays.asList(new String[] { "admin", "editor" }));
registerCommand.validate();
RegisterCommandValidator.INSTANCE.validate(registerCommand);
ValidateUtil.validate(registerCommand, RegisterCommandValidator.INSTANCE);
System.out.println(registerCommand);
}
}
@ -50,7 +51,7 @@ class RegisterCommandValidator extends BaseValidator<RegisterCommand> {
/**
* RegisterCommand
*/
class RegisterCommand implements IValidateRequired {
class RegisterCommand {
private String username;
private String account;
@ -59,11 +60,6 @@ class RegisterCommand implements IValidateRequired {
private String password2;
private List<String> roles;
@Override
public void validate() {
RegisterCommandValidator.INSTANCE.validate(this);
}
public RegisterCommand() {
}