DefaultEnvelopeConverter implements EnvelopeConverter { @Override public JsonEnvelope fromMessage(final TextMessage message) { String messageAsString; try { messageAsString = message.getText(); return jsonObjectEnvelopeConverter.asEnvelope(stringToJsonObjectConverter.convert(messageAsString)); } catch (JMSException e) { throw createJmsConverterException(message, e); } }  @Override JsonEnvelope fromMessage(final TextMessage message); @Override TextMessage toMessage(final JsonEnvelope envelope, final Session session);  }
@Test public void shouldReturnEnvelope() throws Exception { when(textMessage.getText()).thenReturn(MESSAGE_TEXT); when(stringToJsonObjectConverter.convert(MESSAGE_TEXT)).thenReturn(messageAsJsonObject); when(jsonObjectEnvelopeConverter.asEnvelope(messageAsJsonObject)).thenReturn(envelope); JsonEnvelope actualEnvelope = envelopeConverter.fromMessage(textMessage); assertThat(actualEnvelope, equalTo(envelope)); }
@Test(expected = JmsConverterException.class) public void shouldThrowExceptionWhenFailToRetrieveMessageContent() throws JMSException { doThrow(JMSException.class).when(textMessage).getText(); envelopeConverter.fromMessage(textMessage); }
@Test(expected = JmsConverterException.class) public void shouldThrowExceptionWhenFailToRetrieveMessageId() throws JMSException { doThrow(JMSException.class).when(textMessage).getText(); doThrow(JMSException.class).when(textMessage).getJMSMessageID(); envelopeConverter.fromMessage(textMessage); }