Search in sources :

Example 1 with AbstractStepsFactory

use of org.jbehave.core.steps.AbstractStepsFactory in project jbehave-core by jbehave.

the class GuiceStepsFactoryBehaviour method assertThatStepsWithMissingDependenciesCannotBeCreated.

@Test(expected = CreationException.class)
public void assertThatStepsWithMissingDependenciesCannotBeCreated() throws NoSuchFieldException, IllegalAccessException {
    Injector parent = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(FooStepsWithDependency.class);
        }
    });
    AbstractStepsFactory factory = new GuiceStepsFactory(new MostUsefulConfiguration(), parent);
    // When
    factory.createCandidateSteps();
// Then ... expected exception is thrown
}
Also used : Injector(com.google.inject.Injector) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AbstractStepsFactory(org.jbehave.core.steps.AbstractStepsFactory) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 2 with AbstractStepsFactory

use of org.jbehave.core.steps.AbstractStepsFactory in project jbehave-core by jbehave.

the class GuiceStepsFactoryBehaviour method assertThatStepsCanBeCreated.

@Test
public void assertThatStepsCanBeCreated() throws NoSuchFieldException, IllegalAccessException {
    // Given
    Injector parent = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(FooSteps.class).in(Scopes.SINGLETON);
        }
    });
    AbstractStepsFactory factory = new GuiceStepsFactory(new MostUsefulConfiguration(), parent);
    // When
    List<CandidateSteps> steps = factory.createCandidateSteps();
    // Then
    assertFooStepsFound(steps);
}
Also used : Injector(com.google.inject.Injector) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AbstractStepsFactory(org.jbehave.core.steps.AbstractStepsFactory) CandidateSteps(org.jbehave.core.steps.CandidateSteps) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 3 with AbstractStepsFactory

use of org.jbehave.core.steps.AbstractStepsFactory in project jbehave-core by jbehave.

the class GuiceStepsFactoryBehaviour method assertThatStepsWithStepsWithDependencyCanBeCreated.

@Test
public void assertThatStepsWithStepsWithDependencyCanBeCreated() throws NoSuchFieldException, IllegalAccessException {
    Injector parent = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Integer.class).toInstance(42);
            bind(FooStepsWithDependency.class).in(Scopes.SINGLETON);
        }
    });
    // When
    AbstractStepsFactory factory = new GuiceStepsFactory(new MostUsefulConfiguration(), parent);
    List<CandidateSteps> steps = factory.createCandidateSteps();
    // Then
    assertFooStepsFound(steps);
    assertThat((int) ((FooStepsWithDependency) stepsInstance(steps.get(0))).integer, equalTo(42));
}
Also used : Injector(com.google.inject.Injector) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) AbstractStepsFactory(org.jbehave.core.steps.AbstractStepsFactory) CandidateSteps(org.jbehave.core.steps.CandidateSteps) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Aggregations

AbstractModule (com.google.inject.AbstractModule)3 Injector (com.google.inject.Injector)3 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)3 AbstractStepsFactory (org.jbehave.core.steps.AbstractStepsFactory)3 Test (org.junit.Test)3 CandidateSteps (org.jbehave.core.steps.CandidateSteps)2