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);
}
}
Aggregations