### Question:
PersistenceUtils { public static void encodeRMContent(RMMessage rmmsg, Message msg, InputStream msgContent) throws IOException { CachedOutputStream cos = new CachedOutputStream(); if (msg.getAttachments() == null) { rmmsg.setContentType((String)msg.get(Message.CONTENT_TYPE)); IOUtils.copyAndCloseInput(msgContent, cos); cos.flush(); rmmsg.setContent(cos); } else { MessageImpl msgImpl1 = new MessageImpl(); msgImpl1.setContent(OutputStream.class, cos); msgImpl1.setAttachments(msg.getAttachments()); msgImpl1.put(Message.CONTENT_TYPE, msg.get(Message.CONTENT_TYPE)); msgImpl1.setContent(InputStream.class, msgContent); AttachmentSerializer serializer = new AttachmentSerializer(msgImpl1); serializer.setXop(false); serializer.writeProlog(); IOUtils.copyAndCloseInput(msgContent, cos); cos.flush(); serializer.writeAttachments(); rmmsg.setContentType((String) msgImpl1.get(Message.CONTENT_TYPE)); rmmsg.setContent(cos); } } private  PersistenceUtils(); static PersistenceUtils getInstance(); SequenceAcknowledgement deserialiseAcknowledgment(InputStream is); InputStream serialiseAcknowledgment(SequenceAcknowledgement ack); static void encodeRMContent(RMMessage rmmsg, Message msg, InputStream msgContent); static void decodeRMContent(RMMessage rmmsg, Message msg);  }### Answer:
@Test public void testEncodeRMContent() throws Exception { ByteArrayInputStream bis = new ByteArrayInputStream(SOAP_PART.getBytes()); RMMessage rmmsg = new RMMessage(); Message messageImpl = new MessageImpl(); messageImpl.put(Message.CONTENT_TYPE, "text/xml"); PersistenceUtils.encodeRMContent(rmmsg, messageImpl, bis); assertStartsWith(rmmsg.getContent().getInputStream(), "<soap:"); assertNotNull(rmmsg.getContentType()); assertTrue(rmmsg.getContentType().startsWith("text/xml")); }
@Test public void testEncodeRMContentWithAttachments() throws Exception { ByteArrayInputStream bis = new ByteArrayInputStream(SOAP_PART.getBytes()); RMMessage rmmsg = new RMMessage(); Message messageImpl = new MessageImpl(); messageImpl.put(Message.CONTENT_TYPE, "text/xml"); addAttachment(messageImpl); PersistenceUtils.encodeRMContent(rmmsg, messageImpl, bis); assertStartsWith(rmmsg.getContent().getInputStream(), "\r\n--uuid:"); assertNotNull(rmmsg.getContentType()); assertTrue(rmmsg.getContentType().startsWith("multipart/related")); }