Search in sources :

Example 1 with DefaultObjectFactory

use of io.cucumber.core.backend.DefaultObjectFactory in project cucumber-jvm by cucumber.

the class ObjectFactoryServiceLoader method loadSingleObjectFactoryOrDefault.

private static ObjectFactory loadSingleObjectFactoryOrDefault(ServiceLoader<ObjectFactory> loader) {
    Iterator<ObjectFactory> objectFactories = loader.iterator();
    // Find the first non-default object factory,
    // or the default as a side effect.
    ObjectFactory objectFactory = null;
    while (objectFactories.hasNext()) {
        objectFactory = objectFactories.next();
        if (!(objectFactory instanceof DefaultObjectFactory)) {
            break;
        }
    }
    if (objectFactory == null) {
        throw new CucumberException("" + "Could not find any object factory.\n" + "\n" + "Cucumber uses SPI to discover object factory implementations.\n" + "This typically happens when using shaded jars. Make sure\n" + "to merge all SPI definitions in META-INF/services correctly");
    }
    // Check if there are no other non-default object factories
    while (objectFactories.hasNext()) {
        ObjectFactory extraObjectFactory = objectFactories.next();
        if (extraObjectFactory instanceof DefaultObjectFactory) {
            continue;
        }
        throw new CucumberException(getMultipleObjectFactoryLogMessage(objectFactory, extraObjectFactory));
    }
    return objectFactory;
}
Also used : DefaultObjectFactory(io.cucumber.core.backend.DefaultObjectFactory) ObjectFactory(io.cucumber.core.backend.ObjectFactory) DefaultObjectFactory(io.cucumber.core.backend.DefaultObjectFactory) CucumberException(io.cucumber.core.exception.CucumberException)

Aggregations

DefaultObjectFactory (io.cucumber.core.backend.DefaultObjectFactory)1 ObjectFactory (io.cucumber.core.backend.ObjectFactory)1 CucumberException (io.cucumber.core.exception.CucumberException)1