Skip to content

Commit

Permalink
[sinttest] Improve mucChangeNicknameInformationTest()
Browse files Browse the repository at this point in the history
Only declare the body of the participant listeners once. And increase
the try block, to account, for example, for
participantOneSeesTwoEnter.waitForResult() throwing.
  • Loading branch information
Flowdalic committed May 20, 2024
1 parent 2a243fe commit 9f58c99
Showing 1 changed file with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2015-2020 Florian Schmaus, 2021 Dan Caseley
* Copyright 2015-2024 Florian Schmaus, 2021 Dan Caseley
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,6 +30,7 @@
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;

import org.jivesoftware.smack.PresenceListener;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message;
Expand Down Expand Up @@ -968,36 +969,32 @@ public void mucChangeNicknameInformationTest() throws Exception {

createMuc(mucAsSeenByOne, nicknameOne);

SimpleResultSyncPoint participantOneSeesTwoEnter = new SimpleResultSyncPoint();
mucAsSeenByOne.addParticipantListener(presence -> {
if (nicknameTwoOriginal.equals(presence.getFrom().getResourceOrEmpty())) {
participantOneSeesTwoEnter.signal();
}
});

// Have participant two enter the room
mucAsSeenByTwo.join(nicknameTwoOriginal);
participantOneSeesTwoEnter.waitForResult(timeout);

// Although logic dictates that the 'unavailable' presence stanzas for the old nick should precede the presence
// stanza for the new nick - the specification does not dictate that. So we should allow for the order to be
// reversed. Here we will expect an unavailable and an available presence stanza sent to both participant one
// and participant two. So that adds up to a total of four.
MultiResultSyncPoint<Presence, ?> participantTwoPresencesSyncPoint = new MultiResultSyncPoint<>(4);
mucAsSeenByOne.addParticipantListener(presence -> {
if (nicknameTwoOriginal.equals(presence.getFrom().getResourceOrEmpty()) || nicknameTwoNew.equals(
presence.getFrom().getResourceOrEmpty())) {
participantTwoPresencesSyncPoint.signal(presence);
}
});
mucAsSeenByTwo.addParticipantListener(presence -> {
if (nicknameTwoOriginal.equals(presence.getFrom().getResourceOrEmpty()) || nicknameTwoNew.equals(
presence.getFrom().getResourceOrEmpty())) {
participantTwoPresencesSyncPoint.signal(presence);
}
});

try {
SimpleResultSyncPoint participantOneSeesTwoEnter = new SimpleResultSyncPoint();
mucAsSeenByOne.addParticipantListener(presence -> {
if (nicknameTwoOriginal.equals(presence.getFrom().getResourceOrEmpty())) {
participantOneSeesTwoEnter.signal();
}
});

// Have participant two enter the room
mucAsSeenByTwo.join(nicknameTwoOriginal);
participantOneSeesTwoEnter.waitForResult(timeout);

// Although logic dictates that the 'unavailable' presence stanzas for the old nick should precede the presence
// stanza for the new nick - the specification does not dictate that. So we should allow for the order to be
// reversed. Here we will expect an unavailable and an available presence stanza sent to both participant one
// and participant two. So that adds up to a total of four.
MultiResultSyncPoint<Presence, ?> participantTwoPresencesSyncPoint = new MultiResultSyncPoint<>(4);
PresenceListener mucPresenceListener = presence -> {
Resourcepart fromResource = presence.getFrom().getResourceOrEmpty();
if (nicknameTwoOriginal.equals(fromResource) || nicknameTwoNew.equals(fromResource)) {
participantTwoPresencesSyncPoint.signal(presence);
}
};
mucAsSeenByOne.addParticipantListener(mucPresenceListener);
mucAsSeenByTwo.addParticipantListener(mucPresenceListener);

// Participant two changes nickname
mucAsSeenByTwo.changeNickname(nicknameTwoNew);
final List<Presence> partTwoPresencesReceived = participantTwoPresencesSyncPoint.waitForResults(
Expand Down

0 comments on commit 9f58c99

Please sign in to comment.