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

        // Execute system under test.
        final Packet result = StanzaIDUtil.ensureUniqueAndStableStanzaID( input, self );

        // Verify results.
        assertNotNull( result );
        final Element stanzaIDElement = result.getElement().element( QName.get( "stanza-id", "urn:xmpp:sid:0" ) );
        assertNotNull( stanzaIDElement );
        assertDoesNotThrow(() -> UUID.fromString( stanzaIDElement.attributeValue( "id" ) ));
        assertNotEquals( notExpected, stanzaIDElement.attributeValue( "id" ) );
        assertEquals( self.toString(), stanzaIDElement.attributeValue( "by" ) );
    }
Test if {@link StanzaIDUtil#ensureUniqueAndStableStanzaID(Packet, JID)} overwrites a stanza-id
element when another is present with the same 'by' value.
xmppserver/src/test/java/org/jivesoftware/openfire/stanzaid/StanzaIDUtilTest.java