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

cucumber.runtime.ScenarioImpl Maven / Gradle / Ivy

package cucumber.runtime;

import cucumber.api.Scenario;
import gherkin.formatter.Reporter;
import gherkin.formatter.model.Result;
import gherkin.formatter.model.Tag;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static java.util.Arrays.asList;

public class ScenarioImpl implements Scenario {
    private static final List SEVERITY = asList("passed", "skipped", "undefined", "pending", "failed");
    private final List stepResults = new ArrayList();
    private final Reporter reporter;
    private final Set tags;

    public ScenarioImpl(Reporter reporter, Set tags) {
        this.reporter = reporter;
        this.tags = tags;
    }

    void add(Result result) {
        stepResults.add(result);
    }

    @Override
    public Collection getSourceTagNames() {
        Set result = new HashSet();
        for (Tag tag : tags) {
            result.add(tag.getName());
        }
        // Has to be a List in order for JRuby to convert to Ruby Array.
        return new ArrayList(result);
    }

    @Override
    public String getStatus() {
        int pos = 0;
        for (Result stepResult : stepResults) {
            pos = Math.max(pos, SEVERITY.indexOf(stepResult.getStatus()));
        }
        return SEVERITY.get(pos);
    }

    @Override
    public boolean isFailed() {
        return "failed".equals(getStatus());
    }

    @Override
    public void embed(byte[] data, String mimeType) {
        reporter.embedding(mimeType, data);
    }

    @Override
    public void write(String text) {
        reporter.write(text);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy