roster.reload();
while (true) {
final Packet sentPacket = connection.getSentPacket();
if (sentPacket instanceof RosterPacket && ((IQ) sentPacket).getType() == Type.GET) {
// setup the roster get request
final RosterPacket rosterRequest = (RosterPacket) sentPacket;
assertSame("The <query/> element MUST NOT contain any <item/> child elements!",
0,
rosterRequest.getRosterItemCount());
// prepare the roster result
final RosterPacket rosterResult = new RosterPacket();
rosterResult.setTo(connection.getUser());
rosterResult.setType(Type.RESULT);
rosterResult.setPacketID(rosterRequest.getPacketID());
// prepare romeo's roster entry
final Item romeo = new Item("romeo@example.net", "Romeo");
romeo.addGroupName("Friends");
romeo.setItemType(ItemType.both);
rosterResult.addRosterItem(romeo);
// prepare mercutio's roster entry
final Item mercutio = new Item("mercutio@example.com", "Mercutio");
mercutio.setItemType(ItemType.from);
rosterResult.addRosterItem(mercutio);
// prepare benvolio's roster entry
final Item benvolio = new Item("benvolio@example.net", "Benvolio");
benvolio.setItemType(ItemType.both);
rosterResult.addRosterItem(benvolio);
// simulate receiving the roster result and exit the loop
connection.processPacket(rosterResult);
break;
}