@Override public IsRadioButton newRadioButton(String name) { return new StubRadioButton(); }
@Test public void booleanToRadioGroupSetsTheInitialValueWhenNull() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); final BooleanProperty b = booleanProperty("b"); binder.bind(b).to(b1, b2); assertThat(b1.getValue(), is(false)); assertThat(b2.getValue(), 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)); }
@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 toRadioButtonsAndView() { final StubRadioButton b1 = new StubRadioButton(); final StubWidget v1 = new StubWidget(); final StubRadioButton b2 = new StubRadioButton(); final StubWidget v2 = new StubWidget(); EnumProperty<Color> color = enumProperty("color", Color.BLUE); binder.bind(color).to(b1, Color.BLUE, v1).and(b2, Color.GREEN, v2); assertThat(v1, is(shown())); assertThat(v2, is(hidden())); b2.check(); assertThat(v1, is(hidden())); assertThat(v2, is(shown())); }
@Test public void booleanToRadioGroupSetsTheInitialValueWhenFalse() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); final BooleanProperty b = booleanProperty("b", false); binder.bind(b).to(b1, b2); assertThat(b1.getValue(), is(false)); assertThat(b2.getValue(), is(true)); }
@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 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 toRadioButtonAndView() { final StubRadioButton b1 = new StubRadioButton(); final StubWidget v1 = new StubWidget(); final StubRadioButton b2 = new StubRadioButton(); final StubWidget v2 = new StubWidget(); EnumProperty<Color> color = enumProperty("color", Color.BLUE); binder.bind(color).to(b1, Color.BLUE, v1).and(b2, Color.GREEN, v2); assertThat(v1, is(shown())); assertThat(v2, is(hidden())); b2.check(); assertThat(v1, is(hidden())); assertThat(v2, is(shown())); }
@Test public void booleanToRadioGroupSetsTheInitialValueWhenTrue() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); final BooleanProperty b = booleanProperty("b", true); binder.bind(b).to(b1, b2); assertThat(b1.getValue(), is(true)); assertThat(b2.getValue(), is(false)); }
@Test public void booleanToRadioGroupSetsOnUpdateFalse() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); final BooleanProperty b = booleanProperty("b", true); binder.bind(b).to(b1, b2); b.set(false); assertThat(b1.getValue(), is(false)); assertThat(b2.getValue(), is(true)); }
@Test public void booleanToRadioGroupSetsOnUpdateTrue() { final StubRadioButton b1 = new StubRadioButton(); final StubRadioButton b2 = new StubRadioButton(); final BooleanProperty b = booleanProperty("b", false); binder.bind(b).to(b1, b2); b.set(true); assertThat(b1.getValue(), is(true)); assertThat(b2.getValue(), is(false)); }