### Question:
SearchListenerBean implements MessageListener { public void onMessage(Message message) { try { ObjectMessage searchRequest = (ObjectMessage) message; String[] keywords = (String[]) searchRequest.getObject(); String[] results = searchService.search(keywords); QueueConnection connection = connectionFactory .createQueueConnection(); QueueSession session = connection.createQueueSession( false, Session.AUTO_ACKNOWLEDGE); QueueSender sender = session.createSender(resultsQueue); Message resultsMessage = session .createObjectMessage(results); sender.send(resultsMessage); connection.close(); } catch (Exception e) { throw new RuntimeException(e); } }  void onMessage(Message message); @EJB(beanInterface = SearchService.class)
    public SearchService searchService; @Resource(mappedName = "QueueConnectionFactory")
    public QueueConnectionFactory connectionFactory; @Resource(mappedName = "queue/testQueue", type = javax.jms.Queue.class)
    public Queue resultsQueue; }### Answer:
@Test public void searchRequestIsDelegatedAndResultsPassedForward() throws Exception { String[] keywords = new String[] { "keyword1", "keyword2" }; String[] results = new String[] { "match1", "match2" }; expect(searchMessage.getObject()).andReturn(keywords); expect(mockSearchService.search(aryEq(keywords))).andReturn( results); expect(factory.createQueueConnection()).andReturn(connection); expect( connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE)).andReturn(session); expect(session.createSender(mockQueue)).andReturn(sender); expect(session.createObjectMessage(aryEq(results))) .andReturn(resultMessage); sender.send(resultMessage); connection.close(); replay(mockSearchService, factory, connection, session, mockQueue, sender, resultMessage, searchMessage); SearchListenerBean bean = new SearchListenerBean(); bean.searchService = mockSearchService; bean.connectionFactory = factory; bean.resultsQueue = mockQueue; bean.onMessage(searchMessage); verify(mockSearchService, factory, connection, session, mockQueue, sender, resultMessage, searchMessage); }