### Question:
WebSocketWrapper { public void sendResultMessage(WampMessage wampMessage) { String wampMessageRaw = wampMessage.toJson(gson); try { writeToSocket(wampMessageRaw); if (wampMessageHandler != null) { wampMessageHandler.handleWampCallResult( chargingStationId.getId(), wampMessageRaw, wampMessage.getCallId() ); } } catch (IOException e) { LOG.error("IOException while writing to web socket [{}]: {}.", chargingStationId, wampMessageRaw, e); } } WebSocketWrapper(ChargingStationId chargingStationId, WebSocket webSocket, WampMessageHandler wampMessageHandler,
                            Gson gson); WebSocket getWebSocket(); boolean isOpen(); void close(); void sendMessage(WampMessage wampMessage); void sendResultMessage(WampMessage wampMessage);  }### Answer:
@Test public void sendResultMessageShouldWriteToSocket() throws IOException { WebSocket mockWebSocket = getMockWebSocket(); WebSocketWrapper wrapper = new WebSocketWrapper(CHARGING_STATION_ID, mockWebSocket, mock(WampMessageHandler.class), gson); WampMessage wampMessage = new WampMessage(WampMessage.CALL_RESULT, "1", MessageProcUri.AUTHORIZE, "dummy payload"); wrapper.sendResultMessage(wampMessage); verify(mockWebSocket).write(wampMessage.toJson(gson)); }
@Test public void sendResultMessageShouldCallMessageHandler() { WebSocket mockWebSocket = getMockWebSocket(); WampMessageHandler messageHandler = mock(WampMessageHandler.class); String callId = UUID.randomUUID().toString(); WebSocketWrapper wrapper = new WebSocketWrapper(CHARGING_STATION_ID, mockWebSocket, messageHandler, gson); WampMessage wampMessage = new WampMessage(WampMessage.CALL_RESULT, callId, MessageProcUri.START_TRANSACTION, "dummy payload"); wrapper.sendResultMessage(wampMessage); verify(messageHandler).handleWampCallResult(CHARGING_STATION_ID.getId(), wampMessage.toJson(gson), wampMessage.getCallId()); }
@Test public void ioExceptionShouldNotResultInCommunicationExceptionOnSendResultMessage() throws IOException { WebSocket mockWebSocket = getMockWebSocket(); WebSocketWrapper wrapper = new WebSocketWrapper(CHARGING_STATION_ID, mockWebSocket, mock(WampMessageHandler.class), gson); WampMessage wampMessage = new WampMessage(WampMessage.CALL_RESULT, "1", MessageProcUri.START_TRANSACTION, "dummy payload"); when(mockWebSocket.write(anyString())).thenThrow(new IOException("dummy exception")); wrapper.sendResultMessage(wampMessage); }