public static CheckBox checkBoxWithLabel(final String label) { Evaluator evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(CheckBox); when(evaluator.isVisible(any(Component.class))).thenReturn(true); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); when(evaluator.isChecked(any(CheckBox.class))).thenReturn(true); when(evaluator.label(any(CheckBox.class))).thenReturn(label); return new CheckBox(evaluator, id); }
public static CheckBox checkedCheckBox() { Evaluator evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(CheckBox); when(evaluator.isVisible(any(Component.class))).thenReturn(true); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); when(evaluator.label(any(CheckBox.class))).thenReturn("label"); when(evaluator.isChecked(any(CheckBox.class))).thenReturn(true); return new CheckBox(evaluator, id); }
public static CheckBox unCheckedCheckBox() { Evaluator evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(CheckBox); when(evaluator.isVisible(any(Component.class))).thenReturn(true); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); when(evaluator.label(any(CheckBox.class))).thenReturn("label"); when(evaluator.isChecked(any(CheckBox.class))).thenReturn(false); return new CheckBox(evaluator, id); }
public static CheckBox checkBoxWithoutLabel() { Evaluator evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(CheckBox); when(evaluator.isVisible(any(Component.class))).thenReturn(true); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); when(evaluator.isChecked(any(CheckBox.class))).thenReturn(true); when(evaluator.label(any(CheckBox.class))).thenReturn(""); return new CheckBox(evaluator, id); }
@Test public void test_toString() { CheckBox checkBox = new CheckBox(evaluator, id); when(evaluator.isChecked(checkBox)).thenReturn(false); when(evaluator.label(checkBox)).thenReturn("label"); assertThat(checkBox.toString(), is("class org.testatoo.core.component.CheckBox with state : enabled:true, visible:true, label:label, checked:false")); } }
@Test public void test_component_type() { evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(Radio); try { new CheckBox(evaluator, id); fail(); } catch (ComponentException e) { assertThat(e.getMessage(), is("The component with id=" + id + " is not a CheckBox but a Radio")); } }
@Test public void can_check_and_modifiy_checkbox_state() { CheckBox checkBox = new CheckBox(evaluator, id); when(evaluator.isChecked(checkBox)).thenReturn(false, true, false); assertThat(checkBox.isChecked(), is(false)); checkBox.check(); assertThat(checkBox.isChecked(), is(true)); checkBox.unCheck(); assertThat(checkBox.isChecked(), is(false)); verify(evaluator, times(3)).isChecked(checkBox); verify(evaluator, times(1)).check(checkBox); verify(evaluator, times(1)).unCheck(checkBox); }
@Test public void checkbox_usage_through_language() { when(evaluator.componentType(id)).thenReturn(CheckBox); CheckBox checkBox = new CheckBox(evaluator, id); when(evaluator.isChecked(checkBox)).thenReturn(false, true, false); when(evaluator.label(checkBox)).thenReturn("myLabel"); assertThat(checkBox, is(not(checked()))); check(checkBox); assertThat(checkBox, is(checked())); unCheck(checkBox); assertThat(checkBox, is(not(checked()))); assertThat(checkBox, has(label("myLabel"))); verify(evaluator, times(1)).check(checkBox); verify(evaluator, times(1)).unCheck(checkBox); verify(evaluator, times(3)).isChecked(checkBox); }