1 | |
|
2 | |
|
3 | |
|
4 | |
package org.jbehave.core.steps.weld; |
5 | |
|
6 | |
import java.util.ArrayList; |
7 | |
import java.util.List; |
8 | |
|
9 | |
import javax.enterprise.inject.Any; |
10 | |
import javax.enterprise.inject.Instance; |
11 | |
import javax.inject.Inject; |
12 | |
import javax.inject.Singleton; |
13 | |
|
14 | |
import org.jbehave.core.annotations.weld.WeldConfiguration; |
15 | |
import org.jbehave.core.annotations.weld.WeldStep; |
16 | |
import org.jbehave.core.configuration.Configuration; |
17 | |
import org.jbehave.core.steps.AbstractStepsFactory; |
18 | |
import org.jbehave.core.steps.InjectableStepsFactory; |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
@Singleton |
28 | |
public class WeldStepsFactory extends AbstractStepsFactory { |
29 | |
|
30 | |
@Inject |
31 | |
@Any |
32 | |
@WeldStep |
33 | |
private Instance<Object> instances; |
34 | |
|
35 | |
@Inject |
36 | |
public WeldStepsFactory(@WeldConfiguration Configuration configuration) { |
37 | 8 | super(configuration); |
38 | 8 | } |
39 | |
|
40 | |
@Override |
41 | |
protected List<Class<?>> stepsTypes() { |
42 | 3 | List<Class<?>> types = new ArrayList<Class<?>>(); |
43 | 3 | for (Object o : instances) { |
44 | 3 | types.add(o.getClass()); |
45 | |
} |
46 | 3 | return types; |
47 | |
} |
48 | |
|
49 | |
public Object createInstanceOfType(Class<?> type) { |
50 | 3 | for (Object o : instances) { |
51 | 3 | if ( type.equals(o.getClass())){ |
52 | 3 | return o; |
53 | |
} |
54 | |
} |
55 | 0 | throw new StepsInstanceNotFound(type, this); |
56 | |
} |
57 | |
|
58 | |
} |