@Test public void changedWithBinding() { Binder b = new Binder(); StringProperty s = stringProperty("s"); StubTextBox box = new StubTextBox(); b.bind(s).to(box); final Property<Boolean> c = s.changed(); assertThat(c.get(), is(false)); box.typeEach("foo"); assertThat(c.get(), is(true)); s.set("foo"); assertThat(c.get(), is(true)); } }
@Test public void testSettingValueWithTouchIsFalseWhenBound() { IntegerProperty i = integerProperty("i"); Property<String> s = i.asString(); StubTextBox textBox = new StubTextBox(); Binder b = new Binder(); b.bind(s).to(textBox); i.set(1, false); assertThat(i.isTouched(), is(false)); }
@Test public void testSettingInitialValueWhenBound() { IntegerProperty i = integerProperty("i"); Property<String> s = i.asString(); StubTextBox textBox = new StubTextBox(); Binder b = new Binder(); b.bind(s).to(textBox); i.setInitialValue(1); assertThat(i.isTouched(), is(false)); }
@Test public void testContainsBoundWhenUiChanges() { Binder b = new Binder(); StubCheckBox c = new StubCheckBox(); BooleanProperty s = p.contains("s"); b.bind(s).to(c); c.check(); assertThat(p.get(), contains("s")); c.uncheck(); assertThat(p.get().isEmpty(), is(true)); }
@Test public void testContainsBound() { Binder b = new Binder(); StubCheckBox c = new StubCheckBox(); BooleanProperty s = p.contains("s"); b.bind(s).to(c); assertThat(c.getValue(), is(false)); }
@Test public void testContainsBoundWhenAlreadyTrue() { Binder b = new Binder(); StubCheckBox c = new StubCheckBox(); p.add("s"); BooleanProperty s = p.contains("s"); b.bind(s).to(c); assertThat(c.getValue(), is(true)); }
@Test public void testContainsBoundWhenModelChanges() { Binder b = new Binder(); StubCheckBox c = new StubCheckBox(); BooleanProperty s = p.contains("s"); b.bind(s).to(c); p.add("s"); assertThat(c.getValue(), is(true)); }
@Test public void binderDoesFireChangedIfPropertyAlreadySet() { f.name.set("foo"); final StubHasValue<Integer> value = new StubHasValue<Integer>(); Binder b = new Binder(); b.bind(f.name.remaining()).to(value); assertThat(value.getValue(), is(7)); }
@Test public void setBadStringThatIsBoundToATextBox() { IntegerProperty i = integerProperty("i", 1).req(); Binder binder = new Binder(); StubTextBox box = new StubTextBox(); binder.bind(i.asString()).to(box); listenTo(i); box.type("a"); assertThat(box.getText(), is("a")); assertMessages("I must be an integer"); assertThat(i.get(), is(1)); assertThat(box.getText(), is("a")); i.set(2); assertNoMessages(); box.type(""); assertMessages("I is required"); }