public void testSurrogatePairs() throws Exception
    {
        // This test is mainly for Java 8+, where 3-byte surrogates
        // and 6-byte surrogate pairs are not allowed.
        LinkedBuffer lb = new LinkedBuffer(256);
        WriteSession session = new WriteSession(lb);
        StreamedStringSerializer.writeUTF8(surrogatePairs, session, lb);

        byte[] buffered = session.toByteArray();

        // Does our own serialization match native?
        assertTrue(Arrays.equals(buffered, nativeSurrogatePairsSerialized));

        // Does our own serialization / deserialization work?
        assertEquals(surrogatePairs, STRING.deserCustomOnly(buffered));

        // Can we decode legacy encodings?
        assertEquals(surrogatePairs, STRING.deserCustomOnly(legacySurrogatePairSerialized));

        // Does the built in serialization work?
        assertEquals(surrogatePairs, new String(nativeSurrogatePairsSerialized, "UTF-8"));

        // Should be encoded using 4-byte code points, instead of 6-byte surrogate pairs.
        assertFalse(Arrays.equals(buffered, legacySurrogatePairSerialized));

        try
        {
            // Can we deserialize from a protobuf source (specifically java generated)
            // using our first method?
            assertEquals(surrogatePairs, STRING.deserCustomOnly(nativeSurrogatePairsSerialized));
        }
        catch (RuntimeException ex)
        {
            // No? Fallback should catch this.
            assertEquals(surrogatePairs, STRING.deser(nativeSurrogatePairsSerialized));

            // But it means there's a bug in the deserializer
            fail("Deserializer should not have used built in decoder.");
        }
    }
Tests for streaming UTF-8 Encoding

@author David Yu
@created Sep 18, 2010
protostuff-api/src/test/java/io/protostuff/StreamedStringSerializerTest.java