use of cucumber.api.java.ObjectFactory in project cucumber-jvm by cucumber.
the class CucumberExecutor method createBackends.
private Collection<? extends Backend> createBackends() {
final ObjectFactory delegateObjectFactory = ObjectFactoryLoader.loadObjectFactory(classFinder, Env.INSTANCE.get(ObjectFactory.class.getName()));
final AndroidObjectFactory objectFactory = new AndroidObjectFactory(delegateObjectFactory, instrumentation);
final List<Backend> backends = new ArrayList<Backend>();
backends.add(new JavaBackend(objectFactory, classFinder));
return backends;
}
use of cucumber.api.java.ObjectFactory in project cucumber-jvm by cucumber.
the class WeldFactoryTest method shouldGiveUsNewInstancesForEachScenario.
@Test
public void shouldGiveUsNewInstancesForEachScenario() {
ObjectFactory factory = new WeldFactory();
factory.addClass(BellyStepdefs.class);
// Scenario 1
factory.start();
BellyStepdefs o1 = factory.getInstance(BellyStepdefs.class);
factory.stop();
// Scenario 2
factory.start();
BellyStepdefs o2 = factory.getInstance(BellyStepdefs.class);
factory.stop();
assertNotNull(o1);
assertNotSame(o1, o2);
}
use of cucumber.api.java.ObjectFactory in project cucumber-jvm by cucumber.
the class CalculatorTest method cucumber.
@Test
public void cucumber() throws Exception {
assertNotNull(injector);
assertNotNull(bundleContext);
final ResourceLoader resourceLoader = new FileResourceLoader();
final ClassLoader classLoader = Runtime.class.getClassLoader();
final ObjectFactory objectFactory = new PaxExamObjectFactory(injector);
final ClassFinder classFinder = new OsgiClassFinder(bundleContext);
final Backend backend = new JavaBackend(objectFactory, classFinder);
final RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(getClass());
final RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
final Runtime runtime = new Runtime(resourceLoader, classLoader, Collections.singleton(backend), runtimeOptions);
runtime.run();
if (!runtime.getErrors().isEmpty()) {
throw new CucumberException(runtime.getErrors().get(0));
} else if (runtime.exitStatus() != 0x00) {
throw new CucumberException("There are pending or undefined steps.");
}
assertEquals(runtime.getErrors().size(), 0);
}
use of cucumber.api.java.ObjectFactory in project cucumber-jvm by cucumber.
the class ObjectFactoryLoader method loadObjectFactory.
/**
* Loads an instance of {@link ObjectFactory}. The class name can be explicit, or it can be null.
* When it's null, the implementation is searched for in the <pre>cucumber.runtime</pre> packahe.
*
* @param classFinder where to load classes from
* @param objectFactoryClassName specific class name of {@link ObjectFactory} implementation. May be null.
* @return an instance of {@link ObjectFactory}
*/
public static ObjectFactory loadObjectFactory(ClassFinder classFinder, String objectFactoryClassName) {
ObjectFactory objectFactory;
try {
Reflections reflections = new Reflections(classFinder);
if (objectFactoryClassName != null) {
Class<ObjectFactory> objectFactoryClass = (Class<ObjectFactory>) classFinder.loadClass(objectFactoryClassName);
objectFactory = reflections.newInstance(new Class[0], new Object[0], objectFactoryClass);
} else {
objectFactory = reflections.instantiateExactlyOneSubclass(ObjectFactory.class, "cucumber.runtime", new Class[0], new Object[0]);
}
} catch (TooManyInstancesException e) {
System.out.println(e.getMessage());
System.out.println(getMultipleObjectFactoryLogMessage());
objectFactory = new DefaultJavaObjectFactory();
} catch (NoInstancesException e) {
objectFactory = new DefaultJavaObjectFactory();
} catch (ClassNotFoundException e) {
throw new CucumberException("Couldn't instantiate custom ObjectFactory", e);
}
return objectFactory;
}
use of cucumber.api.java.ObjectFactory in project cucumber-jvm by cucumber.
the class SpringFactoryTest method shouldGiveUsNewStepInstancesForEachScenario.
@Test
public void shouldGiveUsNewStepInstancesForEachScenario() {
final ObjectFactory factory = new SpringFactory();
factory.addClass(BellyStepdefs.class);
// Scenario 1
factory.start();
final BellyStepdefs o1 = factory.getInstance(BellyStepdefs.class);
factory.stop();
// Scenario 2
factory.start();
final BellyStepdefs o2 = factory.getInstance(BellyStepdefs.class);
factory.stop();
assertNotNull(o1);
assertNotNull(o2);
assertNotSame(o1, o2);
}
Aggregations