Search in sources :

Example 1 with NoSuchActionError

use of ru.sbtqa.tag.pagefactory.exceptions.NoSuchActionError in project page-factory-2 by sbtqa.

the class DefaultReflection method executeMethodByTitle.

@Override
public void executeMethodByTitle(Object context, String title, Object... param) {
    List<Method> methods = getDeclaredMethods(context.getClass());
    for (Method method : methods) {
        if (isRequiredAction(method, title) && isArgumentsIdentical(method, param)) {
            try {
                method.setAccessible(true);
                method.invoke(context, param);
                return;
            } catch (IllegalAccessException | InvocationTargetException e) {
                throw new FactoryRuntimeException("Error while executing action '" + title + "' on " + method.getDeclaringClass().getSimpleName() + " . See the caused exception below", ExceptionUtils.getRootCause(e));
            }
        }
    }
    throw new NoSuchActionError("There is no '" + title + "' method with parameters ['" + Arrays.stream(param).map(s -> s.getClass().toString()).collect(Collectors.joining(", ")) + "'] on page '" + context.getClass() + "'");
}
Also used : NoSuchActionError(ru.sbtqa.tag.pagefactory.exceptions.NoSuchActionError) Method(java.lang.reflect.Method) FactoryRuntimeException(ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 FactoryRuntimeException (ru.sbtqa.tag.pagefactory.exceptions.FactoryRuntimeException)1 NoSuchActionError (ru.sbtqa.tag.pagefactory.exceptions.NoSuchActionError)1