### Question:
ActiveSyncDecoder implements SyncDefaultValues { public Boolean uniqueBooleanFieldValue(Element root, ActiveSyncFields booleanField) { Element element = DOMUtils.getUniqueElement(root, booleanField.getName()); if (element == null) { return null; } String elementText = DOMUtils.getElementText(element); logger.debug(booleanField.getName() + " value : " + elementText); if (elementText == null) { return true; } else if( !elementText.equals("1") && !elementText.equals("0")) { throw new ASRequestBooleanFieldException("Failed to parse field : " + booleanField.getName()); } return elementText.equalsIgnoreCase(AS_BOOLEAN_TRUE); }  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(expected=ASRequestBooleanFieldException.class) public void testBooleanWhenNotBoolean() throws Exception { Element request = DOMUtils.parse("<root><FieldName>not boolean</FieldName></root>").getDocumentElement(); new ActiveSyncDecoder().uniqueBooleanFieldValue(request, field("FieldName")); }
@Test public void testBooleanWhenNotPresent() throws Exception { Element request = DOMUtils.parse("<root></root>").getDocumentElement(); Boolean value = new ActiveSyncDecoder().uniqueBooleanFieldValue(request, field("FieldName")); assertThat(value).isNull(); }
@Test public void testBooleanWhenEmptyIsTrue() throws Exception { Element request = DOMUtils.parse("<root><FieldName></FieldName></root>").getDocumentElement(); Boolean value = new ActiveSyncDecoder().uniqueBooleanFieldValue(request, field("FieldName")); assertThat(value).isTrue(); }
@Test public void testBooleanWhenJustTagIsTrue() throws Exception { Element request = DOMUtils.parse("<root><FieldName /></root>").getDocumentElement(); Boolean value = new ActiveSyncDecoder().uniqueBooleanFieldValue(request, field("FieldName")); assertThat(value).isTrue(); }
@Test public void testBooleanFalse() throws Exception { Element request = DOMUtils.parse("<root><FieldName>0</FieldName></root>").getDocumentElement(); Boolean value = new ActiveSyncDecoder().uniqueBooleanFieldValue(request, field("FieldName")); assertThat(value).isFalse(); }
@Test public void testBooleanTrue() throws Exception { Element request = DOMUtils.parse("<root><FieldName>1</FieldName></root>").getDocumentElement(); Boolean value = new ActiveSyncDecoder().uniqueBooleanFieldValue(request, field("FieldName")); assertThat(value).isTrue(); }
@Test public void testBooleanDefaultFalse() throws Exception { Element request = DOMUtils.parse("<root></root>").getDocumentElement(); boolean value = new ActiveSyncDecoder().uniqueBooleanFieldValue(request, field("FieldName"), false); assertThat(value).isFalse(); }
@Test public void testBooleanDefaultTrue() throws Exception { Element request = DOMUtils.parse("<root></root>").getDocumentElement(); boolean value = new ActiveSyncDecoder().uniqueBooleanFieldValue(request, field("FieldName"), true); assertThat(value).isTrue(); }