XQueryExpressionEvaluator { public String evaluateXQuery(final String xml, final String query) throws SaxonApiException { Processor processor = processorFactory.createProcessor(); XQueryCompiler xqueryCompiler = processor.newXQueryCompiler(); xqueryCompiler.setErrorListener(errorListener); XQueryExecutable xqueryExec = xqueryCompiler.compile(query); XQueryEvaluator xqueryEval = xqueryExec.load(); xqueryEval.setErrorListener(errorListener); SAXSource requestXml = saxSourceFactory.createSAXSource(inputSourceFactory.createInputSource(xml)); xqueryEval.setSource(requestXml); ByteArrayOutputStream baos = byteArrayOutputStreamFactory.createByteArrayOutputStream(); Serializer ser = serializerFactory.createSerializer(baos); xqueryEval.setDestination(ser); xqueryEval.run(); return baos.toString(); }  String evaluateXQuery(final String xml, final String query);  }
@Test public void testEvaluateXQueryShouldReturnOutputStream() throws SaxonApiException { String actual = underTest.evaluateXQuery(INPUT, QUERY); assertEquals(actual, outputStream.toString()); }
@Test public void testEvaluateXQueryShouldCallRun() throws SaxonApiException { underTest.evaluateXQuery(INPUT, QUERY); verify(xQueryEvaluator).run(); }