All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pdsl.gherkin.models.GherkinExamplesTable Maven / Gradle / Ivy

Go to download

The Polymorphic DSL test framework was designed to solve the challenges with testing large, complex systems. Modern architecture requires software to run as distrubited systems or on multiple platforms. The conventional cost of testing these systems is quite high. PDSL allows a user to describe the system under test using a DSL of some kind: a picture, sentences in natural languages, graphs, etc. Using a common DSL allows someone to make deeply scalable tests. A simple change to the DSL could generate dozens of tests providing coverage through many layers of the test pyramid or even multiple applications.

The newest version!
package com.pdsl.gherkin.models;

import java.util.*;

/**
 * A DTO representing a table in a gherkin scenario.
 */
public class GherkinExamplesTable {
    private final Optional> tags;
    private final Optional title;
    private final Optional longDescription;
    private final Optional>> table;

    private GherkinExamplesTable(Builder builder) {
        this.title = builder.title.isEmpty() ? Optional.empty() : Optional.of(builder.title);
        this.longDescription = builder.longDescription.isEmpty() ? Optional.empty()
                : Optional.of(builder.longDescription);
        this.tags = builder.tags.isEmpty() ? Optional.empty() : Optional.of(builder.tags);
        this.table = builder.table;
    }

    public Optional> getTags() {
        return tags;
    }

    public Optional getTitle() {
        return title;
    }

    public Optional getLongDescription() {
        return longDescription;
    }

    public Optional>> getTable() {
        return table;
    }

    public List> getRows() {
        if (table.isEmpty()) {
            return new ArrayList<>();
        }
        Map> tableData = table.get();
        final int TOTAL_ROWS = tableData.get(new ArrayList<>(tableData.keySet()).get(0)).size();
        List> rows = new ArrayList<>(TOTAL_ROWS);
        for (int i = 0; i < TOTAL_ROWS; i++) {
            Map rowSubstitutions = new HashMap<>();
            for (Map.Entry> entry : tableData.entrySet()) {
                rowSubstitutions.put(entry.getKey(), tableData.get(entry.getKey()).get(i));
            }
            rows.add(rowSubstitutions);
        }
        return rows;
    }

    /**
     * A builder for creating an Examples table DTO.
     */
    public static class Builder {
        private String title = "";
        private String longDescription = "";
        private List tags = new ArrayList<>();
        private Optional>> table = Optional.empty();

        public GherkinExamplesTable build() {
            return new GherkinExamplesTable(this);
        }

        public Builder withTable(Map> table) {
            this.table = table == null ? Optional.empty() : Optional.of(table);
            return this;
        }

        public Builder withTags(List tags) {
            this.tags = tags;
            return this;
        }

        public Builder withTitle(String title) {
            this.title = title;
            return this;
        }

        public Builder withLongDescription(String longDescription) {
            this.longDescription = longDescription;
            return this;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy