### Question:
Entities { static String escape(String string, Document.OutputSettings out) { StringBuilder accum = new StringBuilder(string.length() * 2); try { escape(accum, string, out, false, false, false); } catch (IOException e) { throw new SerializationException(e); } return accum.toString(); } private  Entities(); static boolean isNamedEntity(final String name); static boolean isBaseNamedEntity(final String name); static Character getCharacterByName(String name); static String getByName(String name); static int codepointsForName(final String name, final int[] codepoints);  }### Answer:
@Test public void escape() { String text = "Hello &<> Å å π 新 there ¾ © »"; String escapedAscii = Entities.escape(text, new OutputSettings().charset("ascii").escapeMode(base)); String escapedAsciiFull = Entities.escape(text, new OutputSettings().charset("ascii").escapeMode(extended)); String escapedAsciiXhtml = Entities.escape(text, new OutputSettings().charset("ascii").escapeMode(xhtml)); String escapedUtfFull = Entities.escape(text, new OutputSettings().charset("UTF-8").escapeMode(extended)); String escapedUtfMin = Entities.escape(text, new OutputSettings().charset("UTF-8").escapeMode(xhtml)); assertEquals("Hello &amp;&lt;&gt; &Aring; &aring; &#x3c0; &#x65b0; there &frac34; &copy; &raquo;", escapedAscii); assertEquals("Hello &amp;&lt;&gt; &angst; &aring; &pi; &#x65b0; there &frac34; &copy; &raquo;", escapedAsciiFull); assertEquals("Hello &amp;&lt;&gt; &#xc5; &#xe5; &#x3c0; &#x65b0; there &#xbe; &#xa9; &#xbb;", escapedAsciiXhtml); assertEquals("Hello &amp;&lt;&gt; Å å π 新 there ¾ © »", escapedUtfFull); assertEquals("Hello &amp;&lt;&gt; Å å π 新 there ¾ © »", escapedUtfMin); assertEquals(text, Entities.unescape(escapedAscii)); assertEquals(text, Entities.unescape(escapedAsciiFull)); assertEquals(text, Entities.unescape(escapedAsciiXhtml)); assertEquals(text, Entities.unescape(escapedUtfFull)); assertEquals(text, Entities.unescape(escapedUtfMin)); }
@Test public void escapedSupplemtary() { String text = "\uD835\uDD59"; String escapedAscii = Entities.escape(text, new OutputSettings().charset("ascii").escapeMode(base)); assertEquals("&#x1d559;", escapedAscii); String escapedAsciiFull = Entities.escape(text, new OutputSettings().charset("ascii").escapeMode(extended)); assertEquals("&hopf;", escapedAsciiFull); String escapedUtf= Entities.escape(text, new OutputSettings().charset("UTF-8").escapeMode(extended)); assertEquals(text, escapedUtf); }
@Test public void escapeSupplementaryCharacter() { String text = new String(Character.toChars(135361)); String escapedAscii = Entities.escape(text, new OutputSettings().charset("ascii").escapeMode(base)); assertEquals("&#x210c1;", escapedAscii); String escapedUtf = Entities.escape(text, new OutputSettings().charset("UTF-8").escapeMode(base)); assertEquals(text, escapedUtf); }
@Test public void caseSensitive() { String unescaped = "Ü ü & &"; assertEquals("&Uuml; &uuml; &amp; &amp;", Entities.escape(unescaped, new OutputSettings().charset("ascii").escapeMode(extended))); String escaped = "&Uuml; &uuml; &amp; &AMP"; assertEquals("Ü ü & &", Entities.unescape(escaped)); }