use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.
the class SpringFactoryTest method shouldRespectCustomPropertyPlaceholderConfigurer.
@Test
void shouldRespectCustomPropertyPlaceholderConfigurer() {
final ObjectFactory factory = new SpringFactory();
factory.addClass(WithSpringAnnotations.class);
factory.start();
WithSpringAnnotations stepdef = factory.getInstance(WithSpringAnnotations.class);
factory.stop();
assertThat(stepdef.getProperty(), is(equalTo("property value")));
}
use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.
the class SpringFactoryTest method shouldBeStoppableWhenFacedWithInvalidConfiguration.
@Test
void shouldBeStoppableWhenFacedWithInvalidConfiguration() {
final ObjectFactory factory = new SpringFactory();
factory.addClass(WithEmptySpringAnnotations.class);
IllegalStateException exception = assertThrows(IllegalStateException.class, factory::start);
assertThat(exception.getMessage(), containsString("DelegatingSmartContextLoader was unable to detect defaults"));
assertDoesNotThrow(factory::stop);
}
use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.
the class SpringFactoryTest method shouldRespectDirtiesContextAnnotationsInStepDefsUsingMetaConfiguration.
@Test
void shouldRespectDirtiesContextAnnotationsInStepDefsUsingMetaConfiguration() {
final ObjectFactory factory = new SpringFactory();
factory.addClass(DirtiesContextBellyMetaStepDefinitions.class);
// Scenario 1
factory.start();
final BellyBean o1 = factory.getInstance(DirtiesContextBellyMetaStepDefinitions.class).getBellyBean();
factory.stop();
// Scenario 2
factory.start();
final BellyBean o2 = factory.getInstance(DirtiesContextBellyMetaStepDefinitions.class).getBellyBean();
factory.stop();
assertAll(() -> assertThat(o1, is(notNullValue())), () -> assertThat(o2, is(notNullValue())), () -> assertThat(o1, is(not(equalTo(o2)))), () -> assertThat(o2, is(not(equalTo(o1)))));
}
use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.
the class OpenEJBObjectFactoryTest method shouldGiveUsNewInstancesForEachScenario.
@Test
void shouldGiveUsNewInstancesForEachScenario() {
ObjectFactory factory = new OpenEJBObjectFactory();
factory.addClass(BellyStepDefinitions.class);
// Scenario 1
factory.start();
BellyStepDefinitions o1 = factory.getInstance(BellyStepDefinitions.class);
factory.stop();
// Scenario 2
factory.start();
BellyStepDefinitions o2 = factory.getInstance(BellyStepDefinitions.class);
factory.stop();
assertThat(o1, is(notNullValue()));
assertThat(o1, is(not(equalTo(o2))));
assertThat(o2, is(not(equalTo(o1))));
}
use of io.cucumber.core.backend.ObjectFactory 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;
}
Aggregations