BeanValidator { public void validate(Object o) { Set<ConstraintViolation<Object>> violations = validator.validate(o); if (!violations.isEmpty()) { throw new ConstraintValidationException(violations); } } BeanValidator(Validator validator); void validate(Object o);  }
@Test public void should_do_nothing_if_bean_is_valid() throws Exception { BeanValidator validator = new BeanValidator(Validation.buildDefaultValidatorFactory().getValidator()); validator.validate(aValidBean()); }
@Test(expected = ConstraintValidationException.class) public void should_throw_constraintViolationException_when_bean_is_not_valid() throws Exception { BeanValidator validator = new BeanValidator(Validation.buildDefaultValidatorFactory().getValidator()); validator.validate(anInvalidBean()); }