public void testMessageWithListen() throws IOException, JSONException {
   StringWriter stringWriter = new StringWriter();
   PrintWriter printWriter = new PrintWriter(stringWriter);
   ProtocolMessageWriter writer = new JsonMessageWriter(printWriter);
   Display display = new Display();
   Shell shell = new Shell(display);
   Button button = new Button(shell, SWT.PUSH);
   Map listeners = new HashMap();
   listeners.put("selection", new Boolean(false));
   listeners.put("focus", new Boolean(true));
   listeners.put("fake", new Boolean(true));
   writer.addListenPayload(WidgetUtil.getId(button), listeners);
   String widgetId = WidgetUtil.getId(button);
   String actual = stringWriter.getBuffer().toString();
   JSONObject message = new JSONObject(actual + "]}");
   JSONArray widgetArray = message.getJSONArray(IProtocolConstants.MESSAGE_WIDGETS);
   JSONObject widgetObject = widgetArray.getJSONObject(0);
   String actualId = widgetObject.getString(IProtocolConstants.WIDGETS_ID);
   assertEquals(widgetId, actualId);
   String type = widgetObject.getString(IProtocolConstants.WIDGETS_TYPE);
   assertEquals(IProtocolConstants.PAYLOAD_LISTEN, type);
   JSONObject payload = widgetObject.getJSONObject(IProtocolConstants.WIDGETS_PAYLOAD);
   assertFalse(payload.getBoolean("selection"));
   assertTrue(payload.getBoolean("focus"));
   assertTrue(payload.getBoolean("fake"));
 }
 private void addShellListeners(final Shell shell, final ProtocolMessageWriter writer) {
   Map listeners = new HashMap();
   for (int i = 0; i < 5; i++) {
     boolean listen = i % 2 == 0 ? true : false;
     listeners.put("listener" + i, new Boolean(listen));
   }
   writer.addListenPayload(WidgetUtil.getId(shell), listeners);
 }