@Test
    public void encodeAndDecode() {
        boolean error = false;
        try {
            serializer.encode(null, null);
        } catch (Exception e) {
            error = true;
        }
        Assert.assertTrue(error);

        DemoRequest demoRequest = new DemoRequest();
        demoRequest.setName("a");
        AbstractByteBuf byteBuf = serializer.encode(demoRequest, null);
        DemoRequest req2 = (DemoRequest) serializer.decode(byteBuf, DemoRequest.class, null);
        Assert.assertEquals(demoRequest.getName(), req2.getName());

        AbstractByteBuf data = serializer.encode("xxx", null);
        String dst = (String) serializer.decode(data, String.class, null);
        Assert.assertEquals("xxx", dst);

        error = false;
        Date object = new Date();
        try {
            AbstractByteBuf encode = serializer.encode(object, null);
            Assert.assertEquals(object, serializer.decode(encode, Date.class, null));
        } catch (Exception e) {
            error = true;
        }
        Assert.assertTrue(!error);

        error = false;
        try {
            serializer.encode(1, null);
        } catch (Exception e) {
            error = true;
        }
        Assert.assertTrue(!error);

        error = false;
        try {
            serializer.decode(data, null, null);
        } catch (Exception e) {
            error = true;
        }
        Assert.assertTrue(error);

        error = false;
        try {
            serializer.decode(data, "", null);
        } catch (Exception e) {
            error = true;
        }
        Assert.assertTrue(error);
    }
@author <a href="mailto:zhanggeng.zg@antfin.com">GengZhang</a>
codec/codec-msgpack/src/test/java/com/alipay/sofa/rpc/codec/msgpack/MsgPackSerializerTest.java