@Override
    protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
        byte[] bytes = null;

        if (msg instanceof XmppStreamEvent) {
            XmppStreamEvent streamEvent = (XmppStreamEvent) msg;
            logger.info("SENDING: {}", streamEvent.toXml());
            bytes = streamEvent.toXml().getBytes(CharsetUtil.UTF_8);
        }

        if (msg instanceof Packet) {
            Packet pkt = (Packet) msg;
            logger.info("SENDING /n, {}", pkt.toString());
            bytes = pkt.toXML().getBytes(CharsetUtil.UTF_8);
        }

        out.writeBytes(checkNotNull(bytes));
    }
@Test
    public void testEncode() throws Exception {
        Packet iq = new IQ();
        ByteBuf buffer = Unpooled.buffer();
        xmppEncoder.encode(channelHandlerContext, iq, buffer);
        assertThat(buffer.hasArray(), Matchers.is(true));
    }