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  
 package org.jbehave.core.steps;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.HashMap;
 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  167
     private final Map<Class<?>,Object> stepsInstances = new HashMap<Class<?>, Object>();
 18  
 
 19  
     public InstanceStepsFactory(Configuration configuration, Object... stepsInstances) {
 20  157
         this(configuration, asList(stepsInstances));
 21  157
     }
 22  
 
 23  
     public InstanceStepsFactory(Configuration configuration, List<Object> stepsInstances) {
 24  167
         super(configuration);
 25  167
         for (Object instance : stepsInstances) {
 26  164
             this.stepsInstances.put(instance.getClass(), instance);
 27  
         }
 28  167
     }
 29  
 
 30  
     @Override
 31  
     protected List<Class<?>> stepsTypes() {
 32  14
         return new ArrayList<Class<?>>(stepsInstances.keySet());
 33  
     }
 34  
 
 35  
     public Object createInstanceOfType(Class<?> type) {
 36  139
         Object instance = stepsInstances.get(type);
 37  139
         if ( instance == null ){
 38  0
             throw new StepsInstanceNotFound(type, this);
 39  
         }
 40  139
         return instance;
 41  
     }
 42  
 
 43  
 }