Search in sources :

Example 1 with Expression

use of io.cucumber.tagexpressions.Expression in project cucable-plugin by trivago.

the class GherkinDocumentParser method scenarioShouldBeIncluded.

/**
 * Checks if a scenario should be included in the runner and feature generation based on the tag settings and
 * scenarioNames settings.
 *
 * @param singleScenario a single scenario object.
 * @return true if the combined tags match the given tag expression and the scenario name (if specified) matches.
 */
private boolean scenarioShouldBeIncluded(final SingleScenario singleScenario) throws CucablePluginException {
    String includeScenarioTags = propertyManager.getIncludeScenarioTags();
    String language = singleScenario.getFeatureLanguage();
    String scenarioName = singleScenario.getScenarioName();
    boolean scenarioNameMatchExists = matchScenarioWithScenarioNames(language, scenarioName) >= 0;
    List<String> combinedScenarioTags = new ArrayList<>(singleScenario.getScenarioTags());
    combinedScenarioTags.addAll(singleScenario.getFeatureTags());
    combinedScenarioTags.addAll(singleScenario.getExampleTags());
    combinedScenarioTags = combinedScenarioTags.stream().distinct().collect(Collectors.toList());
    if (includeScenarioTags == null || includeScenarioTags.isEmpty()) {
        return scenarioNameMatchExists;
    }
    try {
        Expression tagExpression = TagExpressionParser.parse(includeScenarioTags);
        return tagExpression.evaluate(combinedScenarioTags) && scenarioNameMatchExists;
    } catch (TagExpressionException e) {
        throw new CucablePluginException("The tag expression '" + includeScenarioTags + "' is invalid: " + e.getMessage());
    }
}
Also used : TagExpressionException(io.cucumber.tagexpressions.TagExpressionException) Expression(io.cucumber.tagexpressions.Expression) CucablePluginException(com.trivago.exceptions.CucablePluginException) ArrayList(java.util.ArrayList)

Aggregations

CucablePluginException (com.trivago.exceptions.CucablePluginException)1 Expression (io.cucumber.tagexpressions.Expression)1 TagExpressionException (io.cucumber.tagexpressions.TagExpressionException)1 ArrayList (java.util.ArrayList)1