Validator { public void validate(T bean, boolean partial) { Map<String, String> errors = errors(bean, partial); if (errors != null) throw new ValidationException(errors); } private  Validator(Class<T> beanClass); @SuppressWarnings("unchecked") static Validator<T> of(Class<T> beanClass); static void cleanup(); void validate(T bean, boolean partial); Map<String, String> errors(T bean, boolean partial);  }
@Test void validate() { assertThatThrownBy(() -> validator.validate(null, false)) .isInstanceOf(ValidationException.class) .hasMessageContaining("bean must not be null"); assertThatThrownBy(() -> validator.validate(new TestBean(), false)) .isInstanceOf(ValidationException.class) .hasMessageContaining("value=field must not be null"); }