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

io.cucumber.testng.UndefinedStepException Maven / Gradle / Ivy

There is a newer version: 5.0.5-RC3
Show newest version
package io.cucumber.testng;

import org.testng.SkipException;

import java.util.Collection;
import java.util.List;

final class UndefinedStepException extends SkipException {
    private static final long serialVersionUID = 1L;
    private final boolean strict;

    UndefinedStepException(String stepText, List snippets, Collection> otherSnippets, boolean strict) {
        super(createMessage(stepText, snippets, otherSnippets));
        this.strict = strict;
    }

    private static String createMessage(String stepText, List snippets, Collection> otherSnippets) {
        StringBuilder sb = new StringBuilder("The step \"" + stepText + "\" is undefined");
        appendSnippets(snippets, sb);
        appendOtherSnippets(otherSnippets, sb);
        return sb.toString();
    }

    private static void appendOtherSnippets(Collection> otherSnippets, StringBuilder sb) {
        if (otherSnippets.isEmpty()) {
            return;
        }

        sb.append("\n");
        sb.append("\n");
        sb.append("Some other steps were also undefined:\n\n");
        otherSnippets.forEach(snippet -> {
            sb.append(String.join("\n", snippet));
            sb.append("\n");
        });
    }

    private static void appendSnippets(List snippets, StringBuilder sb) {
        if (snippets.isEmpty()) {
            return;
        }
        sb.append(". You can implement it using tne snippet(s) below:\n\n");
        sb.append(String.join("\n", snippets));
    }

    @Override
    public boolean isSkip() {
        return !strict;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy