ConfigValidator { public Result validate(final AbstractConfig config) { final Set<ConstraintViolation<AbstractConfig>> constraintViolations = validator.validate(config); return Result.of(constraintViolations); } @Inject  ConfigValidator(final Validator validator); Result validateValue(final Class<? extends AbstractConfig> configClass,
                                final String propertyName,
                                final Object value); Result validate(final AbstractConfig config); Result validateRecursively(final AbstractConfig config); static void logConstraintViolation(
        final ConstraintViolation<? extends AbstractConfig> constraintViolation,
        final ValidationSeverity severity);  }
@Test void testMyPojo_errors_nonRecursive() { final Injector injector = Guice.createInjector(new ValidationModule()); injector.injectMembers(this); var myPojo = new MyPojoErrors(); myPojo.setBooleanValue(false); myPojo.setRegexValue("((("); myPojo.setCronValue("xxxxxxxxxxxxx"); myPojo.setIntValue(0); myPojo.getChild().setBooleanValue(false); myPojo.getChild().setRegexValue("((("); myPojo.getChild().setCronValue("xxxxxxxxxxxxx"); myPojo.getChild().setIntValue(0); ConfigValidator.Result result = configValidator.validate(myPojo); LOGGER.info(result.toString()); result.handleViolations((constraintViolation, validationSeverity) -> { LOGGER.info("{}, {}", validationSeverity, constraintViolation); }); Assertions.assertThat(result.getErrorCount()).isEqualTo(4); Assertions.assertThat(result.getWarningCount()).isEqualTo(0); }
@Test void testMyPojo_warnings() { final Injector injector = Guice.createInjector(new ValidationModule()); injector.injectMembers(this); var myPojo = new MyPojoWarnings(); myPojo.setBooleanValue(false); myPojo.setRegexValue("((("); myPojo.setCronValue("xxxxxxxxxxxxx"); myPojo.setIntValue(0); ConfigValidator.Result result = configValidator.validate(myPojo); LOGGER.info(result.toString()); result.handleViolations((constraintViolation, validationSeverity) -> { LOGGER.info("{}, {}", validationSeverity, constraintViolation); }); Assertions.assertThat(result.getErrorCount()).isEqualTo(0); Assertions.assertThat(result.getWarningCount()).isEqualTo(4); }