@Test public void propertyToWidgetWithBothUnsetIsANoop() { binder.bind(s).to(box); assertThat(box.getValue(), is("")); assertThat(s.get(), is(nullValue())); }
@Test public void propertyToWidgetIsInitiallyUntouched() { binder.bind(s).to(box); assertThat(s.isTouched(), is(false)); }
@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 shouldTouchPropertyOnBlur() { binder.bind(s).to(box); box.blur(); assertThat(s.isTouched(), is(true)); }
@Test public void propertyToWidget() { binder.bind(s).to(box); s.set("test"); assertThat(box.getValue(), is("test")); }
@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 propertyToWidgetImmediatelySetsTheWidgetsValue() { s.set("test"); binder.bind(s).to(box); assertThat(box.getValue(), is("test")); }
@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 propertyToCookieGetsInitialCookieValueUnlessAlreadyTouched() { final StubCookies cookies = new StubCookies(); final StringCookie c = new StringCookie(cookies, "c"); cookies.set("c", "foo"); s.touch(); binder.bind(s).to(c); assertThat(s.get(), is(nullValue())); assertThat(c.getValue(), is(nullValue())); }
@Test public void enhanceIgnoresTabKeyUpEvent() { final StubTextBox b = new StubTextBox(); final StringProperty s = stringProperty("s"); binder.bind(s).to(b); binder.enhance(b); b.keyUp(KEY_TAB); assertThat(s.get(), is(nullValue())); }
@Test public void propertyToListBoxUpdatesListBoxWhenPropertyIsAdaptedAndInitiallySet() { final StubListBox listBox = new StubListBox(); final ArrayList<Integer> values = list(1, 2); // s starts out null assertThat(s.get(), is(nullValue())); binder.bind(s).to(listBox, values, new IntegerAdaptor()); // but is coerced to be a string when we bind assertThat(s.get(), is("1")); assertThat(s.isTouched(), is(false)); // and we made sure to set the listBox to the right value assertThat(listBox.getSelectedIndex(), is(0)); }
@Test public void derivedValueToIsElement() { final StringProperty p = stringProperty(new DerivedValue<String>("p") { public String get() { return null; } }); final StubElement e = new StubElement(); // should skip the "set null property logic", otherwise will fail binder.bind(p).to(textOf(e)); }
@Test public void propertyToListBoxHandlesNullValue() { final StubListBox listBox = new StubListBox(); final ArrayList<String> values = list(null, "a", "b"); binder.bind(s).to(listBox, values); assertThat(listBox.getSelectedIndex(), is(0)); listBox.select("b"); assertThat(s.get(), is("b")); // null gets converted to "" (otherwise it shows up as "null"), so select that listBox.select(""); assertThat(s.get(), is(nullValue())); }
@Test public void propertyToCookieGetsInitialCookieValue() { final StubCookies cookies = new StubCookies(); final StringCookie c = new StringCookie(cookies, "c"); cookies.set("c", "foo"); binder.bind(s).to(c); assertThat(s.get(), is("foo")); assertThat(s.isTouched(), is(false)); assertThat(c.getValue(), is("foo")); }
@Test public void propertyToListBoxUpdatesPropertyWhenListBoxChanges() { final StubListBox listBox = new StubListBox(); final ArrayList<String> values = list("a", "b"); binder.bind(s).to(listBox, values); listBox.select("b"); assertThat(s.get(), is("b")); }
@Test public void propertyToListBoxAutoSelectsFirstValueOnChange() { final StubListBox listBox = new StubListBox(); final ArrayList<String> values = list("a", "b"); binder.bind(s).to(listBox, values); assertThat(s.get(), is("a")); s.set(null); assertThat(s.get(), is("a")); }
@Test public void listPropertyToListBoxHandlesNullValue() { final StubListBox listBox = new StubListBox(); final ListProperty<String> values = listProperty("values", list(null, "a", "b")); binder.bind(s).to(listBox, values); listBox.select("b"); assertThat(s.get(), is("b")); // null gets converted to "" (otherwise it shows up as "null"), so select that listBox.select(""); assertThat(s.get(), is(nullValue())); }
@Test public void listPropertyToListBoxChangesListBoxContents() { final StubListBox listBox = new StubListBox(); final ListProperty<String> values = listProperty("values", list("a", "b")); binder.bind(s).to(listBox, values); assertThat(listBox.getItems(), contains("a", "b")); values.set(list("c", "d")); assertThat(listBox.getItems(), contains("c", "d")); values.set(null); assertThat(listBox.getItems().size(), is(0)); }
@Test public void listPropertyToListBoxHandlesEmptyString() { final StubListBox listBox = new StubListBox(); final ListProperty<String> values = listProperty("values", list("", "a", "b")); binder.bind(s).to(listBox, values); listBox.select("b"); assertThat(s.get(), is("b")); listBox.select(""); assertThat(s.get(), is("")); }
@Test public void propertyToCookieGetsInitialCookieValueUnlessAlreadySet() { final StubCookies cookies = new StubCookies(); final StringCookie c = new StringCookie(cookies, "c"); cookies.set("c", "foo"); s.setValue("bar"); s.setTouched(false); // make sure to untouch binder.bind(s).to(c); assertThat(s.get(), is("bar")); assertThat(c.getValue(), is("bar")); }