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.language;
 
 import org.junit.Test;
 
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.not;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.*;
 import static org.testatoo.core.ComponentType.*;
 import static org.testatoo.core.Language.*;
 import static org.testatoo.core.matcher.Matchers.*;
 
 public class LanguageTest {
 
     private Evaluator evaluator;
     private String id = "myId";
 
     @Before
     public void setUp() {
          = mock(Evaluator.class);
 
         // Needed for Mouse ;)
         EvaluatorHolder.set();
         when(.existComponent()).thenReturn(true);
         when(.isVisible(any(Component.class))).thenReturn(true);
         when(.isEnabled(any(Component.class))).thenReturn(true);
     }
 
     @Test
     public void checkbox_usage_through_language() {
 
         CheckBox checkBox = new CheckBox();
         when(.isChecked(checkBox)).thenReturn(falsetruefalse);
         when(.label(checkBox)).thenReturn("myLabel");
 
         assertThat(checkBoxis(not(checked())));
 
         check(checkBox);
         assertThat(checkBoxis(checked()));
 
         unCheck(checkBox);
         assertThat(checkBoxis(not(checked())));
         assertThat(checkBoxhas(label("myLabel")));
 
         verify(times(1)).check(checkBox);
         verify(times(1)).unCheck(checkBox);
         verify(times(3)).isChecked(checkBox);
     }
 
     @Test
     public void radio_usage_through_language() {
 
         Radio radio = new Radio();
         when(.label(radio)).thenReturn("myLabel");
         when(.isChecked(radio)).thenReturn(falsetrue);
 
         assertThat(radiois(not(checked())));
 
         check(radio);
         assertThat(radiois(checked()));
 
         and(it(), has(label("myLabel")));
 
         assertThat(radiohas(label("myLabel")));
 
         verify(times(1)).check(radio);
         verify(times(2)).isChecked(radio);
     }
 
     @Test
     public void textfield_usage_through_language_part1() {
 
         TextField textField = new TextField();
         when(.label(textField)).thenReturn("myLabel");
        when(.value(textField)).thenReturn("myValue");
        assertThat(textFieldhas(label("myLabel")));
        assertThat(textFieldhas(value("myValue")));
        clickOn(textField);
        Keyboard.type("SomeData");
        verify(times(1)).click(textField.);
        verify(times(1)).type("SomeData");
    }
    @Test
        TextField textField = new TextField();
        when(.maxLength(textField)).thenReturn(255);
        when(.label(textField)).thenReturn("myLabel");
        when(.value(textField)).thenReturn("myValue");
        assertThat(textFieldis(enabled()));
        and(not(disabled()));
        and(it(), visible());
        clickOn(textField);
        Mouse.clickOn(textField);
        type("data_1"into(textField));
        verify(times(2)).click(textField.);
        verify(times(2)).focusOn(any(Component.class));
        verify(times(1)).type("data_1");
    }
    @Test
        TextField textField = new TextField();
        when(.maxLength(textField)).thenReturn(255);
        when(.label(textField)).thenReturn("myLabel");
        when(.value(textField)).thenReturn("");
        enter("SomeData"on(textField));
        verify(atLeastOnce()).focusOn(textField);
        verify(times(1)).reset(textField);
        verify(times(1)).type("SomeData");
    }
    @Test
    public void test_window_usage_through_language() {
        Window window = new Window();
        when(.isVisible(any(Component.class))).thenReturn(true);
        when(.isEnabled(any(Component.class))).thenReturn(true);
        when(.title(window)).thenReturn("windowTitle");
        close(window);
        verify(times(1)).close(window);
    }
    @Test
    public void test_mouse_usage_on_component() {
        Component component = new Component();
        clickOn(component);
        doubleClickOn(component);
        dragMouseOut(component);
        dragMouseOver(component);
        verify(times(1)).click(component.);
        verify(times(1)).doubleClick(component);
        verify(times(1)).mouseOut(component);
        verify(times(1)).mouseOver(component);
    }
    @Test
    public void test_keyboard_usage() {
        TextField textField = new TextField();
        when(.maxLength(textField)).thenReturn(255);
        when(.label(textField)).thenReturn("label");
        when(.value(textField)).thenReturn("value");
        type("Some Data"on(textField));
        Keyboard.type("Other Data");
        Keyboard.keyDown(.);
        Keyboard.release(.);
        Keyboard.press(.);
        Keyboard.release();
        verify(atLeastOnce()).focusOn(textField);
        verify(times(1)).type("Some Data");
        verify(times(1)).type("Other Data");
        verify(times(1)).press(.);
        verify(times(1)).release();
    }
    @Test
    public void test_wait_for_condition() {
        final Component component = new Component();
        Condition condition = new Condition() {
            @Override
            public boolean isReach() {
                int i = 0;
                while (i < 3) {
                    clickOn(component);
                    i++;
                }
                return true;
            }
        };
        waitingFor(condition);
        verify(times(3)).click(component.);
    }
    @Test
    public void test_wait_until_with_success() {
         = mock(Evaluator.class);
        when(.existComponent()).thenReturn(true);
        when(.isVisible(any(Component.class))).thenReturn(falsefalsefalsefalsefalsefalsetrue);
        when(.isEnabled(any(Component.class))).thenReturn(true);
        Component component = new Component();
        waitUntil(componentis(visible()));
        verify(times(7)).isVisible(any(Component.class));
    }
    @Test
    public void test_wait_until_with_failure() {
         = mock(Evaluator.class);
        when(.existComponent()).thenReturn(true);
        when(.isVisible(any(Component.class))).thenReturn(false);
        when(.isEnabled(any(Component.class))).thenReturn(true);
        Component component = new Component();
        try {
            waitUntil(componentis(visible()));
            fail();
        } catch (Exception e) {
            assertThat(e.getMessage(), is("Unable to reach the condition in 1000 milliseconds"));
        }
    }
New to GrepCode? Check out our FAQ X