### Question:
JMSUtil { public static Message createAndSetPayload(Object payload, Session session, String messageType) throws JMSException { Message message = null; if (JMSConstants.TEXT_MESSAGE_TYPE.equals(messageType)) { message = session.createTextMessage((String)payload); } else if (JMSConstants.BYTE_MESSAGE_TYPE.equals(messageType)) { message = session.createBytesMessage(); ((BytesMessage)message).writeBytes((byte[])payload); } else { message = session.createObjectMessage(); ((ObjectMessage)message).setObject((byte[])payload); } return message; } private  JMSUtil(); static Message receive(Session session,
                                  Destination replyToDestination,
                                  String correlationId,
                                  long receiveTimeout,
                                  boolean pubSubNoLocal); static Message receive(Session session,
                                  Destination replyToDestination,
                                  String correlationId,
                                  long receiveTimeout,
                                  boolean pubSubNoLocal,
                                  Exchange exchange); static RuntimeException convertJmsException(JMSException e); static String createCorrelationId(final String prefix, long sequenceNum); static Message createAndSetPayload(Object payload, Session session, String messageType); static Queue createQueue(Connection connection, String name); static final String JMS_MESSAGE_CONSUMER; static final String JMS_IGNORE_TIMEOUT; }### Answer:
@Test public void testJMSMessageMarshal() throws IOException, JMSException { String testMsg = "Test Message"; final byte[] testBytes = testMsg.getBytes(Charset.defaultCharset().name()); JMSConfiguration jmsConfig = new JMSConfiguration(); jmsConfig.setConnectionFactory(new ActiveMQConnectionFactory("vm: try (ResourceCloser closer = new ResourceCloser()) { Connection connection = JMSFactory.createConnection(jmsConfig); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Message jmsMessage = JMSUtil.createAndSetPayload(testBytes, session, JMSConstants.BYTE_MESSAGE_TYPE); assertTrue("Message should have been of type BytesMessage ", jmsMessage instanceof BytesMessage); } }