### Question:
XsdValidator implements SchemaValidator { @Override public SchemaValidationResults validate(String rule) { Set<SchemaValidationError> validationErrors = new LinkedHashSet<>(); try { Source source = new StreamSource(new StringReader(rule)); Validator validator = schema.newValidator(); validator.setErrorHandler(new ValidationHandler(validationErrors)); validator.validate(source); } catch (SAXParseException e) { validationErrors.add(saxParseExceptionToSchemaValidationError(e)); } catch (SAXException e) { validationErrors.add(SchemaValidationError.of(e.getMessage())); } catch (IOException e) { throw new UncheckedIOException(e); } return validationErrors.isEmpty() ? SchemaValidationResults.success() : SchemaValidationResults.ofErrors(validationErrors); }  @Override SchemaValidationResults validate(String rule);  }### Answer:
@Test void shouldSucceedForValidRule() { String xml = ResourceUtils.getResourceAsString("/validator/validRule.xml"); SchemaValidationResults result = validator.validate(xml); assertThat(result.hasErrors()).isFalse(); }
@Test void shouldReturnErrorResultsForParsingError() { String invalidXml = "!@#$"; SchemaValidationResults result = validator.validate(invalidXml); assertThat(result.hasErrors()).isTrue(); assertThat(result.getResults()).containsExactlyInAnyOrder( SchemaValidationError.of(1, 1, "Content is not allowed in prolog.") ); }