1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 12:02:05 +01:00

[sinttest] Do not leak stanza listener in MultiUserChatOccupantIntegrationTest

This commit is contained in:
Florian Schmaus 2024-06-27 21:29:33 +02:00
parent c322ce8046
commit d27fef0bae

View file

@ -32,6 +32,7 @@ import java.util.stream.Collectors;
import org.jivesoftware.smack.PresenceListener; import org.jivesoftware.smack.PresenceListener;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.StanzaListener;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.FromMatchesFilter; import org.jivesoftware.smack.filter.FromMatchesFilter;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
@ -107,12 +108,13 @@ public class MultiUserChatOccupantIntegrationTest extends AbstractMultiUserChatI
final ResultSyncPoint<String, Exception> subjectResultSyncPoint = new ResultSyncPoint<>(); final ResultSyncPoint<String, Exception> subjectResultSyncPoint = new ResultSyncPoint<>();
final List<Stanza> results = new ArrayList<>(); final List<Stanza> results = new ArrayList<>();
conTwo.addStanzaListener(stanza -> { final StanzaListener stanzaListener = stanza -> {
results.add(stanza); results.add(stanza);
if (stanza instanceof Message && ((Message) stanza).getSubject() != null) { if (stanza instanceof Message && ((Message) stanza).getSubject() != null) {
subjectResultSyncPoint.signal(((Message) stanza).getSubject()); subjectResultSyncPoint.signal(((Message) stanza).getSubject());
} }
}, FromMatchesFilter.create(mucAddress)); };
conTwo.addStanzaListener(stanzaListener, FromMatchesFilter.create(mucAddress));
try { try {
mucAsSeenByTwo.join(nicknameTwo); mucAsSeenByTwo.join(nicknameTwo);
@ -130,6 +132,7 @@ public class MultiUserChatOccupantIntegrationTest extends AbstractMultiUserChatI
assertEquals(mucSubject, ((Message) results.get(3)).getSubject(), "The fourth stanza that was received by '" + conTwo.getUser() + "' after it joined room '" + mucAddress + "' was expected to be a different stanza."); assertEquals(mucSubject, ((Message) results.get(3)).getSubject(), "The fourth stanza that was received by '" + conTwo.getUser() + "' after it joined room '" + mucAddress + "' was expected to be a different stanza.");
} finally { } finally {
tryDestroy(mucAsSeenByOne); tryDestroy(mucAsSeenByOne);
conTwo.removeStanzaListener(stanzaListener);
} }
} }