}
@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));