Search in sources :

Example 31 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class ClasspathResourceIterable method iterator.

@Override
public Iterator<Resource> iterator() {
    try {
        FlatteningIterator<Resource> iterator = new FlatteningIterator<Resource>();
        Enumeration<URL> resources = classLoader.getResources(path);
        while (resources.hasMoreElements()) {
            URL url = resources.nextElement();
            Iterator<Resource> resourceIterator = resourceIteratorFactory.createIterator(url, path, suffix);
            iterator.push(resourceIterator);
        }
        return iterator;
    } catch (IOException e) {
        throw new CucumberException(e);
    }
}
Also used : IOException(java.io.IOException) CucumberException(cucumber.runtime.CucumberException) URL(java.net.URL)

Example 32 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class OpenEJBObjectFactory method getInstance.

@Override
public <T> T getInstance(Class<T> type) {
    if (instances.containsKey(type)) {
        return type.cast(instances.get(type));
    }
    T object;
    try {
        object = type.newInstance();
        container.getContext().bind("inject", object);
    } catch (Exception e) {
        throw new CucumberException("can't create " + type.getName(), e);
    }
    instances.put(type, object);
    return object;
}
Also used : CucumberException(cucumber.runtime.CucumberException) CucumberException(cucumber.runtime.CucumberException)

Example 33 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class JUnitReporter method fetchAndCheckRunnerStep.

private Step fetchAndCheckRunnerStep() {
    Step scenarioStep = steps.remove(0);
    Step runnerStep = executionUnitRunner.getRunnerSteps().remove(0);
    if (!scenarioStep.getName().equals(runnerStep.getName())) {
        throw new CucumberException("Expected step: \"" + scenarioStep.getName() + "\" got step: \"" + runnerStep.getName() + "\"");
    }
    return runnerStep;
}
Also used : Step(gherkin.formatter.model.Step) CucumberException(cucumber.runtime.CucumberException)

Example 34 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class DefaultJavaObjectFactory method cacheNewInstance.

private <T> T cacheNewInstance(Class<T> type) {
    try {
        Constructor<T> constructor = type.getConstructor();
        T instance = constructor.newInstance();
        instances.put(type, instance);
        return instance;
    } catch (NoSuchMethodException e) {
        throw new CucumberException(String.format("%s doesn't have an empty constructor. If you need DI, put cucumber-picocontainer on the classpath", type), e);
    } catch (Exception e) {
        throw new CucumberException(String.format("Failed to instantiate %s", type), e);
    }
}
Also used : CucumberException(cucumber.runtime.CucumberException) CucumberException(cucumber.runtime.CucumberException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 35 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class GroovyBackend method loadGlue.

@Override
public void loadGlue(Glue glue, List<String> gluePaths) {
    this.glue = glue;
    final Binding context = shell.getContext();
    for (String gluePath : gluePaths) {
        // Load sources
        for (Resource resource : resourceLoader.resources(gluePath, ".groovy")) {
            Script script = parse(resource);
            runIfScript(context, script);
        }
        // Load compiled scripts
        for (Class<? extends Script> glueClass : classFinder.getDescendants(Script.class, packageName(gluePath))) {
            try {
                Script script = glueClass.getConstructor(Binding.class).newInstance(context);
                runIfScript(context, script);
            } catch (Exception e) {
                throw new CucumberException(e);
            }
        }
    }
}
Also used : Binding(groovy.lang.Binding) Script(groovy.lang.Script) Resource(cucumber.runtime.io.Resource) CucumberException(cucumber.runtime.CucumberException) InvokerInvocationException(org.codehaus.groovy.runtime.InvokerInvocationException) CucumberException(cucumber.runtime.CucumberException) IOException(java.io.IOException)

Aggregations

CucumberException (cucumber.runtime.CucumberException)37 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 SingleValueConverter (cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverter)4 IOException (java.io.IOException)4 Step (gherkin.formatter.model.Step)3 ObjectFactory (cucumber.api.java.ObjectFactory)2 StepdefBody (cucumber.api.java8.StepdefBody)2 RuntimeOptionsFactory (cucumber.runtime.RuntimeOptionsFactory)2 Resource (cucumber.runtime.io.Resource)2 Java8StepDefinition (cucumber.runtime.java.Java8StepDefinition)2 AssetManager (android.content.res.AssetManager)1 DataTable (cucumber.api.DataTable)1 PendingException (cucumber.api.PendingException)1 Scenario (cucumber.api.Scenario)1 After (cucumber.api.java.After)1 Cucumber (cucumber.api.junit.Cucumber)1 OsgiClassFinder (cucumber.java.runtime.osgi.OsgiClassFinder)1 PaxExamObjectFactory (cucumber.java.runtime.osgi.PaxExamObjectFactory)1 Backend (cucumber.runtime.Backend)1