Search in sources :

Example 1 with Options

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

the class ObjectFactoryServiceLoaderTest method shouldThrowIfDefaultObjectFactoryServiceCouldNotBeLoaded.

@Test
void shouldThrowIfDefaultObjectFactoryServiceCouldNotBeLoaded() {
    Options options = () -> null;
    Supplier<ClassLoader> classLoader = () -> new FilteredClassLoader("META-INF/services/io.cucumber.core.backend.ObjectFactory");
    ObjectFactoryServiceLoader loader = new ObjectFactoryServiceLoader(classLoader, options);
    CucumberException exception = assertThrows(CucumberException.class, loader::loadObjectFactory);
    assertThat(exception.getMessage(), is("" + "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"));
}
Also used : Options(io.cucumber.core.backend.Options) URLClassLoader(java.net.URLClassLoader) CucumberException(io.cucumber.core.exception.CucumberException) Test(org.junit.jupiter.api.Test)

Example 2 with Options

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

the class ObjectFactoryServiceLoaderTest method shouldThrowIfSelectedObjectFactoryServiceCouldNotBeLoaded.

@Test
void shouldThrowIfSelectedObjectFactoryServiceCouldNotBeLoaded() {
    Options options = () -> NoSuchObjectFactory.class;
    Supplier<ClassLoader> classLoader = () -> new FilteredClassLoader("META-INF/services/io.cucumber.core.backend.ObjectFactory");
    ObjectFactoryServiceLoader loader = new ObjectFactoryServiceLoader(classLoader, options);
    CucumberException exception = assertThrows(CucumberException.class, loader::loadObjectFactory);
    assertThat(exception.getMessage(), is("" + "Could not find object factory io.cucumber.core.runtime.ObjectFactoryServiceLoaderTest$NoSuchObjectFactory.\n" + "\n" + "Cucumber uses SPI to discover object factory implementations.\n" + "Has the class been registered with SPI and is it available on\n" + "the classpath?"));
}
Also used : Options(io.cucumber.core.backend.Options) URLClassLoader(java.net.URLClassLoader) CucumberException(io.cucumber.core.exception.CucumberException) Test(org.junit.jupiter.api.Test)

Example 3 with Options

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

the class ObjectFactoryServiceLoaderTest method shouldLoadDefaultObjectFactoryService.

@Test
void shouldLoadDefaultObjectFactoryService() {
    Options options = () -> null;
    ObjectFactoryServiceLoader loader = new ObjectFactoryServiceLoader(ObjectFactoryServiceLoaderTest.class::getClassLoader, options);
    assertThat(loader.loadObjectFactory(), instanceOf(DefaultObjectFactory.class));
}
Also used : Options(io.cucumber.core.backend.Options) DefaultObjectFactory(io.cucumber.core.backend.DefaultObjectFactory) Test(org.junit.jupiter.api.Test)

Example 4 with Options

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

the class ObjectFactoryServiceLoaderTest method shouldLoadSelectedObjectFactoryService.

@Test
void shouldLoadSelectedObjectFactoryService() {
    Options options = () -> DefaultObjectFactory.class;
    ObjectFactoryServiceLoader loader = new ObjectFactoryServiceLoader(ObjectFactoryServiceLoaderTest.class::getClassLoader, options);
    assertThat(loader.loadObjectFactory(), instanceOf(DefaultObjectFactory.class));
}
Also used : Options(io.cucumber.core.backend.Options) DefaultObjectFactory(io.cucumber.core.backend.DefaultObjectFactory) Test(org.junit.jupiter.api.Test)

Aggregations

Options (io.cucumber.core.backend.Options)4 Test (org.junit.jupiter.api.Test)4 DefaultObjectFactory (io.cucumber.core.backend.DefaultObjectFactory)2 CucumberException (io.cucumber.core.exception.CucumberException)2 URLClassLoader (java.net.URLClassLoader)2