### Question:
GetItemEstimateProtocol implements ActiveSyncProtocol<GetItemEstimateRequest, GetItemEstimateResponse> { @Override public GetItemEstimateRequest decodeRequest(Document doc) throws CollectionNotFoundException { final NodeList collections = doc.getDocumentElement().getElementsByTagName("Collection"); int nbElements = collections.getLength(); GetItemEstimateRequest.Builder getItemEstimateRequestBuilder = GetItemEstimateRequest.builder(); for (int i = 0; i < nbElements; i++) { final Element ce = (Element) collections.item(i); final String dataClass = DOMUtils.getElementText(ce, "Class"); final String filterType = DOMUtils.getElementText(ce, "FilterType"); final SyncKey syncKey = new SyncKey(DOMUtils.getElementText(ce, "SyncKey")); final Element fid = DOMUtils.getUniqueElement(ce, "CollectionId"); final String collectionId = fid.getTextContent(); try { getItemEstimateRequestBuilder.add(AnalysedSyncCollection.builder() .dataType(PIMDataType.recognizeDataType(dataClass)) .syncKey(syncKey) .options(buildOptions(filterType)) .collectionId(CollectionId.of(collectionId)) .build()); } catch (NumberFormatException e) { throw new CollectionNotFoundException(e); } } return getItemEstimateRequestBuilder .build(); }  @Override GetItemEstimateRequest decodeRequest(Document doc); @Override GetItemEstimateResponse decodeResponse(Document doc); @Override Document encodeResponse(Device device, GetItemEstimateResponse response); @Override Document encodeRequest(GetItemEstimateRequest request); Document buildError(GetItemEstimateStatus status, CollectionId collectionId);  }### Answer:
@Test public void testNoDataClass() throws Exception { String initialDocument = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<GetItemEstimate>" + "<Collection>" + "<SyncKey>123-456</SyncKey>" + "<CollectionId>1</CollectionId>" + "</Collection>" + "</GetItemEstimate>"; GetItemEstimateRequest request = getItemEstimateProtocol.decodeRequest(DOMUtils.parse(initialDocument)); AnalysedSyncCollection syncCollection = Iterables.getOnlyElement(request.getSyncCollections()); assertThat(syncCollection.getDataType()).isNull(); }
@Test public void testUnkownDataClass() throws Exception { String initialDocument = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<GetItemEstimate>" + "<Collection>" + "<Class>music</Class>" + "<SyncKey>123-456</SyncKey>" + "<CollectionId>1</CollectionId>" + "</Collection>" + "</GetItemEstimate>"; GetItemEstimateRequest request = getItemEstimateProtocol.decodeRequest(DOMUtils.parse(initialDocument)); AnalysedSyncCollection syncCollection = Iterables.getOnlyElement(request.getSyncCollections()); assertThat(syncCollection.getDataType()).isEqualTo(PIMDataType.UNKNOWN); }
@Test public void testEmailDataClass() throws Exception { String initialDocument = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<GetItemEstimate>" + "<Collection>" + "<Class>Email</Class>" + "<SyncKey>123-456</SyncKey>" + "<CollectionId>1</CollectionId>" + "</Collection>" + "</GetItemEstimate>"; GetItemEstimateRequest request = getItemEstimateProtocol.decodeRequest(DOMUtils.parse(initialDocument)); AnalysedSyncCollection syncCollection = Iterables.getOnlyElement(request.getSyncCollections()); assertThat(syncCollection.getDataType()).isEqualTo(PIMDataType.EMAIL); }