1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-25 21:42:07 +01:00

[sinttest] Improve mucChangeNicknameInformationTest()

Only declare the body of the participant listeners once. And increase
the try block, to account, for example, for
participantOneSeesTwoEnter.waitForResult() throwing.
This commit is contained in:
Florian Schmaus 2024-05-20 22:10:58 +02:00
parent 2a243fe3b6
commit 9f58c992bd

View file

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import java.util.Set;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.jivesoftware.smack.PresenceListener;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
@ -968,6 +969,7 @@ public class MultiUserChatOccupantIntegrationTest extends AbstractMultiUserChatI
createMuc(mucAsSeenByOne, nicknameOne); createMuc(mucAsSeenByOne, nicknameOne);
try {
SimpleResultSyncPoint participantOneSeesTwoEnter = new SimpleResultSyncPoint(); SimpleResultSyncPoint participantOneSeesTwoEnter = new SimpleResultSyncPoint();
mucAsSeenByOne.addParticipantListener(presence -> { mucAsSeenByOne.addParticipantListener(presence -> {
if (nicknameTwoOriginal.equals(presence.getFrom().getResourceOrEmpty())) { if (nicknameTwoOriginal.equals(presence.getFrom().getResourceOrEmpty())) {
@ -984,20 +986,15 @@ public class MultiUserChatOccupantIntegrationTest extends AbstractMultiUserChatI
// reversed. Here we will expect an unavailable and an available presence stanza sent to both participant one // 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. // and participant two. So that adds up to a total of four.
MultiResultSyncPoint<Presence, ?> participantTwoPresencesSyncPoint = new MultiResultSyncPoint<>(4); MultiResultSyncPoint<Presence, ?> participantTwoPresencesSyncPoint = new MultiResultSyncPoint<>(4);
mucAsSeenByOne.addParticipantListener(presence -> { PresenceListener mucPresenceListener = presence -> {
if (nicknameTwoOriginal.equals(presence.getFrom().getResourceOrEmpty()) || nicknameTwoNew.equals( Resourcepart fromResource = presence.getFrom().getResourceOrEmpty();
presence.getFrom().getResourceOrEmpty())) { if (nicknameTwoOriginal.equals(fromResource) || nicknameTwoNew.equals(fromResource)) {
participantTwoPresencesSyncPoint.signal(presence); participantTwoPresencesSyncPoint.signal(presence);
} }
}); };
mucAsSeenByTwo.addParticipantListener(presence -> { mucAsSeenByOne.addParticipantListener(mucPresenceListener);
if (nicknameTwoOriginal.equals(presence.getFrom().getResourceOrEmpty()) || nicknameTwoNew.equals( mucAsSeenByTwo.addParticipantListener(mucPresenceListener);
presence.getFrom().getResourceOrEmpty())) {
participantTwoPresencesSyncPoint.signal(presence);
}
});
try {
// Participant two changes nickname // Participant two changes nickname
mucAsSeenByTwo.changeNickname(nicknameTwoNew); mucAsSeenByTwo.changeNickname(nicknameTwoNew);
final List<Presence> partTwoPresencesReceived = participantTwoPresencesSyncPoint.waitForResults( final List<Presence> partTwoPresencesReceived = participantTwoPresencesSyncPoint.waitForResults(