public static String findFirstUniqueAndStableStanzaID( final Packet packet, final String by )
    {
        if ( packet == null )
        {
            throw new IllegalArgumentException( "Argument 'packet' cannot be null." );
        }
        if ( by == null || by.isEmpty() )
        {
            throw new IllegalArgumentException( "Argument 'by' cannot be null or an empty string." );
        }

        final List<Element> sids = packet.getElement().elements( QName.get( "stanza-id", "urn:xmpp:sid:0" ) );
        if ( sids == null )
        {
            return null;
        }

        for ( final Element sid : sids )
        {
            if ( by.equals( sid.attributeValue( "by" ) ) )
            {
                final String result = sid.attributeValue( "id" );
                if ( result != null && !result.isEmpty() )
                {
                    return result;
                }
            }
        }

        return null;
    }
@Test
    public void testParseUUIDValue() throws Exception
    {
        // Setup fixture.
        final Packet input = new Message();
        final JID self = new JID( "foobar" );
        final String expected = "de305d54-75b4-431b-adb2-eb6b9e546013";
        final Element toOverwrite = input.getElement().addElement( "stanza-id", "urn:xmpp:sid:0" );
        toOverwrite.addAttribute( "id", expected );
        toOverwrite.addAttribute( "by", self.toString() );

        // Execute system under test.
        final String result = StanzaIDUtil.findFirstUniqueAndStableStanzaID( input, self.toString() );

        // Verify results.
        assertEquals( expected, result );
    }