How to use tableRowIsNotExcludedBy method of io.cucumber.core.plugin.LineFilters class

Best Serenity Cucumber code snippet using io.cucumber.core.plugin.LineFilters.tableRowIsNotExcludedBy

Run Serenity Cucumber automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package io.cucumber.core.plugin;
2
3import io.cucumber.core.internal.gherkin.ast.Examples;
4import io.cucumber.core.internal.gherkin.ast.TableRow;
5import net.serenitybdd.cucumber.CucumberWithSerenity;
6
7import java.net.URI;
8import java.util.HashMap;
9import java.util.Map;
10import java.util.Optional;
11import java.util.Set;
12
13public class LineFilters {
14
15    private Map<URI, Set<Integer>> lineFilters;
16
17    public LineFilters() {
18        lineFilters = newLineFilters();
19    }
20
21    public static LineFilters forCurrentContext() {
22        return new LineFilters();
23    }
24
25    public Optional<URI> getURIForFeaturePath(URI featurePath) {
26        return lineFilters.keySet().stream()
27                .filter(uri -> featurePath.equals(uri))
28                .findFirst();
29    }
30
31    private Map<URI, Set<Integer>> newLineFilters() {
32        Map<URI, Set<Integer>> lineFiltersFromRuntime = CucumberWithSerenity.currentRuntimeOptions().getLineFilters();
33        if (lineFiltersFromRuntime == null) {
34            return new HashMap<>();
35        } else {
36            return lineFiltersFromRuntime;
37        }
38    }
39
40    public Set<Integer> getLineNumbersFor(URI featurePath) {
41        return lineFilters.get(featurePath);
42    }
43
44
45    public boolean examplesAreNotExcluded(Examples examples, URI featurePath) {
46        if (lineFilters.isEmpty()) {
47            return true;
48        }
49        if (lineFiltersContainFeaturePath(featurePath)) {
50            Optional<URI> uriForFeaturePath = getURIForFeaturePath(featurePath);
51            return uriForFeaturePath.filter(
52                    uri -> examples.getTableBody().stream()
53                            .anyMatch(
54                                    row -> lineFilters.get(uri).contains(row.getLocation().getLine()))
55            ).isPresent();
56        }
57        return false;
58    }
59
60    public boolean tableRowIsNotExcludedBy(TableRow tableRow, URI featurePath) {
61        if (lineFilters.isEmpty()) {
62            return true;
63        }
64        if (lineFiltersContainFeaturePath(featurePath)) {
65            Optional<URI> uriForFeaturePath = getURIForFeaturePath(featurePath);
66            return uriForFeaturePath.filter(uri -> lineFilters.get(uri).contains(tableRow.getLocation().getLine())).isPresent();
67        }
68        return false;
69    }
70
71    private boolean lineFiltersContainFeaturePath(URI featurePath) {
72        return getURIForFeaturePath(featurePath) != null;
73    }
74}
75
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger tableRowIsNotExcludedBy code on LambdaTest Cloud Grid

Execute automation tests with tableRowIsNotExcludedBy on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)