@Test public void toRadioButtonsWithAnExistingValue() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); s.set("b1"); binder.bind(s).to(b1, "b1").and(b2, "b2"); // s1 didn't change assertThat(s.get(), is("b1")); // but we know which button to mark as checked assertThat(b1.getValue(), is(true)); assertThat(b2.getValue(), is(false)); // clicking each button works b1.click(); assertThat(s.get(), is("b1")); b2.click(); assertThat(s.get(), is("b2")); }
@Test public void booleanToRadioGroupSetsOnFalse() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); final BooleanProperty b = booleanProperty("b", true); binder.bind(b).to(b1, b2); b2.click(); assertThat(b.get(), is(false)); }
@Test public void booleanToRadioGroupSetsOnTrueClick() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); final BooleanProperty b = booleanProperty("b", false); binder.bind(b).to(b1, b2); b1.click(); assertThat(b.get(), is(true)); }
@Test public void toRadioButtons() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); final StubRadioButton b3 = new StubRadioButton(); binder.bind(s).to(b1, "b1").and(b2, "b2").and(b3, "b3"); // s wasn't touched assertThat(s.get(), is(nullValue())); // and we didn't have any value to know what to set assertThat(b1.getValue(), is(false)); assertThat(b2.getValue(), is(false)); assertThat(b3.getValue(), is(false)); // clicking each button works b1.click(); assertThat(s.get(), is("b1")); b2.click(); assertThat(s.get(), is("b2")); // when model changes, the view is updated s.set("b3"); assertThat(b1.getValue(), is(false)); assertThat(b2.getValue(), is(false)); assertThat(b3.getValue(), is(true)); }