MarshallingUtils { public static void marshal(Marshaller marshaller, Object graph, WebServiceMessage message) throws IOException { if (marshaller instanceof MimeMarshaller && message instanceof MimeMessage) { MimeMarshaller mimeMarshaller = (MimeMarshaller) marshaller; MimeMessageContainer container = new MimeMessageContainer((MimeMessage) message); mimeMarshaller.marshal(graph, message.getPayloadResult(), container); } else { marshaller.marshal(graph, message.getPayloadResult()); } } private  MarshallingUtils(); static Object unmarshal(Unmarshaller unmarshaller, WebServiceMessage message); static void marshal(Marshaller marshaller, Object graph, WebServiceMessage message);  }
@Test public void testMarshal() throws Exception { Marshaller marshallerMock = createMock(Marshaller.class); WebServiceMessage messageMock = createMock(WebServiceMessage.class); Result result = new StringResult(); Object marshalled = new Object(); expect(messageMock.getPayloadResult()).andReturn(result); marshallerMock.marshal(marshalled, result); replay(marshallerMock, messageMock); MarshallingUtils.marshal(marshallerMock, marshalled, messageMock); verify(marshallerMock, messageMock); }
@Test public void testMarshalMime() throws Exception { MimeMarshaller marshallerMock = createMock(MimeMarshaller.class); MimeMessage messageMock = createMock(MimeMessage.class); Result result = new StringResult(); Object marshalled = new Object(); expect(messageMock.getPayloadResult()).andReturn(result); marshallerMock.marshal(eq(marshalled), eq(result), isA(MimeContainer.class)); replay(marshallerMock, messageMock); MarshallingUtils.marshal(marshallerMock, marshalled, messageMock); verify(marshallerMock, messageMock); }