SelectedItemProperty extends OptionalProperty<T> implements ActionListener { public SelectedItemProperty(@NotNull JComboBox comboBox) { myComboBox = comboBox; myComboBox.addActionListener(this); } SelectedItemProperty(@NotNull JComboBox comboBox); @Override void actionPerformed(ActionEvent actionEvent); @NotNull @Override Optional<T> get();  }
@Test public void testSelectedItemProperty() { TestString a = new TestString("A"); TestString b = new TestString("B"); DefaultComboBoxModel model = new DefaultComboBoxModel(); model.addElement(a); model.addElement(b); JComboBox comboBox = new JComboBox(model); SelectedItemProperty<TestString> selectedItemProperty = new SelectedItemProperty<>(comboBox); CountListener listener = new CountListener(); selectedItemProperty.addListener(listener); assertThat(selectedItemProperty.getValue()).isEqualTo(a); assertThat(listener.getCount()).isEqualTo(0); selectedItemProperty.setValue(b); assertThat(comboBox.getSelectedItem()).isEqualTo(b); assertThat(listener.getCount()).isEqualTo(1); comboBox.setSelectedIndex(0); assertThat(comboBox.getSelectedItem()).isEqualTo(a); assertThat(listener.getCount()).isEqualTo(2); comboBox.setSelectedItem(null); assertThat(selectedItemProperty.get().isPresent()).isEqualTo(false); assertThat(listener.getCount()).isEqualTo(3); }