/** * @see Component */ @Override public String toString() { return super.toString() + ", label:" + label(); } }
/** * Class constructor specifying the evaluator to use and the id of the comboBox we want to test. * The constructor checks if the given id does correspond to a comboBox. * * @param evaluator a technology specific evaluator * @param id the id (unique) of the comboBox */ public ComboBox(Evaluator evaluator, String id) { super(evaluator, id); checkIsExpectedComponent(ComboBox); }
/** * @see org.testatoo.core.nature.SimpleSelectable */ public String selectedValue() { return listSelectedValues().get(0); }
@Test public void can_obtain_list_of_values() { List<String> selectedCountries = new ArrayList<String>(); selectedCountries.add("Canada"); when(evaluator.selectedValues(any(ComboBox.class))).thenReturn(selectedCountries); when(evaluator.values(any(ComboBox.class))).thenReturn(countries); ComboBox comboBox = new ComboBox(evaluator, id); assertThat(Arrays.deepToString(comboBox.values().toArray()), is("[France, Canada, Germany, Italy, Spain]")); }
@Test public void can_obtain_the_value() { ComboBox comboBox = new ComboBox(evaluator, id); List<String> selectedValues = new ArrayList<String>(); selectedValues.add("myValue"); when(evaluator.selectedValues(comboBox)).thenReturn(selectedValues); assertThat(comboBox.selectedValue(), is("myValue")); verify(evaluator, times(1)).selectedValues(comboBox); }
@Test public void test_toString() { List<String> selectedCountries = new ArrayList<String>(); selectedCountries.add("Canada"); when(evaluator.selectedValues(any(ComboBox.class))).thenReturn(selectedCountries); when(evaluator.label(any(LabelSupport.class))).thenReturn("label"); when(evaluator.values(any(ComboBox.class))).thenReturn(countries); ComboBox comboBox = new ComboBox(evaluator, id); assertThat(comboBox.toString(), is("class org.testatoo.core.component.ComboBox with state : enabled:true, visible:true, values:[France, Canada, Germany, Italy, Spain], selectedValues:[Canada], label:label")); }
@Test public void can_select_a_value() { ComboBox comboBox = new ComboBox(evaluator, id); when(evaluator.values(any(ComboBox.class))).thenReturn(countries); when(evaluator.selectedValues(any(ComboBox.class))).thenReturn(new ArrayList<String>()); comboBox.select("Spain"); verify(evaluator, times(1)).select("Spain", comboBox); }
public static ComboBox comboBox() { Evaluator evaluator = mock(Evaluator.class); List<String> selectedValues = new ArrayList<String>(); selectedValues.add("Canada"); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(ComboBox); when(evaluator.isVisible(any(Component.class))).thenReturn(true); when(evaluator.isEnabled(any(Component.class))).thenReturn(true); when(evaluator.label(any(LabelSupport.class))).thenReturn("label"); when(evaluator.values(any(ComboBox.class))).thenReturn(countries()); when(evaluator.selectedValues(any(ComboBox.class))).thenReturn(selectedValues); return new ComboBox(evaluator, id); }
@Test public void test_component_type() { evaluator = mock(Evaluator.class); when(evaluator.existComponent(id)).thenReturn(true); when(evaluator.componentType(id)).thenReturn(Radio); try { new ComboBox(evaluator, id); fail(); } catch (ComponentException e) { assertThat(e.getMessage(), is("The component with id=" + id + " is not a ComboBox but a Radio")); } }