Skip to content

Commit

Permalink
[sinttest] Applied review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
guusdk committed Apr 22, 2024
1 parent 3062dc1 commit 253d469
Showing 1 changed file with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -116,7 +119,7 @@ private void checkIfAddedAndSubscribed(Collection<Jid> 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).");
}
Expand Down Expand Up @@ -158,15 +161,15 @@ public void entriesAdded(Collection<Jid> addresses) {
};
rosterOne.addRosterListener(rosterListener);

final Presence subscribe = PresenceBuilder.buildPresence()
final Presence subscribe = conOne.getStanzaFactory().buildPresenceStanza()
.ofType(Presence.Type.subscribe)
.to(conTwo.getUser().asBareJid())
.build();

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 {
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -279,7 +282,7 @@ public void entriesAdded(Collection<Jid> addresses) {
};
rosterTwo.addRosterListener(rosterListener);

final Presence subscribe = PresenceBuilder.buildPresence()
final Presence subscribe = conOne.getStanzaFactory().buildPresenceStanza()
.ofType(Presence.Type.subscribe)
.to(conTwo.getUser().asBareJid())
.build();
Expand Down Expand Up @@ -342,14 +345,14 @@ private void checkIfAdded(Collection<Jid> 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);
Expand All @@ -374,7 +377,7 @@ public void entriesUpdated(Collection<Jid> addresses) {
};
rosterTwo.addRosterListener(rosterListenerTwo);

final Presence subscribeTwo = PresenceBuilder.buildPresence()
final Presence subscribeTwo = conOne.getStanzaFactory().buildPresenceStanza()
.ofType(Presence.Type.subscribe)
.to(conTwo.getUser().asBareJid())
.build();
Expand Down Expand Up @@ -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);

Expand 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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 253d469

Please sign in to comment.