@Data
@Accessors(chain = true)
public class WhiteAEntity {
@Matcher({"a","b","c","null"})
private String name;
private String address;
}
注意:测试代码这里全部采用Spock测试框架进行工具方面的测试,主要是为了方便
def "只有指定的值才能通过"() {
given:
WhiteAEntity entity = new WhiteAEntity()
entity.setName(name as String)
expect:
boolean actResult = MkValidators.check(entity)
if (!actResult) {
println MkValidators.getErrMsgChain()
}
Assert.assertEquals(result, actResult)
where:
name | result
"a" | true
"b" | true
"c" | true
null | true
"d" | false
}