### Question:
XMLScriptService implements ScriptService { public String transform(Source xml, Source xslt) { return XMLUtils.transform(xml, xslt); } XMLScriptService(); static String escape(Object content); static String escapeForAttributeValue(Object content); static String escapeForElementContent(Object content); static String unescape(Object content); Document createDOMDocument(); Document parse(LSInput source); Document parse(byte[] content); Document parse(String content); Document parse(InputStream stream); String serialize(Node node); String serialize(Node node, boolean withXmlDeclaration); String transform(Source xml, Source xslt); String transform(Document xml, Document xslt); String transform(byte[] xml, byte[] xslt); String transform(String xml, String xslt);  }### Answer:
@Test void testTransformByteArray() throws UnsupportedEncodingException { byte[] d = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a b='c'>d</a>".getBytes("UTF-8"); byte[] s = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<xsl:stylesheet xmlns:xsl='http: "<xsl:output method='xml' omit-xml-declaration='yes'/>" + "<xsl:template match='node()'><xsl:copy/></xsl:template></xsl:stylesheet>").getBytes("UTF-8"); String result = this.xml.transform(d, s); assertEquals("<a/>", result); }
@Test void testTransformString() { String d = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a b='c'>d</a>"; String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<xsl:stylesheet xmlns:xsl='http: "<xsl:output method='xml' omit-xml-declaration='yes'/>" + "<xsl:template match='node()'><xsl:copy/></xsl:template></xsl:stylesheet>"; String result = this.xml.transform(d, s); assertEquals("<a/>", result); }
@Test void testTransformWithNullInputs() { StreamSource d = new StreamSource(new StringReader("<a b='c'>d</a>")); StreamSource s = new StreamSource(new StringReader( "<xsl:stylesheet xmlns:xsl='http: + "<xsl:template match='node()'><xsl:copy/></xsl:template></xsl:stylesheet>")); String result = this.xml.transform(null, s); assertNull(null, result); result = this.xml.transform(d, null); assertNull(null, result); result = this.xml.transform((StreamSource) null, (StreamSource) null); assertNull(null, result); }
@Test void testTransformWithNullStrings() { String d = "<a b='c'>d</a>"; String s = "<xsl:stylesheet xmlns:xsl='http: "<xsl:output method='xml'/><xsl:template match='node()'><xsl:copy/></xsl:template></xsl:stylesheet>"; String result = this.xml.transform(null, s); assertNull(null, result); result = this.xml.transform(d, null); assertNull(null, result); result = this.xml.transform((String) null, (String) null); assertNull(null, result); }
@Test void testTransformWithNullByteArrays() throws UnsupportedEncodingException { byte[] d = "<a b='c'>d</a>".getBytes("UTF-8"); byte[] s = ("<xsl:stylesheet xmlns:xsl='http: "<xsl:output method='xml'/><xsl:template match='node()'><xsl:copy/></xsl:template></xsl:stylesheet>") .getBytes(); String result = this.xml.transform(null, s); assertNull(null, result); result = this.xml.transform(d, null); assertNull(null, result); result = this.xml.transform((byte[]) null, (byte[]) null); assertNull(null, result); }