Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2008 Ovea <dev@testatoo.org> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package org.testatoo.core.component;
 
 import org.junit.Test;
 
 import java.util.List;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.*;
 import static org.testatoo.core.ComponentType.ListBox;
 import static org.testatoo.core.ComponentType.Radio;
 
 public class ListBoxTest {
 
     private Evaluator evaluator;
     private String id = "myId";
 
     private List<Stringcountries;
 
     @Before
     public void setUp() {
          = new ArrayList<String>();
         .add("France");
         .add("Canada");
         .add("Germany");
         .add("Italy");
         .add("Spain");
 
          = mock(Evaluator.class);
 
         when(.existComponent()).thenReturn(true);
         when(.isVisible(any(Component.class))).thenReturn(true);
         when(.isEnabled(any(Component.class))).thenReturn(true);
     }
 
     @Test
     public void test_component_type() {
          = mock(Evaluator.class);
 
         when(.existComponent()).thenReturn(true);
 
         try {
             new ListBox();
             fail();
         } catch (ComponentException e) {
             assertThat(e.getMessage(), is("The component with id=" +  + " is not a ListBox but a Radio"));
         }
     }
 
     @Test
     public void can_select_a_value() {
         List<StringselectedCountries = new ArrayList<String>();
         selectedCountries.add("Canada");
 
         when(.selectedValues(any(ListBox.class))).thenReturn(selectedCountries);
         when(.values(any(ListBox.class))).thenReturn();
 
         ListBox listBox = new ListBox();
 
         listBox.select("Spain");
         verify(times(1)).select("Spain"listBox);
     }
 
     @Test
     public void can_unselect_a_value() {
         List<StringselectedCountries = new ArrayList<String>();
         selectedCountries.add("Canada");
 
         when(.selectedValues(any(ListBox.class))).thenReturn(selectedCountries);
         when(.values(any(ListBox.class))).thenReturn();
 
         ListBox listBox = new ListBox();
 
         listBox.unSelect("Canada");
        verify(times(1)).unselect("Canada"listBox);
    }
    @Test
    public void can_unselect_all_selected_values() {
        ListBox listBox = new ListBox();
        .unselectAll(listBox);
        verify(times(1)).unselectAll(listBox);
    }
    @Test
    public void can_obtain_the_selected_values() {
        List<StringselectedCountries = new ArrayList<String>();
        selectedCountries.add("Canada");
        selectedCountries.add("Spain");
        when(.selectedValues(any(ListBox.class))).thenReturn(selectedCountries);
        ListBox listBox = new ListBox();
        assertThat(Arrays.deepToString(listBox.selectedValues().toArray()), is("[Canada, Spain]"));
        verify(times(1)).selectedValues(any(ListBox.class));
    }
    @Test
    public void can_obtain_list_of_values() {
        List<StringselectedCountries = new ArrayList<String>();
        selectedCountries.add("Canada");
        selectedCountries.add("Spain");
        when(.selectedValues(any(ListBox.class))).thenReturn(selectedCountries);
        ListBox listBox = new ListBox();
        assertThat(Arrays.deepToString(listBox.values().toArray()), is("[France, Canada, Germany, Italy, Spain]"));
        assertThat(Arrays.deepToString(listBox.selectedValues().toArray()), is("[Canada, Spain]"));
        verify(times(1)).selectedValues(listBox);
        verify(times(1)).values(listBox);
    }
    @Test
    public void can_obtain_the_label() {
        when(.label(any(LabelSupport.class))).thenReturn("myLabel");
        ListBox listBox = new ListBox();
        assertThat(listBox.label(), is("myLabel"));
    }
    @Test
    public void test_toString() {
        List<StringselectedCountries = new ArrayList<String>();
        selectedCountries.add("Canada");
        selectedCountries.add("Spain");
        when(.label(any(LabelSupport.class))).thenReturn("label");
        when(.selectedValues(any(ListBox.class))).thenReturn(selectedCountries);
        ListBox listBox = new ListBox();
        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"));
    }
New to GrepCode? Check out our FAQ X