Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,36 @@ public void testConnect() throws Exception {
}

}

/**
* Tests isConnected() returns false after a disconnect() call.
* @throws Exception
*/
public void testIsConnected() throws Exception {
IMqttAsyncClient mqttClient = null;
try {
mqttClient = new MqttAndroidClient(mContext, mqttServerURI, "testConnect");
IMqttToken connectToken = null;
IMqttToken disconnectToken = null;

assertFalse(mqttClient.isConnected());

connectToken = mqttClient.connect(null, null);
connectToken.waitForCompletion(waitForCompletionTime);

assertTrue(mqttClient.isConnected());

disconnectToken = mqttClient.disconnect(null, null);
disconnectToken.waitForCompletion(waitForCompletionTime);

assertFalse(mqttClient.isConnected());
}
finally {
if (mqttClient != null) {
mqttClient.close();
}
}
}

/**
* Test connection using a remote host name for the local host.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public MqttAndroidClient(Context context, String serverURI,
*/
@Override
public boolean isConnected() {
if (mqttService != null)
if (mqttService != null && clientHandle != null)
return mqttService.isConnected(clientHandle);
else
return false;
Expand Down