### Question:
FolderCreateProtocol extends ActiveSyncDecoder implements ActiveSyncProtocol<FolderCreateRequest, FolderCreateResponse> { @Override public FolderCreateResponse decodeResponse(Document responseDocument) throws NoDocumentException { if (responseDocument == null) { throw new NoDocumentException("Document of FolderCreate response is null."); } Element root = responseDocument.getDocumentElement(); FolderCreateResponse.Builder builder = FolderCreateResponse.builder(); String syncKey = uniqueStringFieldValue(root, SYNC_KEY); if (syncKey != null) { builder.syncKey(new FolderSyncKey(syncKey)); } String collectionId = uniqueStringFieldValue(root, SERVER_ID); if (collectionId != null) { builder.collectionId(CollectionId.of(collectionId)); } String status = requiredStringFieldValue(root, STATUS); builder.status(FolderCreateStatus.fromSpecificationValue(status)); return builder.build(); }  Document encodeErrorResponse(FolderCreateStatus status); @Override FolderCreateRequest decodeRequest(Document requestDocument); @Override Document encodeRequest(FolderCreateRequest folderCreateRequest); @Override FolderCreateResponse decodeResponse(Document responseDocument); @Override Document encodeResponse(Device device, FolderCreateResponse folderCreateResponse);  }### Answer:
@Test public void testDecodeStatusOK() throws Exception { String initialDocument = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<FolderCreate>" + "<Status>1</Status>" + "<SyncKey>2056e98e-be0e-4d1a-8f39-328614a32f3a</SyncKey>" + "<ServerId>13</ServerId>" + "</FolderCreate>"; FolderCreateResponse folderCreateResponse = folderCreateProtocol.decodeResponse(DOMUtils.parse(initialDocument)); assertThat(folderCreateResponse.getStatus()).isEqualTo(FolderCreateStatus.OK); }
@Test public void testDecodeStatusInvalidSyncKey() throws Exception { String initialDocument = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<FolderCreate>" + "<Status>9</Status>" + "<SyncKey>2056e98e-be0e-4d1a-8f39-328614a32f3a</SyncKey>" + "<ServerId>13</ServerId>" + "</FolderCreate>"; FolderCreateResponse folderCreateResponse = folderCreateProtocol.decodeResponse(DOMUtils.parse(initialDocument)); assertThat(folderCreateResponse.getStatus()).isEqualTo(FolderCreateStatus.INVALID_SYNC_KEY); }
@Test(expected = ProtocolException.class) public void testDecodeMissingStatusShouldThrowError() throws Exception { String initialDocument = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<FolderCreate>" + "<SyncKey>2056e98e-be0e-4d1a-8f39-328614a32f3a</SyncKey>" + "<ServerId>13</ServerId>" + "</FolderCreate>"; folderCreateProtocol.decodeResponse(DOMUtils.parse(initialDocument)); }
@Test public void testDecodeMissingSyncKeyShouldThrowError() throws Exception { String initialDocument = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<FolderCreate>" + "<Status>9</Status>" + "<ServerId>13</ServerId>" + "</FolderCreate>"; FolderCreateResponse response = folderCreateProtocol.decodeResponse(DOMUtils.parse(initialDocument)); assertThat(response.getSyncKey()).isNull(); }
@Test public void testDecodeMissingServerIdShouldBeOptional() throws Exception { String initialDocument = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<FolderCreate>" + "<Status>9</Status>" + "<SyncKey>2056e98e-be0e-4d1a-8f39-328614a32f3a</SyncKey>" + "</FolderCreate>"; FolderCreateResponse response = folderCreateProtocol.decodeResponse(DOMUtils.parse(initialDocument)); assertThat(response.getCollectionId()).isNull(); }