Search in sources :

Example 1 with TagExpression

use of gherkin.TagExpression in project cucumber-jvm by cucumber.

the class Hooks method addHook.

private static void addHook(Object[] tagsExpressionsAndBody, boolean before) {
    long timeoutMillis = DEFAULT_TIMEOUT;
    int order = DEFAULT_ORDER;
    boolean timeoutSet = false;
    boolean orderSet = false;
    Closure body = null;
    List<String> tagExpressions = new ArrayList<String>();
    for (Object o : tagsExpressionsAndBody) {
        if (o instanceof String) {
            tagExpressions.add((String) o);
        } else if (o instanceof Long) {
            if (timeoutSet) {
                throw new CucumberException("Two timeout (Long) arguments found; " + Long.toString(timeoutMillis) + ", and; " + Long.toString((Long) o));
            }
            timeoutMillis = (Long) o;
            timeoutSet = true;
        } else if (o instanceof Integer) {
            if (orderSet) {
                throw new CucumberException("Two order (Integer) arguments found; " + Integer.toString(order) + ", and; " + Integer.toString((Integer) o));
            }
            order = (Integer) o;
            orderSet = true;
        } else if (o instanceof Closure) {
            body = (Closure) o;
        } else {
            throw new CucumberException("An argument of the type " + o.getClass().getName() + " found, " + (before ? "Before" : "After") + " only allows the argument types " + "String - Tag, Long - timeout, Integer - order, and Closure");
        }
    }
    TagExpression tagExpression = new TagExpression(tagExpressions);
    if (before) {
        GroovyBackend.getInstance().addBeforeHook(tagExpression, timeoutMillis, order, body);
    } else {
        GroovyBackend.getInstance().addAfterHook(tagExpression, timeoutMillis, order, body);
    }
}
Also used : Closure(groovy.lang.Closure) ArrayList(java.util.ArrayList) CucumberException(cucumber.runtime.CucumberException) TagExpression(gherkin.TagExpression)

Aggregations

CucumberException (cucumber.runtime.CucumberException)1 TagExpression (gherkin.TagExpression)1 Closure (groovy.lang.Closure)1 ArrayList (java.util.ArrayList)1