XslResponseGenerator { public byte[] generateResponse(final byte[] requestXml, final byte[] xsl, final byte[] template) { byte[] result = null; InputStream requestInputStream = inputStreamFactory.createByteArrayInputStream(requestXml); InputStream xslInputStream = inputStreamFactory.createByteArrayInputStream(xsl); InputStream templateInputStream = inputStreamFactory.createByteArrayInputStream(template); try { result = transformer.transform(xslInputStream, requestInputStream, templateInputStream); } catch (Exception e) { throw new ResponseFormattingFailedException("Template formatting failed with xslt:" + xsl, e); } return result; }  byte[] generateResponse(final byte[] requestXml, final byte[] xsl, final byte[] template);  }
@Test public void testGenerateResponseShouldReturnResponse() throws SaxonApiException, SAXException { byte[] response = new byte[1]; given(transformer.transform(xslInputStream, requestInputStream, templateInputStream)).willReturn(response); byte[] actual = underTest.generateResponse(requestXml, xsl, templateXml); assertEquals(actual, response); }
@Test(expectedExceptions = ResponseFormattingFailedException.class) public void testGenerateResponseWhenSaxonApiExceptionDuringTransformShouldThrowException() throws SaxonApiException, SAXException { given(transformer.transform(xslInputStream, requestInputStream, templateInputStream)).willThrow(new SaxonApiException("exception")); underTest.generateResponse(requestXml, xsl, templateXml); }
@Test(expectedExceptions = ResponseFormattingFailedException.class) public void testGenerateResponseWhenSAXExceptionDuringTransformShouldThrowException() throws SaxonApiException, SAXException { given(transformer.transform(xslInputStream, requestInputStream, templateInputStream)).willThrow(new SAXException()); underTest.generateResponse(requestXml, xsl, templateXml); }