setMockMessageHandler method

void setMockMessageHandler (String channel, Future<ByteData> handler(ByteData message))

Set a mock callback for intercepting messages from the send* methods on this class, on the given channel, without decoding them.

The given callback will replace the currently registered mock callback for that channel, if any. To remove the mock handler, pass null as the handler argument.

The handler's return value, if non-null, is used as a response, unencoded.

This is intended for testing. Messages intercepted in this manner are not sent to platform plugins.

Implementation

static void setMockMessageHandler(String channel, Future<ByteData> handler(ByteData message)) {
  if (handler == null)
    _mockHandlers.remove(channel);
  else
    _mockHandlers[channel] = handler;
}