From 2f219c73170cf1f1457ba16aae88c39e4083ceb9 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 5 Jun 2015 14:04:17 +0200 Subject: [PATCH] Rename processPacket to processStanza and assert that 'stanza' is a Stanza. --- .../smack/AbstractXMPPConnection.java | 31 ++++++------------- .../jivesoftware/smack/DummyConnection.java | 4 +-- .../smack/ThreadedDummyConnection.java | 4 +-- .../smackx/iqlast/LastActivityTest.java | 2 +- .../smackx/iqversion/VersionTest.java | 2 +- .../jivesoftware/smackx/ping/PingTest.java | 2 +- .../smackx/receipts/DeliveryReceiptTest.java | 4 +-- .../smack/chat/ChatConnectionTest.java | 2 +- .../jivesoftware/smack/roster/RosterTest.java | 14 ++++----- .../smack/roster/RosterVersioningTest.java | 8 ++--- .../roster/SubscriptionPreApprovalTest.java | 4 +-- 11 files changed, 33 insertions(+), 44 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java index 835db34fd..43aa0e071 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/AbstractXMPPConnection.java @@ -981,7 +981,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { } ParserUtils.assertAtEndTag(parser); if (stanza != null) { - processPacket(stanza); + processStanza(stanza); } } @@ -990,29 +990,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection { * stanza(/packet) collectors and listeners and letting them examine the stanza(/packet) to see if * they are a match with the filter. * - * @param packet the stanza(/packet) to process. + * @param stanza the stanza to process. */ - protected void processPacket(Stanza packet) { - assert(packet != null); + protected void processStanza(final Stanza stanza) { + assert(stanza != null); lastStanzaReceived = System.currentTimeMillis(); // Deliver the incoming packet to listeners. - executorService.submit(new ListenerNotification(packet)); - } - - /** - * A runnable to notify all listeners and stanza(/packet) collectors of a packet. - */ - private class ListenerNotification implements Runnable { - - private final Stanza packet; - - public ListenerNotification(Stanza packet) { - this.packet = packet; - } - - public void run() { - invokePacketCollectorsAndNotifyRecvListeners(packet); - } + executorService.submit(new Runnable() { + @Override + public void run() { + invokePacketCollectorsAndNotifyRecvListeners(stanza); + } + }); } /** diff --git a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java index ae190711a..c5d14964d 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/DummyConnection.java @@ -44,7 +44,7 @@ import org.jxmpp.stringprep.XmppStringprepException; * used to retrieve a message that was generated by the client. * * Packets that should be processed by the client to simulate a received stanza - * can be delivered using the {@linkplain #processPacket(Stanza)} method. + * can be delivered using the {@linkplain #processStanza(Stanza)} method. * It invokes the registered stanza(/packet) interceptors and listeners. * * @see XMPPConnection @@ -178,7 +178,7 @@ public class DummyConnection extends AbstractXMPPConnection { * * @param packet the stanza(/packet) to process. */ - public void processPacket(Stanza packet) { + public void processStanza(Stanza packet) { invokePacketCollectorsAndNotifyRecvListeners(packet); } diff --git a/smack-core/src/test/java/org/jivesoftware/smack/ThreadedDummyConnection.java b/smack-core/src/test/java/org/jivesoftware/smack/ThreadedDummyConnection.java index 6ed36dd08..3a0a95124 100644 --- a/smack-core/src/test/java/org/jivesoftware/smack/ThreadedDummyConnection.java +++ b/smack-core/src/test/java/org/jivesoftware/smack/ThreadedDummyConnection.java @@ -68,7 +68,7 @@ public class ThreadedDummyConnection extends DummyConnection { /** * Calling this method will cause the next sendStanza call with an IQ stanza(/packet) to timeout. * This is accomplished by simply stopping the auto creating of the reply stanza(/packet) - * or processing one that was entered via {@link #processPacket(Stanza)}. + * or processing one that was entered via {@link #processStanza(Stanza)}. */ public void setTimeout() { timeout = true; @@ -99,7 +99,7 @@ public class ThreadedDummyConnection extends DummyConnection { @Override public void run() { try { - processPacket(processQ.take()); + processStanza(processQ.take()); } catch (InterruptedException e) { LOGGER.log(Level.WARNING, "exception", e); } diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/iqlast/LastActivityTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/iqlast/LastActivityTest.java index bfda54cd0..3250b5a58 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/iqlast/LastActivityTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/iqlast/LastActivityTest.java @@ -46,7 +46,7 @@ public class LastActivityTest extends InitExtensions { IQ lastRequest = (IQ) PacketParserUtils.parseStanza(xml.asString()); assertTrue(lastRequest instanceof LastActivity); - c.processPacket(lastRequest); + c.processStanza(lastRequest); Stanza reply = c.getSentPacket(); assertTrue(reply instanceof LastActivity); LastActivity l = (LastActivity) reply; diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java index d1a31a37b..e79de9251 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/iqversion/VersionTest.java @@ -47,7 +47,7 @@ public class VersionTest extends InitExtensions { assertTrue(versionRequest instanceof Version); - con.processPacket(versionRequest); + con.processStanza(versionRequest); Stanza replyPacket = con.getSentPacket(); assertTrue(replyPacket instanceof Version); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java index de8a68101..2218aa0fa 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/ping/PingTest.java @@ -56,7 +56,7 @@ public class PingTest extends InitExtensions { assertTrue(pingRequest instanceof Ping); - con.processPacket(pingRequest); + con.processStanza(pingRequest); Stanza pongPacket = con.getSentPacket(); assertTrue(pongPacket instanceof IQ); diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java index 2d5ba979b..5cf88e6d4 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/receipts/DeliveryReceiptTest.java @@ -85,7 +85,7 @@ public class DeliveryReceiptTest extends InitExtensions { m.setFrom(JidCreate.from("julia@capulet.com")); m.setStanzaId("reply-id"); m.addExtension(new DeliveryReceipt("original-test-id")); - c.processPacket(m); + c.processStanza(m); rrl.waitUntilInvocationOrTimeout(); } @@ -116,7 +116,7 @@ public class DeliveryReceiptTest extends InitExtensions { DeliveryReceiptRequest.addTo(m); // the DRM will send a reply-packet - c.processPacket(m); + c.processStanza(m); Stanza reply = c.getSentPacket(); DeliveryReceipt r = DeliveryReceipt.from((Message) reply); diff --git a/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java b/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java index 26ee8c2b6..1fe9004b3 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/chat/ChatConnectionTest.java @@ -383,7 +383,7 @@ public class ChatConnectionTest { @Override public void run() { - con.processPacket(chatPacket); + con.processStanza(chatPacket); } } diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java index 658d97522..dfd7ad2cb 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterTest.java @@ -341,7 +341,7 @@ public class RosterTest extends InitSmackIm { rosterListener.reset(); // Simulate receiving the roster push - connection.processPacket(rosterPush); + connection.processStanza(rosterPush); rosterListener.waitUntilInvocationOrTimeout(); // Verify the roster entry of the new contact @@ -380,7 +380,7 @@ public class RosterTest extends InitSmackIm { final String requestId = packet.getStanzaId(); // Simulate receiving the roster push - connection.processPacket(packet); + connection.processStanza(packet); // Smack should reply with an error IQ ErrorIQ errorIQ = (ErrorIQ) connection.getSentPacket(); @@ -482,7 +482,7 @@ public class RosterTest extends InitSmackIm { rosterListener.reset(); // Simulate receiving the roster push - connection.processPacket(rosterPush); + connection.processStanza(rosterPush); rosterListener.waitUntilInvocationOrTimeout(); // Verify the roster entry of the new contact @@ -524,7 +524,7 @@ public class RosterTest extends InitSmackIm { rosterPush.addRosterItem(item); // simulate receiving the roster push - connection.processPacket(rosterPush); + connection.processStanza(rosterPush); } } @@ -572,7 +572,7 @@ public class RosterTest extends InitSmackIm { rosterResult.addRosterItem(benvolio); // simulate receiving the roster result and exit the loop - connection.processPacket(rosterResult); + connection.processStanza(rosterResult); break; } } @@ -672,11 +672,11 @@ public class RosterTest extends InitSmackIm { rosterPush.setType(Type.set); rosterPush.setTo(connection.getUser()); rosterPush.addRosterItem(item); - connection.processPacket(rosterPush); + connection.processStanza(rosterPush); // Create and process the IQ response final IQ response = IQ.createResultIQ(rosterRequest); - connection.processPacket(response); + connection.processStanza(response); // Verify the roster update request assertSame("A roster set MUST contain one and only one element.", diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java index 6385fcc2c..df2d9d512 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/RosterVersioningTest.java @@ -152,7 +152,7 @@ public class RosterVersioningTest { answer.addRosterItem(vaglafItem); rosterListener.reset(); - connection.processPacket(answer); + connection.processStanza(answer); rosterListener.waitUntilInvocationOrTimeout(); } else { assertTrue("Expected to get a RosterPacket ", false); @@ -191,7 +191,7 @@ public class RosterVersioningTest { Item pushedItem = vaglafItem(); rosterPush.addRosterItem(pushedItem); rosterListener.reset(); - connection.processPacket(rosterPush); + connection.processStanza(rosterPush); rosterListener.waitAndReset(); assertEquals("Expect store version after push", "v97", store.getRosterVersion()); @@ -218,7 +218,7 @@ public class RosterVersioningTest { item.setItemType(ItemType.remove); rosterPush.addRosterItem(item); rosterListener.reset(); - connection.processPacket(rosterPush); + connection.processStanza(rosterPush); rosterListener.waitAndReset(); assertNull("Store doses not contain vaglaf", store.getEntry(JidCreate.bareFrom("vaglaf@example.com"))); @@ -255,7 +255,7 @@ public class RosterVersioningTest { Stanza sentPacket = connection.getSentPacket(); if (sentPacket instanceof RosterPacket) { final IQ emptyIQ = IQ.createResultIQ((RosterPacket)sentPacket); - connection.processPacket(emptyIQ); + connection.processStanza(emptyIQ); } else { assertTrue("Expected to get a RosterPacket ", false); } diff --git a/smack-im/src/test/java/org/jivesoftware/smack/roster/SubscriptionPreApprovalTest.java b/smack-im/src/test/java/org/jivesoftware/smack/roster/SubscriptionPreApprovalTest.java index 6724c99ec..338889814 100644 --- a/smack-im/src/test/java/org/jivesoftware/smack/roster/SubscriptionPreApprovalTest.java +++ b/smack-im/src/test/java/org/jivesoftware/smack/roster/SubscriptionPreApprovalTest.java @@ -171,11 +171,11 @@ public class SubscriptionPreApprovalTest extends InitSmackIm { rosterPush.setType(Type.set); rosterPush.setTo(connection.getUser()); rosterPush.addRosterItem(item); - connection.processPacket(rosterPush); + connection.processStanza(rosterPush); // Create and process the IQ response final IQ response = IQ.createResultIQ(rosterRequest); - connection.processPacket(response); + connection.processStanza(response); // Verify the roster update request assertSame("A roster set MUST contain one and only one element.",