Skip to content

Commit

Permalink
Fix Bug 468142 - Added clientHandle null check in isConnected() to pr…
Browse files Browse the repository at this point in the history
…event NullPointerException.

Added testIsConnected unit test

Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=468142
Signed-off-by: Dustin Thomson <dthomson@51systems.com>
  • Loading branch information
powturns authored and Ian Craggs committed Jul 30, 2015
1 parent 91320f7 commit 78605e7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
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
Expand Up @@ -246,7 +246,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

0 comments on commit 78605e7

Please sign in to comment.