DeviceResponseMessageSender implements ResponseMessageSender { @Override public void send(final ResponseMessage responseMessage) { if (!(responseMessage instanceof ProtocolResponseMessage)) { LOGGER.error(LOG_MESSAGE_RESPONSE_MESSAGE_OF_WRONG_TYPE, responseMessage.getClass().getName()); return; } final ProtocolResponseMessage msg = (ProtocolResponseMessage) responseMessage; if (!ProtocolResponseMessageValidator.isValid(msg, LOGGER)) { return; } try { this.sendMessage(msg); } catch (final IllegalStateException | UncategorizedJmsException e) { if (this.isCloseConnectionsOnBrokerFailure) { LOGGER.error(LOG_MESSAGE_JMS_EXCEPTION, e); this.iec60870DeviceConnectionService.closeAllConnections(); } throw e; } }  @Override void send(final ResponseMessage responseMessage);  }
@Test public void shouldSendResponse() { final ProtocolResponseMessage responseMessage = this.createDefaultResponseMessage(); this.messageSender.send(responseMessage); verify(this.jmsTemplate).send(any(MessageCreator.class)); }
@Test public void shouldCloseAllConnectionsOnBrokerFailure() { final ProtocolResponseMessage responseMessage = this.createDefaultResponseMessage(); doThrow(IllegalStateException.class).when(this.jmsTemplate).send(any(MessageCreator.class)); assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { this.messageSender.send(responseMessage); }); verify(this.clientConnectionService).closeAllConnections(); }