public void testQuoteAsUTF8() throws Exception
{
// In this case, let's actually use existing JsonGenerator to produce expected values
JsonFactory f = new JsonFactory();
JsonStringEncoder encoder = new JsonStringEncoder();
int[] lengths = new int[] {
5, 19, 200, 7000, 21000, 37000
};
for (int length : lengths) {
String str = generateRandom(length);
StringWriter sw = new StringWriter(length*2);
JsonGenerator jgen = f.createGenerator(sw);
jgen.writeString(str);
jgen.close();
String encoded = sw.toString();
// ok, except need to remove surrounding quotes
encoded = encoded.substring(1, encoded.length() - 1);
byte[] expected = encoded.getBytes("UTF-8");
byte[] actual = encoder.quoteAsUTF8(str);
assertArrayEquals(expected, actual);
}
}