JComboBoxView implements ItemListener { private void changed() { List<T> list = myList.get(); T selected = myGet.get(); myIgnoreEvents = true; myCombo.removeAllItems(); if (list.isEmpty()) { myCombo.addItem(null); } else { for (T t : list) { myCombo.addItem(t); } } myCombo.setSelectedItem(selected); myIgnoreEvents = false; } JComboBoxView(JComboBox<T> combo, AspectModel<A> object, A aspect, Supplier<List<T>> list, Supplier<T> get, Consumer<T> set); void bind(); @Override void itemStateChanged(ItemEvent event);  }
@Test public void changedList() { myList.add("D"); myAspectModel.changed(TestAspect.CHANGED); check(); }
@Test public void changedSelected() { mySelected = "B"; myAspectModel.changed(TestAspect.CHANGED); check(); }
@Test public void changedListAndSelected() { myList.remove(0); mySelected = "C"; myAspectModel.changed(TestAspect.CHANGED); check(); }
@Test public void listEmpty() { myList.clear(); myAspectModel.changed(TestAspect.CHANGED); ComboBoxModel model = myComboBox.getModel(); assertEquals(1, model.getSize()); assertNull(model.getElementAt(0)); }