### Question:
PingProtocol implements ActiveSyncProtocol<PingRequest, PingResponse> { @Override public PingRequest decodeRequest(Document doc) { if (doc == null) { return PingRequest.builder().build(); } Element pr = doc.getDocumentElement(); Element hb = DOMUtils.getUniqueElement(pr, "HeartbeatInterval"); Long heartbeatInterval = null; if (hb != null) { heartbeatInterval = Long.valueOf(hb.getTextContent()); } LinkedHashSet<SyncCollection> syncCollections = Sets.newLinkedHashSet(); NodeList folders = pr.getElementsByTagName("Folder"); for (int i = 0; i < folders.getLength(); i++) { Element f = (Element) folders.item(i); CollectionId id = CollectionId.of(DOMUtils.getElementText(f, "Id")); syncCollections.add(SyncCollection.builder() .dataType(PIMDataType.recognizeDataType(DOMUtils.getElementText(f, "Class"))) .collectionId(id) .syncKey(SyncKey.INITIAL_SYNC_KEY) .build()); } return PingRequest.builder() .heartbeatInterval(heartbeatInterval) .syncCollections(syncCollections) .build(); } @Inject @VisibleForTesting  PingProtocol(); @Override PingRequest decodeRequest(Document doc); @Override PingResponse decodeResponse(Document doc); @Override Document encodeResponse(Device device, PingResponse pingResponse); @Override Document encodeRequest(PingRequest pingRequest); Document buildError(String errorStatus);  }### Answer:
@Test public void decodeRequest() throws Exception { Document document = DOMUtils.parse( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Ping>" + "<Folders>" + "<Folder>" + "<Id>1</Id>" + "<Class>Calendar</Class>" + "</Folder>" + "<Folder>" + "<Id>4</Id>" + "<Class>Contacts</Class>" + "</Folder>" + "</Folders>" + "</Ping>"); assertThat(pingProtocol.decodeRequest(document)).isEqualTo(PingRequest.builder() .syncCollections(ImmutableSet.of( SyncCollection.builder() .collectionId(CollectionId.of(1)) .dataType(PIMDataType.CALENDAR) .syncKey(SyncKey.INITIAL_SYNC_KEY) .build(), SyncCollection.builder() .collectionId(CollectionId.of(4)) .dataType(PIMDataType.CONTACTS) .syncKey(SyncKey.INITIAL_SYNC_KEY) .build())) .heartbeatInterval(null) .build()); }
@Test public void testDecodeDataClass() throws Exception { Document document = DOMUtils.parse( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Ping>" + "<Folders>" + "<Folder>" + "<Id>1</Id>" + "</Folder>" + "<Folder>" + "<Id>2</Id>" + "<Class>Music</Class>" + "</Folder>" + "<Folder>" + "<Id>3</Id>" + "<Class>Contacts</Class>" + "</Folder>" + "</Folders>" + "</Ping>"); PingRequest decoded = pingProtocol.decodeRequest(document); assertThat(decoded.getSyncCollections()).containsOnly( SyncCollection.builder() .collectionId(CollectionId.of(1)) .dataType(null) .syncKey(SyncKey.INITIAL_SYNC_KEY) .build(), SyncCollection.builder() .collectionId(CollectionId.of(2)) .dataType(PIMDataType.UNKNOWN) .syncKey(SyncKey.INITIAL_SYNC_KEY) .build(), SyncCollection.builder() .collectionId(CollectionId.of(3)) .dataType(PIMDataType.CONTACTS) .syncKey(SyncKey.INITIAL_SYNC_KEY) .build()); }