Search in sources :

Example 26 with CandidateSteps

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

the class SpringStepsFactoryBehaviour method beansWithUndefinedTypeOrCannotBeCreatedWillBeIgnored.

@Test
public void beansWithUndefinedTypeOrCannotBeCreatedWillBeIgnored() {
    // Given
    ApplicationContext context = mock(ApplicationContext.class);
    SpringStepsFactory factory = new SpringStepsFactory(new MostUsefulConfiguration(), context);
    // When
    when(context.getBeanDefinitionNames()).thenReturn(new String[] { "fooSteps", "undefined", "blowUp" });
    doAnswer(new Answer<Class<FooSteps>>() {

        public Class<FooSteps> answer(InvocationOnMock invocation) throws Throwable {
            return FooSteps.class;
        }
    }).when(context).getType("fooSteps");
    when(context.getType("undefined")).thenReturn(null);
    doAnswer(new Answer<Class<BlowUp>>() {

        public Class<BlowUp> answer(InvocationOnMock invocation) throws Throwable {
            return BlowUp.class;
        }
    }).when(context).getType("blowUp");
    when(context.getBean("fooSteps")).thenReturn(new FooSteps());
    when(context.getBean("blowUp")).thenThrow(new RuntimeException("Bum!"));
    List<CandidateSteps> candidateSteps = factory.createCandidateSteps();
    // Then
    assertThat(candidateSteps.size(), equalTo(1));
    assertThat(firstStepsInstance(candidateSteps), instanceOf(FooSteps.class));
    verify(context, never()).getBean("undefined");
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 27 with CandidateSteps

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

the class PicoStepsFactoryBehaviour method assertThatStepsCanBeCreated.

@Test
public void assertThatStepsCanBeCreated() throws NoSuchFieldException, IllegalAccessException {
    // Given
    MutablePicoContainer parent = createPicoContainer();
    parent.as(Characteristics.USE_NAMES).addComponent(FooSteps.class);
    PicoStepsFactory factory = new PicoStepsFactory(new MostUsefulConfiguration(), parent);
    // When
    List<CandidateSteps> steps = factory.createCandidateSteps();
    // Then
    assertFooStepsFound(steps);
}
Also used : MutablePicoContainer(org.picocontainer.MutablePicoContainer) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 28 with CandidateSteps

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

the class NeedleStepsFactoryBehaviour method stepsShouldContainInjectedDependencies.

@Test
public void stepsShouldContainInjectedDependencies() throws NoSuchFieldException, IllegalAccessException {
    // Given
    final InjectableStepsFactory factory = new NeedleStepsFactory(new MostUsefulConfiguration(), FooStepsWithDependency.class);
    // When
    List<CandidateSteps> steps = factory.createCandidateSteps();
    // Then
    assertThat(steps.size(), equalTo(1));
    boolean actual1 = steps.get(0) instanceof CandidateSteps;
    assertThat(actual1, is(true));
    Object instance = stepsInstance(steps.get(0));
    boolean actual = instance instanceof FooStepsWithDependency;
    assertThat(actual, is(true));
    FooStepsWithDependency withDependency = (FooStepsWithDependency) instance;
    assertThat(withDependency.getter, is(notNullValue()));
    assertThat((String) withDependency.getter.getValue(), equalTo(ValueGetter.VALUE));
}
Also used : InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 29 with CandidateSteps

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

the class NeedleStepsFactoryBehaviour method stepsShouldBeCreated.

@Test
public void stepsShouldBeCreated() throws NoSuchFieldException, IllegalAccessException {
    // Given
    final InjectableStepsFactory factory = new NeedleStepsFactory(new MostUsefulConfiguration(), FooSteps.class);
    // When
    List<CandidateSteps> steps = factory.createCandidateSteps();
    // Then
    assertThat(steps.size(), equalTo(1));
    boolean actual1 = steps.get(0) instanceof CandidateSteps;
    assertThat(actual1, is(true));
    Object instance = stepsInstance(steps.get(0));
    boolean actual = instance instanceof FooSteps;
    assertThat(actual, is(true));
}
Also used : InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Aggregations

CandidateSteps (org.jbehave.core.steps.CandidateSteps)29 Test (org.junit.Test)23 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)18 Configuration (org.jbehave.core.configuration.Configuration)6 ApplicationContext (org.springframework.context.ApplicationContext)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStream (java.io.OutputStream)5 PrintStream (java.io.PrintStream)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)5 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)5 Embedder (org.jbehave.core.embedder.Embedder)5 StepFinder (org.jbehave.core.steps.StepFinder)5 PrintStreamStepdocReporter (org.jbehave.core.reporters.PrintStreamStepdocReporter)4 StoryPathResolver (org.jbehave.core.io.StoryPathResolver)3 InjectableStepsFactory (org.jbehave.core.steps.InjectableStepsFactory)3 Steps (org.jbehave.core.steps.Steps)3 AbstractModule (com.google.inject.AbstractModule)2 Injector (com.google.inject.Injector)2 ConfigurableEmbedder (org.jbehave.core.ConfigurableEmbedder)2