### Question:
TextUtil { public static String quote(CharSequence cs) { StringBuilder buf = new StringBuilder(); quoteTo(cs, buf); return buf.toString(); } private  TextUtil(); static String quote(CharSequence cs); static void quoteTo(CharSequence cs, StringBuilder target); static int countLeadingWhitespaces(CharSequence cs, int offset, int length); static int countTrailingWhitespaces(CharSequence cs, int offset, int length); static byte parseByte(CharSequence cs, int offset, int length); static short parseShort(CharSequence cs, int offset, int length); static int parseInt(CharSequence cs, int offset, int length); static long parseLong(CharSequence cs, int offset, int length); static BigDecimal parseDecimal(CharSequence cs, int offset, int length); static float parseFloat(CharSequence cs, int offset, int length); static double parseDouble(CharSequence cs, int offset, int length);  }### Answer:
@Test public void quote() { assertThat(TextUtil.quote("Hello, world!"), is("\"Hello, world!\"")); }
@Test public void quote_escape() { assertThat(TextUtil.quote("say \"hello\"\n"), is("\"say \\\"hello\\\"\\n\"")); }
@Test public void quote_unicode() { assertThat(TextUtil.quote("\000\001"), is("\"\\u0000\\u0001\"")); }
@Test public void quote_surrogate_pair() { assertThat(TextUtil.quote(CP_BEER), is('"' + CP_BEER + '"')); }
@Test public void quote_surrogate_broken() { char hi = CP_BEER.charAt(0); char lo = CP_BEER.charAt(1); assertThat(TextUtil.quote(String.valueOf(hi)), is(String.format("\"\\u%04x\"", (int) hi))); assertThat(TextUtil.quote(String.valueOf(lo)), is(String.format("\"\\u%04x\"", (int) lo))); assertThat( TextUtil.quote(new StringBuilder().append(hi).append('a')), is(String.format("\"\\u%04xa\"", (int) hi))); }