Coverage Report - org.jbehave.core.steps.InstanceStepsFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
InstanceStepsFactory
92%
12/13
75%
3/4
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  196
     private final Map<Class<?>,Object> stepsInstances = new LinkedHashMap<Class<?>, Object>();
 18  
 
 19  
     public InstanceStepsFactory(Configuration configuration, Object... stepsInstances) {
 20  185
         this(configuration, asList(stepsInstances));
 21  185
     }
 22  
 
 23  
     public InstanceStepsFactory(Configuration configuration, List<?> stepsInstances) {
 24  196
         super(configuration);
 25  196
         for (Object instance : stepsInstances) {
 26  194
             this.stepsInstances.put(instance.getClass(), instance);
 27  194
         }
 28  196
     }
 29  
 
 30  
     @Override
 31  
     protected List<Class<?>> stepsTypes() {
 32  22
         return new ArrayList<Class<?>>(stepsInstances.keySet());
 33  
     }
 34  
 
 35  
     public Object createInstanceOfType(Class<?> type) {
 36  156
         Object instance = stepsInstances.get(type);
 37  156
         if ( instance == null ){
 38  0
             throw new StepsInstanceNotFound(type, this);
 39  
         }
 40  156
         return instance;
 41  
     }
 42  
 
 43  
 }