XsdStubDescriptorValidator implements StubDescriptorValidator { @Override public void validate(final Document document, final Schema schema) { try { Validator validator = schema.newValidator(); validator.validate(domSourceFactory.newDOMSource(document)); } catch (Exception e) { throw new DescriptorValidationFailedException("Validation of stub descriptor failed - XSD validation failed.", e); } }  @Override void validate(final Document document, final Schema schema);  }
@Test public final void testValidateShouldValidateXMLWithXsd() throws SAXException, IOException { given(schema.newValidator()).willReturn(validator); given(domSourceFactory.newDOMSource(document)).willReturn(domSource); underTest.validate(document, schema); verify(validator).validate(domSource); }
@Test(expectedExceptions = DescriptorValidationFailedException.class) public final void testValidateShouldThrowExceptionWhenValidationFailed() throws SAXException, IOException { given(schema.newValidator()).willReturn(validator); given(domSourceFactory.newDOMSource(document)).willReturn(domSource); willThrow(new IOException()).given(validator).validate(domSource); underTest.validate(document, schema); }