### Question:
LongString implements EncodableData { public static LongString parse(ByteBuf buf) throws Exception { int size = (int) buf.readUnsignedInt(); if (size < 0) { throw new Exception("Invalid string length"); } byte[] data = new byte[size]; buf.readBytes(data); return new LongString(size, data); } @SuppressFBWarnings("EI_EXPOSE_REP2")  LongString(long length, byte[] content); static LongString parseString(String data); @Override long getSize(); @Override void write(ByteBuf buf); static LongString parse(ByteBuf buf); static LongString parse(byte[] data); @Override boolean equals(Object obj); boolean isEmpty(); @Override int hashCode(); @Override String toString(); @SuppressFBWarnings("EI_EXPOSE_REP") byte[] getBytes();  }### Answer:
@Test public void testParse() throws Exception { ByteBuf buf = Unpooled.buffer(DEFAULT_DATA_STRING.length() + 4); DEFAULT_TEST_OBJECT.write(buf); LongString parsedObject = LongString.parse(buf); Assert.assertEquals(parsedObject, DEFAULT_TEST_OBJECT, "Encoding and decoding should match to same object"); }
@Test(expectedExceptions = Exception.class) public void testInvalidBuffer() throws Exception { ByteBuf buf = Unpooled.buffer(DEFAULT_DATA_STRING.length() + 4); buf.writeLong(-2); LongString.parse(buf); }