/** @return a fluent {@link StringPropertyBinder} against {@code property}. */ public <P> StringPropertyBinder bind(StringProperty property) { return new StringPropertyBinder(this, property); }
@Test public void propertyToWidgetWithBothUnsetIsANoop() { binder.bind(s).to(box); assertThat(box.getValue(), is("")); assertThat(s.get(), is(nullValue())); }
@Test public void stringToKeyUpDoesTrimEntirelyEmptySpaces() { binder.bind(s).toKeyUp(box); box.keyUp('a'); box.keyUp(KeyCodes.KEY_BACKSPACE); assertThat(s.get(), is(nullValue())); }
@Test public void errorsThatAlreadyFiredGetAddedToAnErrorList() { s.req().touch(); assertThat(s.isValid(), is(false)); binder.bind(s).errorsTo(errors); assertThat(errors.getList().size(), is(1)); }
@Test public void propertyToWidgetIsInitiallyUntouched() { binder.bind(s).to(box); assertThat(s.isTouched(), is(false)); }
@Test public void stringToKeyUpDoestTrimOnChange() { binder.bind(s).toKeyUp(box); box.type("a "); assertThat(s.get(), is("a")); }
@Test public void propertyToListBoxDoesNotFailWhenThereAreNoOptions() { final StubListBox listBox = new StubListBox(); final ArrayList<Integer> values = new ArrayList<Integer>(); // s starts out null assertThat(s.get(), is(nullValue())); binder.bind(s).to(listBox, values, new IntegerAdaptor()); // and s is still null assertThat(s.get(), is(nullValue())); // and so we were unable to select anything assertThat(listBox.getSelectedIndex(), is(-1)); }
@Test public void stringToKeyUpUpdatesModelOnKeyUp() { binder.bind(s).toKeyUp(box); box.press('a'); assertThat(s.get(), is("a")); }
@Test public void propertyToSetsValueLambda() { final StringProperty b = stringProperty("b", "foo"); final String[] value = { null }; binder.bind(b).to(v -> value[0] = v); assertThat(value[0], is("foo")); b.set("bar"); assertThat(value[0], is("bar")); }
@Test public void stringToKeyUpUpdatesModelOnChange() { binder.bind(s).toKeyUp(box); box.type("a"); // just a change, no key up assertThat(s.get(), is("a")); }
@Test public void shouldTouchPropertyOnBlur() { binder.bind(s).to(box); box.blur(); assertThat(s.isTouched(), is(true)); }
@Test public void stringToKeyUpUpdatesViewOnChange() { binder.bind(s).toKeyUp(box); s.set("a"); assertThat(box.getValue(), is("a")); }
@Test public void propertyToWidget() { binder.bind(s).to(box); s.set("test"); assertThat(box.getValue(), is("test")); }
@Test public void stringToKeyUpSetsInitialValue() { s.set("a"); binder.bind(s).toKeyUp(box); assertThat(box.getValue(), is("a")); }
@Test public void emptyStringIsTreatedAsNull() { s.set("a"); binder.bind(s).to(box); box.setValue("", true); assertThat(s.get(), is(nullValue())); }
@Test public void stringToKeyUpSetsMaxLength() { s.max(20); binder.bind(s).toKeyUp(box); assertThat(box.getMaxLength(), is(20)); }
@Test public void propertyToWidgetUsesWidgetValueIfPropertyIsUninitalized() { box.setValue("test"); binder.bind(s).to(box); assertThat(s.get(), is("test")); }
@Test public void stringToKeyUpSetsMaxLengthOnTextArea() { final StubTextArea box = new StubTextArea(); s.max(20); binder.bind(s).toKeyUp(box); assertThat(box.getMaxLength(), is(20)); }
@Test public void propertyToWidgetImmediatelySetsTheWidgetsValue() { s.set("test"); binder.bind(s).to(box); assertThat(box.getValue(), is("test")); }
@Test public void stringToKeyUpDoesNotTrimOnPress() { binder.bind(s).toKeyUp(box); box.keyPress('a'); box.keyPress(' '); box.keyUp(0); // should have a keyUp('a') assertThat(s.get(), is("a ")); }