How to use omitEmptyStrings method of net.serenitybdd.cucumber.util.Splitter class

Best Serenity Cucumber code snippet using net.serenitybdd.cucumber.util.Splitter.omitEmptyStrings

Run Serenity Cucumber automation tests on LambdaTest cloud grid

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

copy
1package net.serenitybdd.cucumber.util;
2
3import org.apache.commons.lang3.StringUtils;
4
5import java.util.Arrays;
6import java.util.List;
7import java.util.stream.Collectors;
8
9public class Splitter {
10    private String separator;
11    private boolean omitEmptyStrings = false;
12    private boolean trimResults = false;
13    private String trimmable = null;
14
15    public Splitter(String separator) {
16        this.separator = separator;
17    }
18
19    public static Splitter on(String separator) {
20        return new Splitter(separator);
21    }
22
23    public Splitter omitEmptyStrings() {
24        omitEmptyStrings = true;
25        return this;
26    }
27
28    public Splitter trimResults() {
29        this.trimResults = true;
30        return this;
31    }
32
33    public Splitter trimResults(String trimmable) {
34        this.trimResults = true;
35        this.trimmable = trimmable;
36        return this;
37    }
38
39    public List<String> splitToList(String value) {
40        String[] separatedElements = StringUtils.split(value, separator);
41        List<String> result = Arrays.asList(separatedElements);
42
43        if (omitEmptyStrings) {
44            result = result.stream()
45                    .filter(element -> !element.trim().equals(""))
46                    .collect(Collectors.toList());
47        }
48
49        if (trimResults) {
50            result = result.stream()
51                    .map(v -> StringUtils.strip(v, trimmable))
52                    .collect(Collectors.toList());
53        }
54
55        return result;
56    }
57
58    public static Splitter on(char separator) {
59        return on(Character.toString(separator));
60    }
61
62}
63
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

Most used method in Splitter

Trigger omitEmptyStrings code on LambdaTest Cloud Grid

Execute automation tests with omitEmptyStrings 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)