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