### Question:
WebSocketRouter implements WebSocketListener, Publisher { @Override public void publish(String uri, String message) { if (message == null) { LOGGER.warn("Cannot send websocket message on {}, the message is null", uri); return; } for (WebSocketDispatcher dispatcher : dispatchers) { dispatcher.publish(uri, message); } }  static Logger getLogger(); @Bind(aggregate = true) void bindDispatcher(WebSocketDispatcher dispatcher); @Unbind void unbindDispatcher(WebSocketDispatcher dispatcher); @Invalidate void stop(); @Bind(aggregate = true) synchronized void bindController(Controller controller); ParameterFactories converter(); ContentEngine engine(); @Unbind synchronized void unbindController(Controller controller); @Override void received(final String uri, final String from, final byte[] content); @Override void opened(String uri, String client); @Override void closed(String uri, String client); @Override void publish(String uri, String message); @Override void publish(String uri, byte[] message); @Override void publish(String uri, JsonNode message); @Override void send(String uri, String client, String message); @Override void send(String uri, String client, JsonNode message); @Override void send(String uri, String client, byte[] message); @Override Map<String, Integer> getNumberOpenedSocketsByUri(); @Override Integer getUriOpenedSockets(String uri);  }### Answer:
@Test public void testPublish() { WebSocketRouter router = new WebSocketRouter(); final WebSocketDispatcher dispatcher = mock(WebSocketDispatcher.class); router.dispatchers = new WebSocketDispatcher[]{dispatcher}; router.publish("/ws", "hello"); verify(dispatcher, times(1)).publish("/ws", "hello"); router.publish("/ws", "hello".getBytes(Charset.defaultCharset())); verify(dispatcher, times(1)).publish("/ws", "hello".getBytes(Charset.defaultCharset())); router.publish("/ws", (String) null); verify(dispatcher, times(0)).publish("/ws", (String) null); router.publish("/ws", (byte[]) null); verify(dispatcher, times(0)).publish("/ws", (byte[]) null); }
@Test public void testPublishJson() { ObjectMapper mapper = new ObjectMapper(); ObjectNode object = mapper.createObjectNode(); object.put("message", "hello"); ArrayNode array = mapper.createArrayNode(); array.add(object).add(mapper.createObjectNode().put("name", "wisdom")); WebSocketRouter router = new WebSocketRouter(); final WebSocketDispatcher dispatcher = mock(WebSocketDispatcher.class); router.dispatchers = new WebSocketDispatcher[]{dispatcher}; router.publish("/ws", object); verify(dispatcher, times(1)).publish("/ws", object.toString()); router.publish("/ws", array); verify(dispatcher, times(1)).publish("/ws", array.toString()); router.publish("/ws", (JsonNode) null); verify(dispatcher, times(1)).publish("/ws", NullNode.getInstance().toString()); }