-
Notifications
You must be signed in to change notification settings - Fork 136
Validator
johnmcclean-aol edited this page Nov 21, 2016
·
2 revisions
Validator allows a set of validation parameters to be lazily configured and then executed against a target to be validated. Errors can either be accumulated or validation can fail on error.
While Xor (or even Try) can be used to store validation results, Validator is an active validator that executes the supplied validation rules.
ValidationResults results = CumulativeValidator.of((User user)->user.age>18, "too young", "age ok")
.isValid(user->user.email!=null, "user email null","email ok")
.accumulate(new User(10,"[email protected]"));
assertThat(results.getResults().size(),equalTo(2));
ValidationResults<String,String> results = CumulativeValidator.of((User user)->user.age>18, "too young", "age ok")
.add(Validator.of((User user)->user.email!=null, "user email null","email ok"))
.accumulateUntilFail(new User(10,"[email protected]"));
assertThat(results.getResults().size(),equalTo(1));
oops - my bad