### Question:
MSEmailEncoder { @VisibleForTesting void encodeData(MSEmailBody body, Element bodyElement) throws IOException { Optional<SerializableInputStream> dataStream = body.getMimeData(); if (!dataStream.isPresent()) { return; } if (body.getBodyType().isCDataEncoded()) { DOMUtils.createElementAndCDataText(bodyElement, ASAirs.DATA.asASValue(), dataStream.get(), body.getCharset()); } else { String html = CharStreams.toString(new InputStreamReader(dataStream.get(), body.getCharset())); DOMUtils.createElementAndText(bodyElement, ASAirs.DATA.asASValue(), html); } } @Inject @VisibleForTesting  MSEmailEncoder(IntEncoder intEncoder, TimeZoneEncoder timeZoneEncoder,
			TimeZoneConverter timeZoneConverter); void encode(Element parent, IApplicationData data); Element encodedApplicationData(IApplicationData data); final static String DEFAULT_TIME_ZONE; final static String UTC_DATE_PATTERN; final static String UTC_DATE_NO_PUNCTUATION_PATTERN; }### Answer:
@Test public void testEncodeDataPlainText() throws Exception { Document reply = DOMUtils.createDoc(null, "Sync"); Element root = reply.getDocumentElement(); MSEmailBody emailBody = MSEmailBody.builder() .mimeData(Optional.of(new SerializableInputStream("text"))) .bodyType(MSEmailBodyType.PlainText) .estimatedDataSize(10) .charset(Charsets.UTF_8) .truncated(true) .build(); msEmailEncoder.encodeData(emailBody, root); String result = DOMUtils.serialize(reply); String expectedData = "<AirSyncBase:Data>" + "<![CDATA[text]]>" + "</AirSyncBase:Data>"; assertThat(result).contains(expectedData); }
@Test public void testEncodeDataHtml() throws Exception { Document reply = DOMUtils.createDoc(null, "Sync"); Element root = reply.getDocumentElement(); MSEmailBody emailBody = MSEmailBody.builder() .mimeData(Optional.of(new SerializableInputStream("<html></html>"))) .bodyType(MSEmailBodyType.HTML) .estimatedDataSize(10) .charset(Charsets.UTF_8) .truncated(true) .build(); msEmailEncoder.encodeData(emailBody, root); String result = DOMUtils.serialize(reply); String expectedData = "<AirSyncBase:Data>" + "&lt;html&gt;&lt;/html&gt;" + "</AirSyncBase:Data>"; assertThat(result).contains(expectedData); }