### Question:
PostMessageEventListener { public void onMessageEvent(final String eventData) { try { final JSONValue root = JSONParser.parseStrict(eventData); final JSONObject fullJSONMessage = root.isObject(); if (isActionWatched(fullJSONMessage)) { handleJSONMessage(fullJSONMessage); } } catch (final Exception e) { GWT.log("Error while parsing content of message", e); } }  void onMessageEvent(final String eventData); abstract String getActionToWatch();  }### Answer:
@Test public void onSuccessOrError_should_not_be_called_with_action_not_watched() throws Exception { final String jsonMessage = "{\"message\":\"error\",\"action\":\"\"}"; customPostMessageEventListener.setActionToWatch("Start process"); customPostMessageEventListener.onMessageEvent(jsonMessage); verify(customPostMessageEventListener, never()).success(anyString()); verify(customPostMessageEventListener, never()).error(anyString(), anyInt()); }
@Test public void onSuccessOrError_should_be_called_with_valid_json() throws Exception { final String jsonMessage = "{\"message\":\"error\",\"action\":\"\"}"; customPostMessageEventListener.setActionToWatch(""); customPostMessageEventListener.onMessageEvent(jsonMessage); verify(customPostMessageEventListener).error(anyString(), anyInt()); }
@Test public void onSuccessOrError_should_not_be_called_with_invalid_json() throws Exception { final String jsonMessage = "{\"message\":\"success\",action\":\"Start process\"}"; customPostMessageEventListener.setActionToWatch("Start process"); customPostMessageEventListener.onMessageEvent(jsonMessage); verify(customPostMessageEventListener, never()).success(anyString()); verify(customPostMessageEventListener, never()).error(anyString(), anyInt()); }