EscapeTool extends org.apache.velocity.tools.generic.EscapeTool { @Override public String xml(Object content) { return XMLUtils.escape(Objects.toString(content, null)); }  @Override String xml(Object content); String json(Object string); String quotedPrintable(Object content); String q(Object content); String b(Object content); String url(Map<String, ?> parametersMap); String css(String identifier); @Override String url(Object string);  }
@Test void escapeSimpleXML() { String escapedText = this.tool.xml("a < a' && a' < a\" => a < a\""); assertFalse(escapedText.contains("<"), "Failed to escape <"); assertFalse(escapedText.contains(">"), "Failed to escape >"); assertFalse(escapedText.contains("'"), "Failed to escape '"); assertFalse(escapedText.contains("\""), "Failed to escape \""); assertFalse(escapedText.contains("&&"), "Failed to escape &"); }
@Test void escapeXMLApos() { assertNotEquals("&apos;", this.tool.xml("'"), "' wrongly escaped to non-HTML &apos;"); }
@Test void escapeXMLWithNull() { assertNull(this.tool.xml(null), "null should be null"); }
@Test void escapeXMLNonAscii() { assertEquals("\u0123", this.tool.xml("\u0123"), "Non-ASCII characters shouldn't be escaped"); }