### Question:
StanzaIDUtil { 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; }  static Packet ensureUniqueAndStableStanzaID( final Packet packet, final JID self ); static String generateUniqueAndStableStanzaID( final Packet packet ); @Deprecated static UUID parseUniqueAndStableStanzaID( final Packet packet, final String by ); static String findFirstUniqueAndStableStanzaID( final Packet packet, final String by );  }### Answer:
@Test public void testParseUUIDValue() throws Exception { 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() ); final String result = StanzaIDUtil.findFirstUniqueAndStableStanzaID( input, self.toString() ); assertEquals( expected, result ); }
@Test public void testParseNonUUIDValue() throws Exception { final Packet input = new Message(); final JID self = new JID( "foobar" ); final String expected = "not-a-uuid"; final Element toOverwrite = input.getElement().addElement( "stanza-id", "urn:xmpp:sid:0" ); toOverwrite.addAttribute( "id", expected ); toOverwrite.addAttribute( "by", self.toString() ); final String result = StanzaIDUtil.findFirstUniqueAndStableStanzaID( input, self.toString() ); assertEquals( expected, result ); }