EscapeTool extends org.apache.velocity.tools.generic.EscapeTool { public String q(Object content) { if (content != null) { try { return new QCodec().encode(String.valueOf(content)).replace(' ', '_'); } catch (EncoderException ex) { } } return 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 qWithSimpleText() { assertEquals("=?UTF-8?Q?Hello_World?=", this.tool.q("Hello World")); }
@Test void qWithSpecialChars() { assertEquals("=?UTF-8?Q?a=3Db=3F=5F=0A?=", this.tool.q("a=b?_\n")); }
@Test void qWithNonAsciiChars() { assertEquals("=?UTF-8?Q?=C4=A3?=", this.tool.q("\u0123")); }
@Test void qWithNull() { assertNull(this.tool.q(null)); }