1 | |
package org.jbehave.core.steps; |
2 | |
|
3 | |
import java.util.List; |
4 | |
|
5 | |
import org.jbehave.core.steps.AbstractStepsFactory.StepsInstanceNotFound; |
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
public class ProvidedStepsFactory implements InjectableStepsFactory { |
12 | |
|
13 | |
private final List<CandidateSteps> candidateSteps; |
14 | |
|
15 | 30 | public ProvidedStepsFactory(List<CandidateSteps> candidateSteps) { |
16 | 30 | this.candidateSteps = candidateSteps; |
17 | 30 | } |
18 | |
|
19 | |
public List<CandidateSteps> createCandidateSteps() { |
20 | 29 | return candidateSteps; |
21 | |
} |
22 | |
|
23 | |
public Object createInstanceOfType(Class<?> type) { |
24 | 0 | Object instance = null; |
25 | 0 | for (CandidateSteps steps : candidateSteps) { |
26 | |
try { |
27 | 0 | if (type.equals(((Steps) steps).type())) { |
28 | 0 | instance = ((Steps) steps).instance(); |
29 | |
} |
30 | 0 | } catch (RuntimeException e) { |
31 | |
|
32 | 0 | } |
33 | |
} |
34 | 0 | if (instance == null) { |
35 | 0 | throw new StepsInstanceNotFound(type, this); |
36 | |
} |
37 | 0 | return instance; |
38 | |
} |
39 | |
|
40 | |
} |