Coverage Report - org.jbehave.core.steps.pico.PicoStepsFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
PicoStepsFactory
91%
11/12
83%
5/6
2.333
 
 1  
 package org.jbehave.core.steps.pico;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.List;
 5  
 
 6  
 import org.jbehave.core.configuration.Configuration;
 7  
 import org.jbehave.core.steps.AbstractStepsFactory;
 8  
 import org.jbehave.core.steps.InjectableStepsFactory;
 9  
 import org.picocontainer.ComponentAdapter;
 10  
 import org.picocontainer.PicoContainer;
 11  
 
 12  
 /**
 13  
  * An {@link InjectableStepsFactory} that uses a {@link PicoContainer} for the
 14  
  * composition and instantiation of all components that contain JBehave
 15  
  * annotated methods.
 16  
  * 
 17  
  * @author Paul Hammant
 18  
  * @author Mauro Talevi
 19  
  */
 20  
 public class PicoStepsFactory extends AbstractStepsFactory {
 21  
 
 22  
         private final PicoContainer parent;
 23  
 
 24  
         public PicoStepsFactory(Configuration configuration, PicoContainer parent) {
 25  6
                 super(configuration);
 26  6
                 this.parent = parent;
 27  6
         }
 28  
 
 29  
         @Override
 30  
         protected List<Class<?>> stepsTypes() {
 31  5
                 List<Class<?>> types = new ArrayList<Class<?>>();
 32  5
                 for (ComponentAdapter<?> adapter : parent.getComponentAdapters()) {
 33  24
                         if (hasAnnotatedMethods(adapter.getComponentImplementation())) {
 34  4
                                 types.add(adapter.getComponentImplementation());
 35  
                         }
 36  
                 }
 37  5
                 return types;
 38  
         }
 39  
 
 40  
     public Object createInstanceOfType(Class<?> type) {
 41  6
         Object instance = parent.getComponent(type);
 42  5
         if ( instance == null ){
 43  0
             throw new StepsInstanceNotFound(type, this);
 44  
         }
 45  5
         return instance;
 46  
     }
 47  
 
 48  
 }