### Question:
Stax2ValidationUtils { public boolean setupValidation(XMLStreamReader reader, Endpoint endpoint, ServiceInfo serviceInfo) throws XMLStreamException { XMLStreamReader effectiveReader = reader; if (effectiveReader instanceof DepthXMLStreamReader) { effectiveReader = ((DepthXMLStreamReader) reader).getReader(); } final XMLStreamReader2 reader2 = (XMLStreamReader2) effectiveReader; XMLValidationSchema vs = getValidator(endpoint, serviceInfo); if (vs == null) { return false; } reader2.setValidationProblemHandler(new ValidationProblemHandler() { public void reportProblem(XMLValidationProblem problem) throws XMLValidationException { throw new Fault(new Message("READ_VALIDATION_ERROR", LOG, problem.getMessage()), Fault.FAULT_CODE_CLIENT); } }); reader2.validateAgainst(vs); return true; } Stax2ValidationUtils(); boolean setupValidation(XMLStreamReader reader, Endpoint endpoint, ServiceInfo serviceInfo); boolean setupValidation(XMLStreamWriter writer, Endpoint endpoint, ServiceInfo serviceInfo);  }### Answer:
@Test public void testValidMessage() throws Exception { Throwable exception = null; xmlReader = createReader(validMessage); utils.setupValidation(xmlReader, endpoint, serviceInfo); try { while (xmlReader.hasNext()) { xmlReader.next(); } } catch (Throwable e) { exception = e; } assertThat(exception, is(nullValue())); }
@Test public void testInvalidMessage() throws Exception { Throwable exception = null; xmlReader = createReader(invalidMessage); utils.setupValidation(xmlReader, endpoint, serviceInfo); try { while (xmlReader.hasNext()) { xmlReader.next(); } } catch (Throwable e) { exception = e; } assertThat(exception, is(notNullValue())); assertThat(exception.getMessage(), containsString(errorMessage)); }