From 9f58c992bdd462fdd66965e39cf0d157a4e8fdd9 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 20 May 2024 22:10:58 +0200 Subject: [PATCH] [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. --- .../MultiUserChatOccupantIntegrationTest.java | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatOccupantIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatOccupantIntegrationTest.java index 323a245a6..437b552bd 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatOccupantIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatOccupantIntegrationTest.java @@ -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. @@ -30,6 +30,7 @@ import java.util.Set; 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; @@ -968,36 +969,32 @@ public class MultiUserChatOccupantIntegrationTest extends AbstractMultiUserChatI 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 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 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 partTwoPresencesReceived = participantTwoPresencesSyncPoint.waitForResults(