ModelValidator { public boolean validateModel(Object model) { List<ValidationError> errors = getModelValidationErrors(model, Default.class); if (!errors.isEmpty()) { throw new DataValidationException(errors); } return true; } ModelValidator(Validator validator, ObjectMapper mapper); List<ValidationError> getModelValidationErrors(Object object, Class validationGroup); List<ValidationError> getCreateValidationErrors(Object create, FieldData fieldData); List<ValidationError> getUpdateValidationErrors(Update<?> update, FieldData fieldData); boolean validateModel(Object model); boolean validateCreate(Object create, FieldData fieldData); boolean validateUpdate(Update<?> update, FieldData fieldData);  }
@Test public void testValidateModel() throws Exception { try { validator.validateModel(TestValidateModel.builder().email("bad").build()); fail("Expected DataValidationException"); } catch (DataValidationException e) { assertEquals(1, e.getErrors().size()); } assertTrue(validator.validateModel(TestValidateModel.builder().email("ok@example.com").build())); }