### Question:
SyncDecoder extends ActiveSyncDecoder { @VisibleForTesting Integer getWait(Element root) { return uniqueIntegerFieldValue(root, SyncRequestFields.WAIT); } @Inject protected  SyncDecoder(DecoderFactory decoderFactory); SyncRequest decodeSync(Document doc); SyncResponse decodeSyncResponse(Document responseDocument);  }### Answer:
@Test(expected=ASRequestIntegerFieldException.class) public void testGetWaitWhenNotANumber() throws Exception { Document request = DOMUtils.parse( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Sync>" + "<Wait>a10</Wait>" + "<Collections>" + "<Collection>" + "<SyncKey>ddcf2e35-9834-49de-96ff-09979c7e2aa0</SyncKey>" + "<CollectionId>2</CollectionId>" + "</Collection>" + "</Collections>" + "</Sync>"); new SyncDecoder(null).getWait(request.getDocumentElement()); }
@Test public void testGetWaitWhenJustTagReturnNull() throws Exception { Document request = DOMUtils.parse( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Sync>" + "<Wait/>" + "<Collections>" + "<Collection>" + "<SyncKey>ddcf2e35-9834-49de-96ff-09979c7e2aa0</SyncKey>" + "<CollectionId>2</CollectionId>" + "</Collection>" + "</Collections>" + "</Sync>"); Integer wait = new SyncDecoder(null).getWait(request.getDocumentElement()); assertThat(wait).isNull(); }
@Test(expected=ASRequestIntegerFieldException.class) public void testGetWaitWhenEmpty() throws Exception { Document request = DOMUtils.parse( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Sync>" + "<Wait> </Wait>" + "<Collections>" + "<Collection>" + "<SyncKey>ddcf2e35-9834-49de-96ff-09979c7e2aa0</SyncKey>" + "<CollectionId>2</CollectionId>" + "</Collection>" + "</Collections>" + "</Sync>"); new SyncDecoder(null).getWait(request.getDocumentElement()); }
@Test public void testGetWaitWhenNotReturnNull() throws Exception { Document request = DOMUtils.parse( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Sync>" + "<Collections>" + "<Collection>" + "<SyncKey>ddcf2e35-9834-49de-96ff-09979c7e2aa0</SyncKey>" + "<CollectionId>2</CollectionId>" + "</Collection>" + "</Collections>" + "</Sync>"); Integer wait = new SyncDecoder(null).getWait(request.getDocumentElement()); assertThat(wait).isNull(); }
@Test public void testGetWaitWhen0() throws Exception { Document request = DOMUtils.parse( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Sync>" + "<Wait>0</Wait>" + "<Collections>" + "<Collection>" + "<SyncKey>ddcf2e35-9834-49de-96ff-09979c7e2aa0</SyncKey>" + "<CollectionId>2</CollectionId>" + "</Collection>" + "</Collections>" + "</Sync>"); int wait = new SyncDecoder(null).getWait(request.getDocumentElement()); assertThat(wait).isEqualTo(0); }
@Test public void testGetWaitWhen1000() throws Exception { Document request = DOMUtils.parse( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Sync>" + "<Wait>1000</Wait>" + "<Collections>" + "<Collection>" + "<SyncKey>ddcf2e35-9834-49de-96ff-09979c7e2aa0</SyncKey>" + "<CollectionId>2</CollectionId>" + "</Collection>" + "</Collections>" + "</Sync>"); int wait = new SyncDecoder(null).getWait(request.getDocumentElement()); assertThat(wait).isEqualTo(1000); }