From 253d46964e9d230ce85d6585bb68cd042db3216a Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Mon, 22 Apr 2024 19:18:09 +0200 Subject: [PATCH] [sinttest] Applied review feedback --- .../smack/roster/RosterIntegrationTest.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smack/roster/RosterIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smack/roster/RosterIntegrationTest.java index f03ac2fcdb..091293c4d1 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smack/roster/RosterIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smack/roster/RosterIntegrationTest.java @@ -1,6 +1,6 @@ /** * - * Copyright 2015-2020 Florian Schmaus + * Copyright 2015-2020 Florian Schmaus, 2022-2024 Guus der Kinderen * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,11 +65,14 @@ public RosterIntegrationTest(SmackIntegrationTestEnvironment environment) { public void subscribeRequestListenerTest() throws TimeoutException, Exception { IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); - final SubscribeListener subscribeListener = (from, subscribeRequest) -> { - if (from.equals(conOne.getUser().asBareJid())) { - return SubscribeListener.SubscribeAnswer.Approve; + final SubscribeListener subscribeListener = new SubscribeListener() { + @Override + public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) { + if (from.equals(conOne.getUser().asBareJid())) { + return SubscribeAnswer.Approve; + } + return SubscribeAnswer.Deny; } - return SubscribeListener.SubscribeAnswer.Deny; }; rosterTwo.addSubscribeListener(subscribeListener); @@ -116,7 +119,7 @@ private void checkIfAddedAndSubscribed(Collection addresses) { try { rosterOne.createItemAndRequestSubscription(conTwo.getUser().asBareJid(), conTwosRosterName, null); - assertResult(addedAndSubscribed, 2 * connection.getReplyTimeout(), + assertResult(addedAndSubscribed, "A roster entry for " + conTwo.getUser().asBareJid() + " using the name '" + conTwosRosterName + "' of type 'to' was expected to be added to the roster of " + conOne.getUser() + " (but it was not)."); } @@ -158,7 +161,7 @@ public void entriesAdded(Collection addresses) { }; rosterOne.addRosterListener(rosterListener); - final Presence subscribe = PresenceBuilder.buildPresence() + final Presence subscribe = conOne.getStanzaFactory().buildPresenceStanza() .ofType(Presence.Type.subscribe) .to(conTwo.getUser().asBareJid()) .build(); @@ -166,7 +169,7 @@ public void entriesAdded(Collection addresses) { try { conOne.sendStanza(subscribe); - final RosterEntry rosterEntry = assertResult(added, 2 * connection.getReplyTimeout(), "Expected the server to send a roster push back to '" + conOne.getUser() + "' after they sent a presence subscription request to '" + conTwo.getUser().asBareJid() + "' (but the server did not)."); + final RosterEntry rosterEntry = assertResult(added, "Expected the server to send a roster push back to '" + conOne.getUser() + "' after they sent a presence subscription request to '" + conTwo.getUser().asBareJid() + "' (but the server did not)."); assertEquals(ItemType.none, rosterEntry.getType(), "Unexpected subscription type on roster push after '" + conOne.getUser() + "' sent a presence subscription request to '" + conTwo.getUser().asBareJid() + "'."); assertTrue(rosterEntry.isSubscriptionPending(), "Missing 'ask=subscribe' attribute on roster push after '" + conOne.getUser() + "' sent a presence subscription request to '" + conTwo.getUser().asBareJid() + "'."); } finally { @@ -192,7 +195,7 @@ public void testPresenceDeliveredToRecipient() throws Exception { final StanzaListener stanzaListener = stanza -> added.signal((Presence) stanza); conTwo.addAsyncStanzaListener(stanzaListener, new AndFilter(StanzaTypeFilter.PRESENCE, FromMatchesFilter.createBare(conOne.getUser()))); - final Presence subscribe = PresenceBuilder.buildPresence() + final Presence subscribe = conOne.getStanzaFactory().buildPresenceStanza() .ofType(Presence.Type.subscribe) .to(conTwo.getUser().asBareJid()) .build(); @@ -230,7 +233,7 @@ public void testPresenceApprovalStampedAndDelivered() throws Exception { conOne.addAsyncStanzaListener(stanzaListener, PresenceTypeFilter.SUBSCRIBED); - final Presence subscribe = PresenceBuilder.buildPresence() + final Presence subscribe = conOne.getStanzaFactory().buildPresenceStanza() .ofType(Presence.Type.subscribe) .to(conTwo.getUser().asBareJid()) .build(); @@ -279,7 +282,7 @@ public void entriesAdded(Collection addresses) { }; rosterTwo.addRosterListener(rosterListener); - final Presence subscribe = PresenceBuilder.buildPresence() + final Presence subscribe = conOne.getStanzaFactory().buildPresenceStanza() .ofType(Presence.Type.subscribe) .to(conTwo.getUser().asBareJid()) .build(); @@ -342,14 +345,14 @@ private void checkIfAdded(Collection addresses) { }; rosterTwo.addRosterListener(rosterListenerTwo); - final Presence subscribeOne = PresenceBuilder.buildPresence() + final Presence subscribeOne = conTwo.getStanzaFactory().buildPresenceStanza() .ofType(Presence.Type.subscribe) .to(conOne.getUser().asBareJid()) .build(); try { conTwo.sendStanza(subscribeOne); - fixtureComplete.waitForResult(2 * connection.getReplyTimeout()); + fixtureComplete.waitForResult(connection.getReplyTimeout()); } finally { rosterOne.setSubscriptionMode(Roster.getDefaultSubscriptionMode()); rosterTwo.removeRosterListener(rosterListenerTwo); @@ -374,7 +377,7 @@ public void entriesUpdated(Collection addresses) { }; rosterTwo.addRosterListener(rosterListenerTwo); - final Presence subscribeTwo = PresenceBuilder.buildPresence() + final Presence subscribeTwo = conOne.getStanzaFactory().buildPresenceStanza() .ofType(Presence.Type.subscribe) .to(conTwo.getUser().asBareJid()) .build(); @@ -402,7 +405,7 @@ public void testCurrentPresenceSentAfterSubscriptionApproval() throws Exception IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); final String needle = "Look for me!"; - conTwo.sendStanza(PresenceBuilder.buildPresence().setStatus(needle).build()); + conTwo.sendStanza(conTwo.getStanzaFactory().buildPresenceStanza().setStatus(needle).build()); rosterTwo.setSubscriptionMode(Roster.SubscriptionMode.accept_all); @@ -415,7 +418,7 @@ public void testCurrentPresenceSentAfterSubscriptionApproval() throws Exception }; conOne.addAsyncStanzaListener(stanzaListener, new AndFilter(StanzaTypeFilter.PRESENCE, FromMatchesFilter.createBare(conTwo.getUser()))); - final Presence subscribe = PresenceBuilder.buildPresence() + final Presence subscribe = conOne.getStanzaFactory().buildPresenceStanza() .ofType(Presence.Type.subscribe) .to(conTwo.getUser().asBareJid()) .build(); @@ -475,7 +478,7 @@ public IQ handleIQRequest(IQ iqRequest) { // listener and the roster pushes captured by the IQ Request Handler (above). conOne.addSyncStanzaListener(presenceUpdateListener, ForEveryStanza.INSTANCE); - final Presence subscribe = PresenceBuilder.buildPresence() + final Presence subscribe = conOne.getStanzaFactory().buildPresenceStanza() .ofType(Presence.Type.subscribe) .to(conTwo.getUser().asBareJid()) .build();