@Test public void propertyToStringTrimsToNull() { binder.bind(s).to(box); box.typeEachWithoutBlur(" "); assertThat(box.getValue(), is(" ")); // to the property the value is still null, so it doesn't update the text box assertThat(s.get(), is(nullValue())); box.blur(); assertThat(box.getValue(), is("")); assertThat(s.get(), is(nullValue())); }
@Test public void propertyToWidgetWithBothUnsetIsANoop() { binder.bind(s).to(box); assertThat(box.getValue(), is("")); assertThat(s.get(), is(nullValue())); }
@Test public void propertyToWidget() { binder.bind(s).to(box); s.set("test"); assertThat(box.getValue(), is("test")); }
@Test public void propertyToWidgetImmediatelySetsTheWidgetsValue() { s.set("test"); binder.bind(s).to(box); assertThat(box.getValue(), is("test")); }
@Test public void stringToKeyUpUpdatesViewOnChange() { binder.bind(s).toKeyUp(box); s.set("a"); assertThat(box.getValue(), is("a")); }
@Test public void stringToKeyUpSetsInitialValue() { s.set("a"); binder.bind(s).toKeyUp(box); assertThat(box.getValue(), is("a")); }
@Test public void propertyToStringTrims() { binder.bind(s).to(box); box.type(" foo bar "); assertThat(s.get(), is("foo bar")); // to the property the value changed from null to "foo bar", so it updates the text box assertThat(box.getValue(), is("foo bar")); }
@Test public void shouldOnlyUpdateSourceOnBlur() { final DoubleProperty p = new DoubleProperty(new SetValue<Double>("p")); binder.bind(p.asString()).to(box); box.focus(); box.typeEachWithoutBlur("123"); assertThat(box.getValue(), is("123")); assertThat(p.getValue(), is(123.0)); box.typeEachWithoutBlur("4"); assertThat(box.getValue(), is("1234")); assertThat(p.getValue(), is(1234.0)); box.blur(); assertThat(box.getValue(), is("1234.0")); assertThat(p.getValue(), is(1234.0)); }
@Test public void shouldSetInitialValueEvenIfBlurred() { // given a property that is not set final DoubleProperty p = new DoubleProperty(new SetValue<Double>("p")); // and we bind to it binder.bind(p.asString()).to(box); // and immediately focus (e.g. because it's the first form field on the page) box.focus(); // when we bind the initial value from the server p.setInitialValue(2.0); // then we should go ahead and update the box value assertThat(box.getValue(), is("2.0")); }