##### Coverage Report - org.jbehave.core.steps.CompositeStepsFactory

Classes in this File | Line Coverage | Branch Coverage | Complexity
CompositeStepsFactory |
0% | 0/15
0% | 0/6
| 2.6666666666666665;2.667

1 |  |
     package org.jbehave.core.steps;
2 |  |
3 |  |
     import java.util.ArrayList;
4 |  |
     import java.util.List;
5 |  |
6 |  |
     import org.jbehave.core.steps.AbstractStepsFactory.StepsInstanceNotFound;
7 |  |
8 |  |
     /**
9 |  |
      * An {@link InjectableStepsFactory} that composes {@link CandidateSteps}
10 |  |
      * created from other factories.
11 |  |
      */
12 |  |
     public class CompositeStepsFactory implements InjectableStepsFactory {
13 |  |
14 |  |
         private final InjectableStepsFactory[] stepsFactories;
15 |  |
16 | 0 |
         public CompositeStepsFactory(InjectableStepsFactory... stepsFactories) {
17 | 0 |
             this.stepsFactories = stepsFactories;
18 | 0 |
         }
19 |  |
20 |  |
         public List<CandidateSteps> createCandidateSteps() {
21 | 0 |
             List<CandidateSteps> steps = new ArrayList<CandidateSteps>();
22 | 0 |
             for (InjectableStepsFactory factory : stepsFactories) {
23 | 0 |
                 steps.addAll(factory.createCandidateSteps());
24 |  |
             }
25 | 0 |
             return steps;
26 |  |
         }
27 |  |
28 |  |
         public Object createInstanceOfType(Class<?> type) {
29 | 0 |
             Object instance = null;
30 | 0 |
             for (InjectableStepsFactory factory : stepsFactories) {
31 |  |
                 try {
32 | 0 |
                     instance = factory.createInstanceOfType(type);
33 | 0 |
                 } catch (RuntimeException e) {
34 |  |
                     // creation failed on given factory, carry on
35 | 0 |
                 }
36 |  |
             }
37 | 0 |
             if ( instance == null ){
38 | 0 |
                 throw new StepsInstanceNotFound(type, this);
39 |  |
             }
40 | 0 |
             return instance;
41 |  |
         }
42 |  |
43 |  |
     }