From 426a5efb1de171edac1cbd94764db9edd2484963 Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Tue, 2 Jul 2024 10:50:42 +0200 Subject: [PATCH] [sinttest] Cleanup of test fixtures Additional cleanup of test fixtures: - various tests that change roster/subscription get a roster-reset - one test that registers a listener now deregisters that listener --- .../roster/LowLevelRosterIntegrationTest.java | 25 +++++++++++++------ .../GeolocationIntegrationTest.java | 2 ++ .../smackx/mood/MoodIntegrationTest.java | 2 ++ .../SoftwareInfoIntegrationTest.java | 6 +++++ .../usertune/UserTuneIntegrationTest.java | 2 ++ 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smack/roster/LowLevelRosterIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smack/roster/LowLevelRosterIntegrationTest.java index 305e9ae47..045f06691 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smack/roster/LowLevelRosterIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smack/roster/LowLevelRosterIntegrationTest.java @@ -49,7 +49,7 @@ public class LowLevelRosterIntegrationTest extends AbstractSmackLowLevelIntegrat final SimpleResultSyncPoint offlineTriggered = new SimpleResultSyncPoint(); - rosterOne.addPresenceEventListener(new AbstractPresenceEventListener() { + final AbstractPresenceEventListener presenceEventListener = new AbstractPresenceEventListener() { @Override public void presenceUnavailable(FullJid jid, Presence presence) { if (!jid.equals(conTwo.getUser())) { @@ -57,15 +57,24 @@ public class LowLevelRosterIntegrationTest extends AbstractSmackLowLevelIntegrat } offlineTriggered.signal(); } - }); + }; + rosterOne.addPresenceEventListener(presenceEventListener); - // Disconnect conTwo, this should cause an 'unavailable' presence to be send from conTwo to - // conOne. - conTwo.disconnect(); + try { + // Disconnect conTwo, this should cause an 'unavailable' presence to be send from conTwo to + // conOne. + conTwo.disconnect(); - Boolean result = offlineTriggered.waitForResult(timeout); - if (!result) { - throw new Exception("presenceUnavailable() was not called"); + Boolean result = offlineTriggered.waitForResult(timeout); + if (!result) { + throw new Exception("presenceUnavailable() was not called"); + } + } finally { + // Clean up test fixture. + rosterOne.removePresenceEventListener(presenceEventListener); + conTwo.connect(); + conTwo.login(); + IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); } } diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/geolocation/GeolocationIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/geolocation/GeolocationIntegrationTest.java index f7e708775..1cd1d3b8d 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/geolocation/GeolocationIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/geolocation/GeolocationIntegrationTest.java @@ -111,6 +111,7 @@ public class GeolocationIntegrationTest extends AbstractSmackIntegrationTest { " that contained '" + data.toXML() + "', but did not."); } finally { unregisterListener(glm2, geoLocationListener); + IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); } } @@ -171,6 +172,7 @@ public class GeolocationIntegrationTest extends AbstractSmackIntegrationTest { " that contained '" + data.toXML() + "', but did not."); } finally { unregisterListener(glm2, geoLocationListener); + IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); } } diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/mood/MoodIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/mood/MoodIntegrationTest.java index 9b1dfeacd..c430938db 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/mood/MoodIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/mood/MoodIntegrationTest.java @@ -82,6 +82,7 @@ public class MoodIntegrationTest extends AbstractSmackIntegrationTest { assertResult(moodReceived, "Expected " + conTwo.getUser() + " to receive a PEP notification, but did not."); } finally { unregisterListener(mm2, moodListener); + IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); } } @@ -117,6 +118,7 @@ public class MoodIntegrationTest extends AbstractSmackIntegrationTest { assertResult(moodReceived, "Expected " + conTwo.getUser() + " to receive a PEP notification, but did not."); } finally { unregisterListener(mm2, moodListener); + IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); } } diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/softwareInfo/SoftwareInfoIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/softwareInfo/SoftwareInfoIntegrationTest.java index 838dc3074..f01371f10 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/softwareInfo/SoftwareInfoIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/softwareInfo/SoftwareInfoIntegrationTest.java @@ -31,6 +31,7 @@ import org.jivesoftware.smackx.softwareinfo.form.SoftwareInfoForm; import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest; import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment; +import org.igniterealtime.smack.inttest.annotations.AfterClass; import org.igniterealtime.smack.inttest.annotations.BeforeClass; import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest; import org.igniterealtime.smack.inttest.annotations.SpecificationReference; @@ -54,6 +55,11 @@ public class SoftwareInfoIntegrationTest extends AbstractSmackIntegrationTest { IntegrationTestRosterUtil.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout); } + @AfterClass + public void cleanUp() throws Exception { + IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); + } + @SmackIntegrationTest public void test() throws Exception { SoftwareInfoForm softwareInfoSent = createSoftwareInfoForm(); diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/usertune/UserTuneIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/usertune/UserTuneIntegrationTest.java index 97d6eb971..e204031c4 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/usertune/UserTuneIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/usertune/UserTuneIntegrationTest.java @@ -98,6 +98,7 @@ public class UserTuneIntegrationTest extends AbstractSmackIntegrationTest { Assertions.assertNotNull(result, "Expected to receive a PEP notification, but did not."); } finally { unregisterListener(utm2, userTuneListener); + IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); } } @@ -142,6 +143,7 @@ public class UserTuneIntegrationTest extends AbstractSmackIntegrationTest { assertResult(userTuneReceived, "Expected " + conTwo.getUser() + " to receive a PEP notification from " + conOne.getUser() + ", but did not."); } finally { unregisterListener(utm2, userTuneListener); + IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); } }