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