/** * Class constructor specifying the evaluator to use and the id of the radio button we want to test. * The radio button allows the user to choose only one of a predefined set of options. * The constructor checks if the given id does correspond to a radio button. * * @param evaluator a technology specific evaluator * @param id the id (unique) of the radio button */ public Radio(Evaluator evaluator, String id) { super(evaluator, id); checkIsExpectedComponent(Radio); }
@Test public void can_check_radiobutton() { Radio radio = new Radio(evaluator, id); when(evaluator.isChecked(radio)).thenReturn(false, true); assertThat(radio.isChecked(), is(false)); radio.check(); assertThat(radio.isChecked(), is(true)); verify(evaluator, times(2)).isChecked(radio); verify(evaluator, times(1)).check(radio); }
@Test public void test_toString() { when(evaluator.label(any(Field.class))).thenReturn("label"); when(evaluator.isChecked(any(Radio.class))).thenReturn(true); Radio radio = new Radio(evaluator, id); assertThat(radio.toString(), is("class org.testatoo.core.component.Radio with state : enabled:true, visible:true, label:label, checked:true")); } }
public static Radio checkedRadio() { Evaluator evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(Radio); when(evaluator.isVisible(any(Component.class))).thenReturn(true); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); when(evaluator.label(any(Radio.class))).thenReturn("label"); when(evaluator.isChecked(any(Radio.class))).thenReturn(true); return new Radio(evaluator, id); }
public static Radio unCheckedRadio() { Evaluator evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(Radio); when(evaluator.isVisible(any(Component.class))).thenReturn(true); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); when(evaluator.label(any(Radio.class))).thenReturn("label"); when(evaluator.isChecked(any(Radio.class))).thenReturn(false); return new Radio(evaluator, id); }
@Test public void test_component_type() { evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(Panel); try { new Radio(evaluator, id); fail(); } catch (ComponentException e) { assertThat(e.getMessage(), is("The component with id=" + id + " is not a Radio but a Panel")); } }
@Test public void radio_usage_through_language() { when(evaluator.componentType(id)).thenReturn(Radio); Radio radio = new Radio(evaluator, id); when(evaluator.label(radio)).thenReturn("myLabel"); when(evaluator.isChecked(radio)).thenReturn(false, true); assertThat(radio, is(not(checked()))); check(radio); assertThat(radio, is(checked())); and(it(), has(label("myLabel"))); assertThat(radio, has(label("myLabel"))); verify(evaluator, times(1)).check(radio); verify(evaluator, times(2)).isChecked(radio); }