### Question:
SelectItemsConverter implements Converter { public Object getAsObject(FacesContext context, UIComponent component, String value) { SelectItem matchingSelectItem = null; Iterator<SelectItem> iterator = getSelectItemsIterator(context, component); while (iterator.hasNext()) { SelectItem selectItem = iterator.next(); String stringValue = getAsString(context, component, selectItem.getValue()); if (ObjectUtils.nullSafeEquals(value, stringValue)) { Assert.state(matchingSelectItem == null, "Multiple select items mapped to string value '" + stringValue + "' ensure that getAsString always returns a unique value"); matchingSelectItem = selectItem; } } Assert.state(matchingSelectItem != null, "No select item mapped to string value '" + value + "' ensure that getAsString always returns a consistent value"); return matchingSelectItem.getValue(); }  Object getAsObject(FacesContext context, UIComponent component, String value);  }### Answer:
@Test public void shouldGetAsObjectUsingStringValue() throws Exception { this.children.add(newSelectItem(1)); this.children.add(newSelectItem(2)); this.children.add(newSelectItem(3)); Object object = this.converter.getAsObject(this.context, this.component, "2"); assertThat(object, is((Object) 2)); }
@Test public void shouldFailIfMultipleSelectItemsHaveSameStringValue() throws Exception { this.children.add(newSelectItem(1)); this.children.add(newSelectItem(2)); this.children.add(newSelectItem(2)); this.thrown.expect(IllegalStateException.class); this.thrown .expectMessage("Multiple select items mapped to string value '2' ensure that getAsString always returns a unique value"); this.converter.getAsObject(this.context, this.component, "2"); }
@Test public void shouldFailIfNoSelectItemHasStringValue() throws Exception { this.children.add(newSelectItem(1)); this.children.add(newSelectItem(3)); this.thrown.expect(IllegalStateException.class); this.thrown .expectMessage("No select item mapped to string value '2' ensure that getAsString always returns a consistent value"); this.converter.getAsObject(this.context, this.component, "2"); }
@Test public void shouldSupportSelectItemWithNullValue() throws Exception { this.children.add(newSelectItem(1)); this.children.add(newSelectItem(null)); this.children.add(newSelectItem(3)); Object object = this.converter.getAsObject(this.context, this.component, ""); assertThat(object, is(nullValue())); }