### Question:
ActiveSyncDecoder implements SyncDefaultValues { public Integer uniqueIntegerFieldValue(Element root, ActiveSyncFields integerField) { Long value = uniqueNumberFieldValue(root, integerField); if (value != null) { return Ints.checkedCast(value); } return null; }  String uniqueStringFieldValue(Element root, ActiveSyncFields stringField); String requiredStringFieldValue(Element root, ActiveSyncFields stringField); Boolean uniqueBooleanFieldValue(Element root, ActiveSyncFields booleanField); boolean uniqueBooleanFieldValue(Element root, ActiveSyncFields booleanField, boolean defaultValue); Integer uniqueIntegerFieldValue(Element root, ActiveSyncFields integerField); Integer requiredIntegerFieldValue(Element root, ActiveSyncFields integerField); Long uniqueLongFieldValue(Element root, ActiveSyncFields longField); void appendBoolean(Element root, ActiveSyncFields booleanField, Boolean value); void appendInteger(Element root, ActiveSyncFields integerField, Integer value); void appendString(Element root, ActiveSyncFields stringField, String value); void appendElement(Element root, Element value);  }### Answer:
@Test public void testIntegerWhen0() throws Exception { Element request = DOMUtils.parse("<root><FieldName>0</FieldName></root>").getDocumentElement(); Integer value = new ActiveSyncDecoder().uniqueIntegerFieldValue(request, field("FieldName")); assertThat(value).isEqualTo(0); }
@Test public void testIntegerWhen1000() throws Exception { Element request = DOMUtils.parse("<root><FieldName>1000</FieldName></root>").getDocumentElement(); Integer value = new ActiveSyncDecoder().uniqueIntegerFieldValue(request, field("FieldName")); assertThat(value).isEqualTo(1000); }
@Test(expected=ASRequestIntegerFieldException.class) public void testIntegerWhenNotANumber() throws Exception { Element request = DOMUtils.parse("<root><FieldName>a10</FieldName></root>").getDocumentElement(); new ActiveSyncDecoder().uniqueIntegerFieldValue(request, field("FieldName")); }
@Test public void testIntegerWhenJustTag() throws Exception { Element request = DOMUtils.parse("<root><FieldName /></root>").getDocumentElement(); Integer value = new ActiveSyncDecoder().uniqueIntegerFieldValue(request, field("FieldName")); assertThat(value).isNull(); }
@Test(expected=ASRequestIntegerFieldException.class) public void testIntegerWhenEmpty() throws Exception { Element request = DOMUtils.parse("<root><FieldName> </FieldName></root>").getDocumentElement(); new ActiveSyncDecoder().uniqueIntegerFieldValue(request, field("FieldName")); }
@Test public void testIntegerWhenNoTag() throws Exception { Element request = DOMUtils.parse("<root><FieldName></FieldName></root>").getDocumentElement(); Integer value = new ActiveSyncDecoder().uniqueIntegerFieldValue(request, field("OtherField")); assertThat(value).isNull(); }