@Override public void execute(final Object[] args) throws Throwable { Utils.invoke(body, method, timeoutMillis, args); }
public boolean addClass(Class<?> clazz) { if (Utils.isInstantiable(clazz) && classes.add(clazz)) { addConstructorDependencies(clazz); } return true; }
private String calculateElementName(cucumber.api.TestCase testCase) { String testCaseName = testCase.getName(); if (testCaseName.equals(previousTestCaseName)) { return Utils.getUniqueTestNameForScenarioExample(testCaseName, ++exampleNumber); } else { previousTestCaseName = testCase.getName(); exampleNumber = 1; return testCaseName; } }
public static String getUniqueTestNameForScenarioExample(String testCaseName, int exampleNumber) { return testCaseName + (includesBlank(testCaseName) ? " " : "_") + exampleNumber; }
private Object convertOrNull(String arg, Class ctorArgClass, String formatterString) throws IOException, URISyntaxException { if (arg == null) { if (ctorArgClass.equals(Appendable.class)) { return defaultOutOrFailIfAlreadyUsed(formatterString); } else { return null; } } if (ctorArgClass.equals(URI.class)) { return new URI(arg); } if (ctorArgClass.equals(URL.class)) { return toURL(arg); } if (ctorArgClass.equals(File.class)) { return new File(arg); } if (ctorArgClass.equals(String.class)) { return arg; } if (ctorArgClass.equals(Appendable.class)) { return new UTF8OutputStreamWriter(new URLOutputStream(toURL(arg))); } return null; }
public static Object invoke(final Object target, final Method method, long timeoutMillis, final Object... args) throws Throwable { final Method targetMethod = targetMethod(target, method); return Timeout.timeout(new Timeout.Callback<Object>() { @Override public Object call() throws Throwable { boolean accessible = targetMethod.isAccessible(); try { targetMethod.setAccessible(true); return targetMethod.invoke(target, args); } catch (IllegalArgumentException e) { throw new CucumberException("Failed to invoke " + MethodFormat.FULL.format(targetMethod) + ", caused by " + e.getClass().getName() + ": " + e.getMessage(), e); } catch (InvocationTargetException e) { throw e.getTargetException(); } catch (IllegalAccessException e) { throw new CucumberException("Failed to invoke " + MethodFormat.FULL.format(targetMethod) + ", caused by " + e.getClass().getName() + ": " + e.getMessage(), e); } finally { targetMethod.setAccessible(accessible); } } }, timeoutMillis); }
@Override public Object invoke(Object target, Method method, Object[] args) throws Throwable { for (Object plugin : getPlugins()) { if (type.isInstance(plugin)) { try { Utils.invoke(plugin, method, 0, args); } catch (Throwable t) { if (!method.getName().equals("startOfScenarioLifeCycle") && !method.getName().equals("endOfScenarioLifeCycle")) { // IntelliJ has its own formatter which doesn't yet implement these methods. throw t; } } } } return null; } });
public <T> Collection<? extends T> instantiateSubclasses(Class<T> parentType, List<String> packageNames, Class[] constructorParams, Object[] constructorArgs) { Collection<T> result = new HashSet<T>(); for (String packageName : packageNames) { for (Class<? extends T> clazz : classFinder.getDescendants(parentType, packageName)) { if (Utils.isInstantiable(clazz)) { result.add(newInstance(constructorParams, constructorArgs, clazz)); } } } return result; }
/** * {@inheritDoc} */ @Override public Object invoke(Object target, Method method, Object[] args) throws Throwable { synchronized(ZucchiniInvocationHandler.lock) { Utils.invoke(this.baseProxy, method, 0, args); } return null; } }
public boolean addClass(Class<?> clazz) { if (Utils.isInstantiable(clazz) && classes.add(clazz)) { addConstructorDependencies(clazz); } return true; }
@Override public void execute(final Object[] args) throws Throwable { Utils.invoke(body, method, timeoutMillis, args); }
public void execute(final I18n i18n, final Object[] args) throws Throwable { Utils.invoke(instance, method, timeout, args); }
private long timeout(final Annotation annotation) throws Throwable { final Method regexpMethod = annotation.getClass().getMethod("timeout"); return (Long) Utils.invoke(annotation, regexpMethod, 0); }
private Pattern pattern(final Annotation annotation) throws Throwable { final Method regexpMethod = annotation.getClass().getMethod("value"); final String regexpString = (String) Utils.invoke(annotation, regexpMethod, 0); return Pattern.compile(regexpString); }
@Override public void execute(final 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(instance, method, timeout, args); }