Search in sources :

Example 1 with I18NRuntimeException

use of ru.sbtqa.tag.qautils.i18n.I18NRuntimeException in project page-factory-2 by sbtqa.

the class PageFactoryUtils method isRequiredAction.

/**
 * Check whether given method has {@link ActionTitle} or
 * {@link ActionTitles} annotation with required title
 *
 * @param method method to check
 * @param title required title
 * @return true|false
 */
public static Boolean isRequiredAction(Method method, final String title) {
    ActionTitle actionTitle = method.getAnnotation(ActionTitle.class);
    ActionTitles actionTitles = method.getAnnotation(ActionTitles.class);
    List<ActionTitle> actionList = new ArrayList<>();
    if (actionTitles != null) {
        actionList.addAll(Arrays.asList(actionTitles.value()));
    }
    if (actionTitle != null) {
        actionList.add(actionTitle);
    }
    for (ActionTitle action : actionList) {
        String actionValue = action.value();
        try {
            I18N i18n = I18N.getI18n(method.getDeclaringClass(), TagCucumber.getFeature().getI18n().getLocale());
            actionValue = i18n.get(action.value());
        } catch (I18NRuntimeException e) {
            LOG.debug("There is no bundle for translation class. Leave it as is", e);
        }
        if (actionValue.equals(title)) {
            return true;
        }
    }
    return false;
}
Also used : I18NRuntimeException(ru.sbtqa.tag.qautils.i18n.I18NRuntimeException) ActionTitles(ru.sbtqa.tag.pagefactory.annotations.ActionTitles) ArrayList(java.util.ArrayList) ActionTitle(ru.sbtqa.tag.pagefactory.annotations.ActionTitle) I18N(ru.sbtqa.tag.qautils.i18n.I18N)

Aggregations

ArrayList (java.util.ArrayList)1 ActionTitle (ru.sbtqa.tag.pagefactory.annotations.ActionTitle)1 ActionTitles (ru.sbtqa.tag.pagefactory.annotations.ActionTitles)1 I18N (ru.sbtqa.tag.qautils.i18n.I18N)1 I18NRuntimeException (ru.sbtqa.tag.qautils.i18n.I18NRuntimeException)1