protected Packet recognizeAndReturnXmppPacket(Element root)
            throws UnsupportedStanzaTypeException, IllegalArgumentException {
        checkNotNull(root);

        Packet packet = null;
        if (root.getName().equals(XmppConstants.IQ_QNAME)) {
            packet = new IQ(root);
        } else if (root.getName().equals(XmppConstants.MESSAGE_QNAME)) {
            packet = new Message(root);
        } else if (root.getName().equals(XmppConstants.PRESENCE_QNAME)) {
            packet = new Presence(root);
        } else {
            throw new UnsupportedStanzaTypeException("Unrecognized XMPP Packet");
        }
        logger.info("XMPP Packet received\n" + root.asXML());
        return packet;
    }
@Test
    public void testRecognizePacket() throws Exception {
        Packet iqPacket = xmppDecoder.recognizeAndReturnXmppPacket(iqElement);
        assertThat(iqPacket, is(instanceOf(IQ.class)));
        Packet messagePacket = xmppDecoder.recognizeAndReturnXmppPacket(messageElement);
        assertThat(messagePacket, is(instanceOf(Message.class)));
        Packet presencePacket = xmppDecoder.recognizeAndReturnXmppPacket(presenceElement);
        assertThat(presencePacket, is(instanceOf(Presence.class)));
        Element wrongElement = new DefaultElement("test");
        try {
            xmppDecoder.recognizeAndReturnXmppPacket(wrongElement);
        } catch (Exception e) {
            assertThat(e, is(instanceOf(UnsupportedStanzaTypeException.class)));
        }
    }