DefaultValidator implements Validator { @Override public void performValidation(Schema schema, Object input) { ValidationFailureReporter failureReporter = createFailureReporter(schema); ReadWriteValidator readWriteValidator = ReadWriteValidator.createForContext(readWriteContext, failureReporter); ValidatingVisitor visitor = new ValidatingVisitor(input, failureReporter, readWriteValidator, validationListener); try { visitor.visit(schema); visitor.failIfErrorFound(); } catch (InternalValidationException e) { throw e.copy(); } } DefaultValidator(boolean failEarly, ReadWriteContext readWriteContext, ValidationListener validationListener); @Override void performValidation(Schema schema, Object input);  }
@Test public void testCollectAllMode() { Validator actual = Validator.builder().build(); try { actual.performValidation(ObjectSchemaTest.MULTIPLE_VIOLATIONS_SCHEMA, ResourceLoader.DEFAULT.readObj("objecttestcases.json").get("multipleViolations")); fail("did not throw exception"); } catch (ValidationException e) { assertEquals("#: 3 schema violations found", e.getMessage()); assertEquals(3, e.getCausingExceptions().size()); } }
@Test public void testFailEarlyMode() { Validator actual = Validator.builder().failEarly().build(); try { actual.performValidation(ObjectSchemaTest.MULTIPLE_VIOLATIONS_SCHEMA, ResourceLoader.DEFAULT.readObj("objecttestcases.json").get("multipleViolations")); fail("did not throw exception"); } catch (ValidationException e) { assertEquals("#: required key [boolProp] not found", e.getMessage()); assertTrue("no causing exceptions", e.getCausingExceptions().isEmpty()); } }