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

Classes in this File | Line Coverage | Branch Coverage | Complexity
InstanceStepsFactory |
91% | 11/12
75% | 3/4
| 1.75;1.75

1 |  |
     package org.jbehave.core.steps;
2 |  |
3 |  |
     import java.util.ArrayList;
4 |  |
     import java.util.LinkedHashMap;
5 |  |
     import java.util.List;
6 |  |
     import java.util.Map;
7 |  |
8 |  |
     import org.jbehave.core.configuration.Configuration;
9 |  |
10 |  |
     import static java.util.Arrays.asList;
11 |  |
12 |  |
     /**
13 |  |
      * An {@link InjectableStepsFactory} that is provided Object instances.
14 |  |
      */
15 |  |
     public class InstanceStepsFactory extends AbstractStepsFactory {
16 |  |
17 | 190 |
         private final Map<Class<?>,Object> stepsInstances = new LinkedHashMap<Class<?>, Object>();
18 |  |
19 |  |
         public InstanceStepsFactory(Configuration configuration, Object... stepsInstances) {
20 | 180 |
             this(configuration, asList(stepsInstances));
21 | 180 |
         }
22 |  |
23 |  |
         public InstanceStepsFactory(Configuration configuration, List<Object> stepsInstances) {
24 | 190 |
             super(configuration);
25 | 190 |
             for (Object instance : stepsInstances) {
26 | 187 |
                 this.stepsInstances.put(instance.getClass(), instance);
27 |  |
             }
28 | 190 |
         }
29 |  |
30 |  |
         @Override
31 |  |
         protected List<Class<?>> stepsTypes() {
32 | 16 |
             return new ArrayList<Class<?>>(stepsInstances.keySet());
33 |  |
         }
34 |  |
35 |  |
         public Object createInstanceOfType(Class<?> type) {
36 | 152 |
             Object instance = stepsInstances.get(type);
37 | 152 |
             if ( instance == null ){
38 | 0 |
                 throw new StepsInstanceNotFound(type, this);
39 |  |
             }
40 | 152 |
             return instance;
41 |  |
         }
42 |  |
43 |  |
     }