### Question:
PingProtocol implements ActiveSyncProtocol<PingRequest, PingResponse> { @Override public Document encodeResponse(Device device, PingResponse pingResponse) { Document document = DOMUtils.createDoc(null, "Ping"); Element root = document.getDocumentElement(); DOMUtils.createElementAndText(root, "Status", pingResponse.getPingStatus().asSpecificationValue()); if (responseHasFolders(pingResponse)) { encodeFolders(pingResponse, root); } return document; } @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 encodeNoChangesWithFolders() throws TransformerException { PingResponse pingResponse = PingResponse.builder() .syncCollections(ImmutableSet.of( SyncCollectionResponse.builder() .collectionId(CollectionId.of(1)) .dataType(PIMDataType.CALENDAR) .syncKey(SyncKey.INITIAL_SYNC_KEY) .build(), SyncCollectionResponse.builder() .collectionId(CollectionId.of(4)) .dataType(PIMDataType.CONTACTS) .syncKey(SyncKey.INITIAL_SYNC_KEY) .build())) .pingStatus(PingStatus.NO_CHANGES) .build(); assertThat(DOMUtils.serialize(pingProtocol.encodeResponse(device, pingResponse))).isEqualTo( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Ping>" + "<Status>1</Status>" + "<Folders>" + "<Folder>1</Folder>" + "<Folder>4</Folder>" + "</Folders>" + "</Ping>"); }
@Test public void encodeChangesWithoutFolder() throws TransformerException { PingResponse pingResponse = PingResponse.builder() .syncCollections(ImmutableSet.<SyncCollectionResponse>of()) .pingStatus(PingStatus.CHANGES_OCCURED) .build(); assertThat(DOMUtils.serialize(pingProtocol.encodeResponse(device, pingResponse))).isEqualTo( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Ping>" + "<Status>2</Status>" + "</Ping>"); }