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

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

package io.cucumber.testng;

import io.cucumber.core.runtime.TestCaseResultObserver.Suggestion;
import org.testng.SkipException;

import java.util.Collection;
import java.util.stream.Collectors;

final class UndefinedStepException extends SkipException {

    private static final long serialVersionUID = 1L;

    UndefinedStepException(Collection suggestions) {
        super(createMessage(suggestions));
    }

    private static String createMessage(Collection suggestions) {
        if (suggestions.isEmpty()) {
            return "This step is undefined";
        }
        Suggestion first = suggestions.iterator().next();
        StringBuilder sb = new StringBuilder("The step '" + first.getStep() + "'");
        if (suggestions.size() == 1) {
            sb.append(" is undefined.");
        } else {
            sb.append(" and ").append(suggestions.size() - 1).append(" other step(s) are undefined.");
        }
        sb.append("\n");
        if (suggestions.size() == 1) {
            sb.append("You can implement this step using the snippet(s) below:\n\n");
        } else {
            sb.append("You can implement these steps using the snippet(s) below:\n\n");
        }
        String snippets = suggestions
                .stream()
                .map(Suggestion::getSnippets)
                .flatMap(Collection::stream)
                .distinct()
                .collect(Collectors.joining("\n", "", "\n"));
        sb.append(snippets);
        return sb.toString();
    }

    @Override
    public boolean isSkip() {
        return false;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy