Coverage Report - org.jbehave.core.steps.ProvidedStepsFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ProvidedStepsFactory
30%
4/13
0%
0/6
2.667
 
 1  
 package org.jbehave.core.steps;
 2  
 
 3  
 import java.util.List;
 4  
 
 5  
 import org.jbehave.core.steps.AbstractStepsFactory.StepsInstanceNotFound;
 6  
 
 7  
 /**
 8  
  * An {@link InjectableStepsFactory} that is provided with the
 9  
  * {@link CandidateSteps} instances.
 10  
  */
 11  
 public class ProvidedStepsFactory implements InjectableStepsFactory {
 12  
 
 13  
     private final List<CandidateSteps> candidateSteps;
 14  
 
 15  30
     public ProvidedStepsFactory(List<CandidateSteps> candidateSteps) {
 16  30
         this.candidateSteps = candidateSteps;
 17  30
     }
 18  
 
 19  
     public List<CandidateSteps> createCandidateSteps() {
 20  29
         return candidateSteps;
 21  
     }
 22  
 
 23  
     public Object createInstanceOfType(Class<?> type) {
 24  0
         Object instance = null;
 25  0
         for (CandidateSteps steps : candidateSteps) {
 26  
             try {
 27  0
                 if (type.equals(((Steps) steps).type())) {
 28  0
                     instance = ((Steps) steps).instance();
 29  
                 }
 30  0
             } catch (RuntimeException e) {
 31  
                 // creation failed on given factory, carry on
 32  0
             }
 33  
         }
 34  0
         if (instance == null) {
 35  0
             throw new StepsInstanceNotFound(type, this);
 36  
         }
 37  0
         return instance;
 38  
     }
 39  
 
 40  
 }