1 | |
package org.jbehave.core.steps.spring; |
2 | |
|
3 | |
import java.lang.reflect.Modifier; |
4 | |
import java.util.ArrayList; |
5 | |
import java.util.List; |
6 | |
|
7 | |
import org.jbehave.core.configuration.Configuration; |
8 | |
import org.jbehave.core.steps.AbstractStepsFactory; |
9 | |
import org.jbehave.core.steps.InjectableStepsFactory; |
10 | |
import org.springframework.beans.BeansException; |
11 | |
import org.springframework.context.ApplicationContext; |
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
public class SpringStepsFactory extends AbstractStepsFactory { |
22 | |
|
23 | |
private final ApplicationContext context; |
24 | |
|
25 | |
public SpringStepsFactory(Configuration configuration, ApplicationContext context) { |
26 | 6 | super(configuration); |
27 | 6 | this.context = context; |
28 | 6 | } |
29 | |
|
30 | |
@Override |
31 | |
protected List<Object> stepsInstances() { |
32 | 6 | List<Object> steps = new ArrayList<Object>(); |
33 | 33 | for (String name : context.getBeanDefinitionNames()) { |
34 | 27 | Class<?> type = context.getType(name); |
35 | 27 | if ( isAllowed(type) && hasAnnotatedMethods(type)) { |
36 | |
try { |
37 | 5 | steps.add(context.getBean(name)); |
38 | 0 | } catch ( BeansException e ){ |
39 | |
|
40 | |
|
41 | 5 | } |
42 | |
} |
43 | |
} |
44 | 6 | return steps; |
45 | |
} |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
protected boolean isAllowed(Class<?> type) { |
55 | 27 | return type != null && !Modifier.isAbstract(type.getModifiers()); |
56 | |
} |
57 | |
|
58 | |
} |