1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-11 21:41:08 +01:00

Rename 'Packet' class to 'Stanza'

Smack still uses the term 'Packet' in some places. This is just the
first step towards using correct XMPP terms in Smack.
This commit is contained in:
Florian Schmaus 2015-02-05 11:17:27 +01:00
parent 9fc26f1d83
commit 4698805a34
142 changed files with 595 additions and 572 deletions

View file

@ -29,7 +29,7 @@ import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.mockito.invocation.InvocationOnMock;
@ -80,7 +80,7 @@ public class ConnectionUtils {
Answer<PacketCollector> collectorAndSend = new Answer<PacketCollector>() {
@Override
public PacketCollector answer(InvocationOnMock invocation) throws Throwable {
Packet packet = (Packet) invocation.getArguments()[0];
Stanza packet = (Stanza) invocation.getArguments()[0];
protocol.getRequests().add(packet);
return collector;
}
@ -91,24 +91,24 @@ public class ConnectionUtils {
// mock send method
Answer<Object> addIncoming = new Answer<Object>() {
public Object answer(InvocationOnMock invocation) throws Throwable {
protocol.getRequests().add((Packet) invocation.getArguments()[0]);
protocol.getRequests().add((Stanza) invocation.getArguments()[0]);
return null;
}
};
doAnswer(addIncoming).when(connection).sendPacket(isA(Packet.class));
doAnswer(addIncoming).when(connection).sendPacket(isA(Stanza.class));
// mock receive methods
Answer<Packet> answer = new Answer<Packet>() {
public Packet answer(InvocationOnMock invocation) throws Throwable {
Answer<Stanza> answer = new Answer<Stanza>() {
public Stanza answer(InvocationOnMock invocation) throws Throwable {
return protocol.getResponses().poll();
}
};
when(collector.nextResult(anyInt())).thenAnswer(answer);
when(collector.nextResult()).thenAnswer(answer);
Answer<Packet> answerOrThrow = new Answer<Packet>() {
Answer<Stanza> answerOrThrow = new Answer<Stanza>() {
@Override
public Packet answer(InvocationOnMock invocation) throws Throwable {
Packet packet = protocol.getResponses().poll();
public Stanza answer(InvocationOnMock invocation) throws Throwable {
Stanza packet = protocol.getResponses().poll();
if (packet == null) return packet;
XMPPError xmppError = packet.getError();
if (xmppError != null) throw new XMPPErrorException(xmppError);

View file

@ -32,7 +32,7 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Stanza;
/**
* This class can be used in conjunction with a mocked XMPP connection (
@ -94,16 +94,16 @@ public class Protocol {
public boolean printProtocol = false;
// responses to requests are taken form this queue
Queue<Packet> responses = new LinkedList<Packet>();
Queue<Stanza> responses = new LinkedList<Stanza>();
// list of verifications
List<Verification<?, ?>[]> verificationList = new ArrayList<Verification<?, ?>[]>();
// list of requests
List<Packet> requests = new ArrayList<Packet>();
List<Stanza> requests = new ArrayList<Stanza>();
// list of all responses
List<Packet> responsesList = new ArrayList<Packet>();
List<Stanza> responsesList = new ArrayList<Stanza>();
/**
* Adds a responses and all verifications for the request/response pair to
@ -112,7 +112,7 @@ public class Protocol {
* @param response the response for a request
* @param verifications verifications for request/response pair
*/
public void addResponse(Packet response, Verification<?, ?>... verifications) {
public void addResponse(Stanza response, Verification<?, ?>... verifications) {
responses.offer(response);
verificationList.add(verifications);
responsesList.add(response);
@ -130,8 +130,8 @@ public class Protocol {
System.out.println("=================== Start ===============\n");
for (int i = 0; i < requests.size(); i++) {
Packet request = requests.get(i);
Packet response = responsesList.get(i);
Stanza request = requests.get(i);
Stanza response = responsesList.get(i);
if (printProtocol) {
System.out.println("------------------- Request -------------\n");
@ -145,9 +145,9 @@ public class Protocol {
}
}
Verification<Packet, Packet>[] verifications = (Verification<Packet, Packet>[]) verificationList.get(i);
Verification<Stanza, Stanza>[] verifications = (Verification<Stanza, Stanza>[]) verificationList.get(i);
if (verifications != null) {
for (Verification<Packet, Packet> verification : verifications) {
for (Verification<Stanza, Stanza> verification : verifications) {
verification.verify(request, response);
}
}
@ -161,7 +161,7 @@ public class Protocol {
*
* @return the responses queue
*/
protected Queue<Packet> getResponses() {
protected Queue<Stanza> getResponses() {
return responses;
}
@ -170,7 +170,7 @@ public class Protocol {
*
* @return list of requests
*/
public List<Packet> getRequests() {
public List<Stanza> getRequests() {
return requests;
}

View file

@ -19,7 +19,7 @@ package org.jivesoftware.util;
import static org.junit.Assert.assertEquals;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Stanza;
/**
* Implement this interface to verify a request/response pair.
@ -31,15 +31,15 @@ import org.jivesoftware.smack.packet.Packet;
*
* @author Henning Staib
*/
public interface Verification<T extends Packet, S extends Packet> {
public interface Verification<T extends Stanza, S extends Stanza> {
/**
* Verifies that the "To" field of the request corresponds with the "From" field of
* the response.
*/
public static Verification<Packet, Packet> correspondingSenderReceiver = new Verification<Packet, Packet>() {
public static Verification<Stanza, Stanza> correspondingSenderReceiver = new Verification<Stanza, Stanza>() {
public void verify(Packet request, Packet response) {
public void verify(Stanza request, Stanza response) {
assertEquals(response.getFrom(), request.getTo());
}
@ -48,9 +48,9 @@ public interface Verification<T extends Packet, S extends Packet> {
/**
* Verifies that the type of the request is a GET.
*/
public static Verification<IQ, Packet> requestTypeGET = new Verification<IQ, Packet>() {
public static Verification<IQ, Stanza> requestTypeGET = new Verification<IQ, Stanza>() {
public void verify(IQ request, Packet response) {
public void verify(IQ request, Stanza response) {
assertEquals(IQ.Type.get, request.getType());
}
@ -59,9 +59,9 @@ public interface Verification<T extends Packet, S extends Packet> {
/**
* Verifies that the type of the request is a SET.
*/
public static Verification<IQ, Packet> requestTypeSET = new Verification<IQ, Packet>() {
public static Verification<IQ, Stanza> requestTypeSET = new Verification<IQ, Stanza>() {
public void verify(IQ request, Packet response) {
public void verify(IQ request, Stanza response) {
assertEquals(IQ.Type.set, request.getType());
}
@ -70,9 +70,9 @@ public interface Verification<T extends Packet, S extends Packet> {
/**
* Verifies that the type of the request is a RESULT.
*/
public static Verification<IQ, Packet> requestTypeRESULT = new Verification<IQ, Packet>() {
public static Verification<IQ, Stanza> requestTypeRESULT = new Verification<IQ, Stanza>() {
public void verify(IQ request, Packet response) {
public void verify(IQ request, Stanza response) {
assertEquals(IQ.Type.result, request.getType());
}
@ -81,9 +81,9 @@ public interface Verification<T extends Packet, S extends Packet> {
/**
* Verifies that the type of the request is an ERROR.
*/
public static Verification<IQ, Packet> requestTypeERROR = new Verification<IQ, Packet>() {
public static Verification<IQ, Stanza> requestTypeERROR = new Verification<IQ, Stanza>() {
public void verify(IQ request, Packet response) {
public void verify(IQ request, Stanza response) {
assertEquals(IQ.Type.error, request.getType());
}