### Question:
JMSEventUnMarshaller implements EventUnMarshaller<TextMessage> { @Override public Event unmarshallEvent(List<Class<? extends Event>> eventBodyClasses, Class<? extends Event> defaultBodyClass, TextMessage transportEvent) throws CougarException { InputStream is = null; try { String messageText = ((TextMessage)transportEvent).getText(); LOGGER.debug("Received message with body [" + messageText + "]"); is = new ByteArrayInputStream(messageText.getBytes(encodingType)); String eventNameFromMessage = transportEvent.getStringProperty(JMSPropertyConstants.EVENT_NAME_FIELD_NAME); Class<? extends Event> correctClass = defaultBodyClass; for (Class c : eventBodyClasses) { if (c.getSimpleName().equals(eventNameFromMessage)) { correctClass = c; break; } } if (correctClass == null) { throw new CougarFrameworkException("Can't find event class for event named '"+eventNameFromMessage+"'"); } AbstractEvent event = (AbstractEvent) dataBindingFactory.getUnMarshaller().unmarshall(is, correctClass, encodingType, true); event.setMessageId(transportEvent.getStringProperty(JMSPropertyConstants.MESSAGE_ID_FIELD_NAME)); event.setCougarMessageRouteString(transportEvent.getStringProperty(JMSPropertyConstants.MESSAGE_ROUTING_FIELD_NAME)); return event; } catch (UnsupportedEncodingException ex) { throw new CougarFrameworkException("Unsupported encoding exception for JMS Event", ex); } catch (JMSException jmsex) { throw new CougarFrameworkException("Unsupported encoding exception for JMS Event", jmsex); } }  @Override Event unmarshallEvent(List<Class<? extends Event>> eventBodyClasses, Class<? extends Event> defaultBodyClass, TextMessage transportEvent); DataBindingFactory getDataBindingFactory(); @Required void setDataBindingFactory(DataBindingFactory dataBindingFactory); String getEncodingType(); void setEncodingType(String encodingType); static final String DEFAULT_ENCODING_TYPE; }### Answer:
@Test public void testUnMarshalling() throws JMSException { String expectedMessageId="21231123xxx"; String expectedRoutingString="betfair.com@19/1/2011 15:07"; String expectedEventName=ExpectedEvent.class.getSimpleName(); TextMessage message = Mockito.mock(TextMessage.class); Mockito.when(message.getStringProperty(Matchers.eq(JMSPropertyConstants.MESSAGE_ID_FIELD_NAME))).thenReturn(expectedMessageId); Mockito.when(message.getStringProperty(Matchers.eq(JMSPropertyConstants.MESSAGE_ROUTING_FIELD_NAME))).thenReturn(expectedRoutingString); Mockito.when(message.getStringProperty(Matchers.eq(JMSPropertyConstants.EVENT_NAME_FIELD_NAME))).thenReturn(expectedEventName); Mockito.when(message.getText()).thenReturn(""); ExpectedEvent e = Mockito.mock(ExpectedEvent.class); Mockito.when(unMarshallerImpl.unmarshall(Matchers.any(InputStream.class), Matchers.eq(ExpectedEvent.class), Matchers.anyString(), Matchers.eq(true))).thenReturn(e); List<Class<? extends Event>> eventBodyClasses = new ArrayList<Class<? extends Event>>(); eventBodyClasses.add(ExpectedEvent.class); unMarshaller.unmarshallEvent(eventBodyClasses, ExpectedEvent.class, message); Mockito.verify(e).setCougarMessageRouteString(expectedRoutingString); Mockito.verify(e).setMessageId(expectedMessageId); }