### Question:
MSEmailDecoder extends ActiveSyncDecoder implements IDataDecoder { @VisibleForTesting MSEmailBody msEmailBody(Element body) { if (body == null) { return MSEmailBody.builder().build(); } Builder bodyBuilder = MSEmailBody.builder() .bodyType(MSEmailBodyType.getValueOf(uniqueIntegerFieldValue(body, ASAirs.TYPE))); Integer estimatedDataSize = uniqueIntegerFieldValue(body, ASAirs.ESTIMATED_DATA_SIZE); if (estimatedDataSize != null) { bodyBuilder.estimatedDataSize(estimatedDataSize); } Boolean truncated = uniqueBooleanFieldValue(body, ASAirs.TRUNCATED); if (truncated != null) { bodyBuilder.truncated(truncated); } String mimeData = uniqueStringFieldValue(body, ASAirs.DATA); if (mimeData != null) { bodyBuilder.mimeData(Optional.of(new SerializableInputStream(mimeData))); } return bodyBuilder.build(); } @Inject protected  MSEmailDecoder(MSMeetingRequestDecoder meetingRequestDecoder); @Override MSEmail decode(Element data);  }### Answer:
@Test public void parseBody() throws Exception { Document doc = DOMUtils.parse( "<Body>" + "<Type>2</Type>" + "<EstimatedDataSize>930</EstimatedDataSize>" + "<Truncated>1</Truncated>" + "<Data>Email data</Data>" + "</Body>"); MSEmailBody body = decoder.msEmailBody(doc.getDocumentElement()); assertThat(body.getBodyType()).isEqualTo(MSEmailBodyType.HTML); assertThat(body.getEstimatedDataSize()).isEqualTo(930); assertThat(body.isTruncated()).isTrue(); assertThat(body.getMimeData().get()).hasContentEqualTo(new ByteArrayInputStream("Email data".getBytes(Charsets.UTF_8))); }
@Test public void parseBodyTruncatedTrue() throws Exception { Document doc = DOMUtils.parse( "<Body>" + "<Type>2</Type>" + "<EstimatedDataSize>930</EstimatedDataSize>" + "<Truncated>1</Truncated>" + "<Data>Email data</Data>" + "</Body>"); MSEmailBody body = decoder.msEmailBody(doc.getDocumentElement()); assertThat(body.isTruncated()).isTrue(); }
@Test public void parseBodyTruncatedFalse() throws Exception { Document doc = DOMUtils.parse( "<Body>" + "<Type>2</Type>" + "<EstimatedDataSize>930</EstimatedDataSize>" + "<Truncated>0</Truncated>" + "<Data>Email data</Data>" + "</Body>"); MSEmailBody body = decoder.msEmailBody(doc.getDocumentElement()); assertThat(body.isTruncated()).isFalse(); }
@Test public void parseBodyTypeMime() throws Exception { Document doc = DOMUtils.parse( "<Body>" + "<Type>4</Type>" + "<EstimatedDataSize>930</EstimatedDataSize>" + "<Truncated>0</Truncated>" + "<Data>Email data</Data>" + "</Body>"); MSEmailBody body = decoder.msEmailBody(doc.getDocumentElement()); assertThat(body.getBodyType()).isEqualTo(MSEmailBodyType.MIME); }
@Test public void parseBodyHasOptionalData() throws Exception { Document doc = DOMUtils.parse( "<Body>" + "<Type>2</Type>" + "<EstimatedDataSize>930</EstimatedDataSize>" + "<Truncated>1</Truncated>" + "</Body>"); MSEmailBody body = decoder.msEmailBody(doc.getDocumentElement()); assertThat(body.getMimeData()).isAbsent(); }
@Test public void parseBodyHasOptionalType() throws Exception { Document doc = DOMUtils.parse( "<Body>" + "<EstimatedDataSize>930</EstimatedDataSize>" + "<Truncated>1</Truncated>" + "<Data>Email data</Data>" + "</Body>"); MSEmailBody body = decoder.msEmailBody(doc.getDocumentElement()); assertThat(body.getBodyType()).isNull(); }