Back to project page CucumberAndroidGradle.
The source code is released under:
Apache License
If you think the Android project CucumberAndroidGradle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package cucumber.runtime.android; //from ww w . j a v a 2s .com import cucumber.api.Scenario; import cucumber.runtime.CucumberException; import cucumber.runtime.HookDefinition; import cucumber.runtime.Utils; import cucumber.runtime.java.ObjectFactory; import gherkin.TagExpression; import gherkin.formatter.model.Tag; import java.lang.reflect.Method; import java.util.Collection; import static java.util.Arrays.asList; class JavaHookDefinition implements HookDefinition { private final Method method; private final int timeout; private final TagExpression tagExpression; private final int order; private final ObjectFactory objectFactory; public JavaHookDefinition(Method method, String[] tagExpressions, int order, int timeout, ObjectFactory objectFactory) { this.method = method; this.timeout = timeout; tagExpression = new TagExpression(asList(tagExpressions)); this.order = order; this.objectFactory = objectFactory; } @Override public String getLocation(boolean detail) { AndroidMethodFormat format = detail ? AndroidMethodFormat.FULL : AndroidMethodFormat.SHORT; return format.format(method); } @Override public void execute(Scenario scenario) throws Throwable { Object[] args; switch (method.getParameterTypes().length) { case 0: args = new Object[0]; break; case 1: if (!Scenario.class.equals(method.getParameterTypes()[0])) { throw new CucumberException("When a hook declares an argument it must be of type " + Scenario.class.getName() + ". " + method.toString()); } args = new Object[]{scenario}; break; default: throw new CucumberException("Hooks must declare 0 or 1 arguments. " + method.toString()); } Utils.invoke(objectFactory.getInstance(method.getDeclaringClass()), method, timeout, args); } @Override public boolean matches(Collection<Tag> tags) { return tagExpression.eval(tags); } @Override public int getOrder() { return order; } }