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;
 
This is the abstract base class corresponding to Testatoo Domain Specific Langage. This DSL is based on test langage (like "assertThat") improved with articles, adverbs, etc... It provides also action verbs (like "click on") to simulate actions on graphic objects

Author(s):
dev@testatoo.org
 
 public abstract class Language {
 
     private static ThreadLocal<Objectit = new ThreadLocal<Object>();
 
     @SuppressWarnings({"unchecked"})
     public static <T> T it() {
         return (T) .get();
     }

    
To check an assertion on a graphic object

Parameters:
<T> type of the graphic object
object the graphic object
matcher the matcher to calculate the assertion
 
     public static <T> void assertThat(T objectMatcher<T> matcher) {
         set(object);
         org.hamcrest.MatcherAssert.assertThat(objectmatcher);
     }

    
To avoid repeating the "assertThat" when calculating another assertion on the same object

Parameters:
<T> type of the graphic object
matcher the matcher to calculate the assertion
 
     @SuppressWarnings({"unchecked"})
     public static <T> void and(Matcher<T> matcher) {
         org.hamcrest.MatcherAssert.assertThat((T) ..get(), matcher);
     }

    
To avoid repeating the "assertThat" when calculating another assertion on the same object

Parameters:
object dummy object for language support (use it() in place)
matcher the matcher to calculate the assertion
 
     @SuppressWarnings({"unchecked"})
     public static <T> void and(Object objectMatcher<T> matcher) {
         and(matcher);
     }

    
To allow more readable tests

Parameters:
<T> type of the component
component testatoo component
Returns:
a testatoo component
 
     public static <T> T on(T component) {
         return into(component);
     }

    
To allow more readable tests

Parameters:
<T> type of the component
component testatoo component
Returns:
a testatoo component
 
     public static <T> T into(T component) {
        EvaluatorHolder.get().focusOn((Componentcomponent);
        return component;
    }

    
Reset the field and call the method type

Parameters:
<T> type of the textField
value value to be entered
element the textField
Returns:
the textField with value in it
    public static <T extends AbstractTextField> T enter(String value, T element) {
        EvaluatorHolder.get().reset(element);
        return type(valueelement);
    }

    
To simulate the enter of a value in a textField

Parameters:
<T> type of the textField
value value to be entered
element the textField
Returns:
the textField with value in it
    public static <T extends AbstractTextField> T type(String value, T element) {
        EvaluatorHolder.get().focusOn(element);
        Keyboard.type(value);
        return element;
    }

    
To simulate a click on a component

Parameters:
<T> type of the component
component testatoo component
Returns:
the component after click
    public static <T extends Component> T clickOn(T component) {
        Mouse.clickOn(component);
        return component;
    }

    
To simulate a double-click on a component

Parameters:
<T> type of the component
component testatoo component
Returns:
the component after double-click
    public static <T extends Component> T doubleClickOn(T component) {
        Mouse.doubleClickOn(component);
        return component;
    }

    
To simulate a mouse movement over a component

Parameters:
<T> type of the component
component testatoo component
Returns:
the component after mouse-over
    public static <T extends Component> T dragMouseOver(T component) {
        Mouse.mouseOverOn(component);
        return component;
    }

    
To simulate a mouse movement out of a component

Parameters:
<T> type of the component
component testatoo component
Returns:
the component after mouse-out
    public static <T extends Component> T dragMouseOut(T component) {
        Mouse.mouseOutOf(component);
        return component;
    }

    
To simulate a check of the component

Parameters:
<T> type of the component
component testatoo component
Returns:
the checked component
    public static <T extends Checkable> T check(T component) {
        component.check();
        return component;
    }

    
To simulate a uncheck of the component

Parameters:
<T> type of the component
component testatoo component
Returns:
the unchecked component
    public static <T extends CheckBox> T unCheck(T component) {
        component.unCheck();
        return component;
    }

    
To simulate the closing of a window

Parameters:
window the window to close
    public static void close(Window window) {
        window.close();
    }

    
Waiting until a condition is reached

Parameters:
condition a condition
    public static void waitingFor(Condition condition) {
        while (!condition.isReach()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // Do nothing
            }
        }
    }

    
Waiting until an assertion is reached. The timeout is 1 second

Parameters:
<T> type of the graphic object
object the graphic object
matcher the matcher to calculate the assertion
    public static <T> void waitUntil(T objectorg.hamcrest.Matcher<T> matcher) {
        waitUntil(objectmatcher, 1000);
    }

    
Waiting until an assertion is reached.

Parameters:
<T> type of the graphic object
object the graphic object
matcher the matcher to calculate the assertion
timeout the timeout
    public static <T> void waitUntil(T objectorg.hamcrest.Matcher<T> matcherlong timeout) {
        long step = 100;
        long current = 0;
        Throwable ex = null;
        while (current < timeout) {
            try {
                Thread.sleep(step);
                assertThat(objectmatcher);
                return;
            } catch (Throwable e) {
                ex = e;
            }
            current += step;
        }
        throw new RuntimeException("Unable to reach the condition in " + timeout + " milliseconds"ex);
    }

    
Placeholder for language

Returns:
empty Columns array
    public static Column[] columns() {
        return new Column[0];
    }

    
Placeholder for language

Returns:
empty Rows array
    public static Row[] rows() {
        return new Row[0];
    }

    
Placeholder for language

Returns:
empty Cells array
    public static Cell[] cells() {
        return new Cell[0];
    }
    private static <T> T set(T it) {
        ..set(it);
        return it;
    }
New to GrepCode? Check out our FAQ X