/** @return a fluent {@link EnumPropertyBinder} against {@code property}. */ public <E extends Enum<E>> EnumPropertyBinder<E> bind(EnumProperty<E> property) { return new EnumPropertyBinder<E>(this, property); }
@Test public void bindEnumCreatesItems() { final SetValue<Color> v = new SetValue<Color>("v", Color.BLUE); final EnumProperty<Color> e = enumProperty(v); final StubListBox box = new StubListBox(); binder.bind(e).to(box, Color.values()); assertThat(box.getItemCount(), is(2)); assertThat(box.getItemText(0), is("Green")); assertThat(box.getItemText(1), is("Blue (not green)")); }
@Test public void bindEnumSetsInitialValueToOtherValue() { final SetValue<Color> v = new SetValue<Color>("v", Color.BLUE); final EnumProperty<Color> e = enumProperty(v); final StubListBox box = new StubListBox(); binder.bind(e).to(box, Color.values()); assertThat(box.getSelectedIndex(), is(1)); }
@Test public void bindEnumAutoSelectsFirstValueIfNull() { final SetValue<Color> v = new SetValue<Color>("v", null); final EnumProperty<Color> e = enumProperty(v); final StubListBox box = new StubListBox(); binder.bind(e).to(box, Color.values()); assertThat(box.getSelectedIndex(), is(0)); assertThat(v.get(), is(Color.GREEN)); }
@Test public void bindEnumSetsInitialValue() { final SetValue<Color> v = new SetValue<Color>("v", Color.GREEN); final EnumProperty<Color> e = enumProperty(v); final StubListBox box = new StubListBox(); binder.bind(e).to(box, Color.values()); assertThat(box.getSelectedIndex(), is(0)); }
@Test public void bindEnumUpdatesListBoxOnPropertyChange() { final SetValue<Color> v = new SetValue<Color>("v", Color.BLUE); final EnumProperty<Color> e = enumProperty(v); final StubListBox box = new StubListBox(); binder.bind(e).to(box, Color.values()); assertThat(box.getSelectedIndex(), is(1)); e.set(Color.GREEN); assertThat(box.getSelectedIndex(), is(0)); }
@Test public void bindEnumSetsValueOnChange() { final SetValue<Color> v = new SetValue<Color>("v", Color.GREEN); final EnumProperty<Color> e = enumProperty(v); final StubListBox box = new StubListBox(); binder.bind(e).to(box, Color.values()); box.select("Blue (not green)"); assertThat(v.get(), is(Color.BLUE)); }
@Test public void toRadioButtonAndView() { final StubRadioButton b1 = new StubRadioButton(); final StubWidget v1 = new StubWidget(); final StubRadioButton b2 = new StubRadioButton(); final StubWidget v2 = new StubWidget(); EnumProperty<Color> color = enumProperty("color", Color.BLUE); binder.bind(color).to(b1, Color.BLUE, v1).and(b2, Color.GREEN, v2); assertThat(v1, is(shown())); assertThat(v2, is(hidden())); b2.check(); assertThat(v1, is(hidden())); assertThat(v2, is(shown())); }
@Test public void toRadioButtonsAndView() { final StubRadioButton b1 = new StubRadioButton(); final StubWidget v1 = new StubWidget(); final StubRadioButton b2 = new StubRadioButton(); final StubWidget v2 = new StubWidget(); EnumProperty<Color> color = enumProperty("color", Color.BLUE); binder.bind(color).to(b1, Color.BLUE, v1).and(b2, Color.GREEN, v2); assertThat(v1, is(shown())); assertThat(v2, is(hidden())); b2.check(); assertThat(v1, is(hidden())); assertThat(v2, is(shown())); }