ListBoxItem lbi = new ListBoxItem("listbox", "List Box");
assertEquals("listbox", lbi.getName());
assertEquals("List Box", lbi.getTitle());
HorizontalPanel panel = (HorizontalPanel) lbi.asWidget();
ListBox listBox = findListBox(panel);
assertEquals(0, listBox.getItemCount());
lbi.setChoices(Arrays.asList("b", "a"), null);
assertEquals(2, listBox.getItemCount());
assertEquals("a", listBox.getItemText(0));
assertEquals("b", listBox.getItemText(1));
assertNull(lbi.getValue());
try {
lbi.setValue("c");
fail("Should have thrown an exception as 'c' is not one of the listbox values");
} catch (IllegalStateException ise) {
// good
}
assertNull(lbi.getValue());
lbi.setValue("b");
assertEquals("b", lbi.getValue());
listBox.setSelectedIndex(0);
assertEquals("a", lbi.getValue());
lbi.setChoices(Collections.singleton("d"), "d");
assertEquals(1, listBox.getItemCount());
assertEquals("d", listBox.getItemText(0));
assertEquals("d", lbi.getValue());
}