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 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.CheckBox;
import static org.testatoo.core.ComponentType.Radio;
public class CheckBoxTest {
    private Evaluator evaluator;
    private String id = "myId";
    @Before
    public void setUp() {
         = 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 CheckBox();
            fail();
        } catch (ComponentException e) {
            assertThat(e.getMessage(), is("The component with id=" +  + " is not a CheckBox but a Radio"));
        }
    }
    @Test
    public void can_check_and_modifiy_checkbox_state() {
        CheckBox checkBox = new CheckBox();
        when(.isChecked(checkBox)).thenReturn(falsetruefalse);
        assertThat(checkBox.isChecked(), is(false));
        checkBox.check();
        assertThat(checkBox.isChecked(), is(true));
        checkBox.unCheck();
        assertThat(checkBox.isChecked(), is(false));
        verify(times(3)).isChecked(checkBox);
        verify(times(1)).check(checkBox);
        verify(times(1)).unCheck(checkBox);
    }
    @Test
    public void test_toString() {
        CheckBox checkBox = new CheckBox();
        when(.isChecked(checkBox)).thenReturn(false);
        when(.label(checkBox)).thenReturn("label");
        assertThat(checkBox.toString(), is("class org.testatoo.core.component.CheckBox with state : enabled:true, visible:true, label:label, checked:false"));
    }
New to GrepCode? Check out our FAQ X