In this test this assertion fails:

assertEquals(“Offline presence status not received.”, “Offline test”, presence.getStatus());

As the status is null.

The messages are:

Presence sent by test2:

Offline test

Presence received by test1:

Offline test

Test 1 is the user for connection 0, test2 the user for connection 1.

So, whilst the messages are correctly sent and received, and there is a presence, the status value of the presence is null.

As far as I can tell this is just wrong, and not obviously timing related.



public void testOfflineStatusPresence() throws Exception {

// Add a new roster entry for other user.

Roster roster = getConnection(0).getRoster();

roster.createEntry(getBareJID(1), “gato1”, null);

// Wait up to 2 seconds

long initial = System.currentTimeMillis();

while (System.currentTimeMillis() - initial < 2000 && (

roster.getPresence(getBareJID(1)).getType().equals(Presence.Type.unavailable))) {



// Sign out of conn1 with status

Presence offlinePresence = new Presence(Presence.Type.unavailable);

offlinePresence.setStatus(“Offline test”);


// Wait 500 ms


Presence presence = getConnection(0).getRoster().getPresence(getBareJID(1));

assertEquals(“Offline presence status not received.”, “Offline test”, presence.getStatus());

// Sign out of conn0.


// See if conneciton 0 can get offline status.

XMPPConnection con0 = getConnection(0);


con0.login(getUsername(0), getUsername(0));

// Wait 500 ms


presence = con0.getRoster().getPresence(getBareJID(1));

assertTrue(“Offline presence status not received after logout.”,

“Offline test”.equals(presence.getStatus()));


The problem seems to be in line 507, snippet below:

if (presence == null) {

presence = new Presence(Presence.Type.unavailable); //507


return presence;


The Presence constructor called does not set status, and the default value of status is null.

There is a Presence constructor that does explicitly set the status message, but I can’t see how to call this constructor with the appropriate arguments at this point in the code.