Coverage Report - org.jbehave.core.ConfigurableEmbedder
 
Classes in this File Line Coverage Branch Coverage Complexity
ConfigurableEmbedder
100%
21/21
N/A
1
 
 1  
 package org.jbehave.core;
 2  
 
 3  
 import static java.util.Arrays.asList;
 4  
 
 5  
 import java.util.ArrayList;
 6  
 import java.util.List;
 7  
 
 8  
 import org.jbehave.core.configuration.Configuration;
 9  
 import org.jbehave.core.configuration.MostUsefulConfiguration;
 10  
 import org.jbehave.core.embedder.Embedder;
 11  
 import org.jbehave.core.junit.JUnitStories;
 12  
 import org.jbehave.core.junit.JUnitStory;
 13  
 import org.jbehave.core.steps.CandidateSteps;
 14  
 import org.jbehave.core.steps.InjectableStepsFactory;
 15  
 
 16  
 /**
 17  
  * <p>
 18  
  * Abstract implementation of {@link Embeddable} which allow to configure
 19  
  * the {@link Embedder} used to run the story or stories, using the
 20  
  * {@link Configuration} and the {@link CandidateSteps} specified.
 21  
  * </p>
 22  
  * <p>
 23  
  * By default {@link MostUsefulConfiguration}) is used and be overridden
 24  
  * via the {@link #useConfiguration(Configuration)} method.
 25  
  * </p>
 26  
  * <p>
 27  
  * Users need to specify the {@link InjectableStepsFactory} which will be 
 28  
  * used to create the {@link CandidateSteps}.
 29  
  * </p>
 30  
  * <p>
 31  
  * Typically, users that use JUnit will find it easier to extend other
 32  
  * implementations, such as {@link JUnitStory} or {@link JUnitStories}, which
 33  
  * implement the {@link#run()} using the configured embedder and annotate it
 34  
  * with JUnit's {@link Test} annotation.
 35  
  * </p>
 36  
  */
 37  14
 public abstract class ConfigurableEmbedder implements Embeddable {
 38  
 
 39  14
     private Embedder embedder = new Embedder();
 40  14
     private Configuration configuration = new MostUsefulConfiguration();
 41  14
     private List<CandidateSteps> candidateSteps = new ArrayList<CandidateSteps>();
 42  
     private InjectableStepsFactory stepsFactory;
 43  
 
 44  
     public void useEmbedder(Embedder embedder) {
 45  12
         this.embedder = embedder;
 46  12
     }
 47  
 
 48  
     public void useConfiguration(Configuration configuration) {
 49  7
         this.configuration = configuration;
 50  7
     }
 51  
 
 52  
     public Configuration configuration() {
 53  8
         return configuration;
 54  
     }
 55  
     
 56  
     /**
 57  
      * @deprecated Use {@link #useStepsFactory(InjectableStepsFactory)}
 58  
      */
 59  
     public void addSteps(CandidateSteps... steps) {
 60  4
         addSteps(asList(steps));
 61  4
     }
 62  
 
 63  
     /**
 64  
      * @deprecated Use {@link #useStepsFactory(InjectableStepsFactory)}
 65  
      */
 66  
     public void addSteps(List<CandidateSteps> steps) {
 67  6
         this.candidateSteps.addAll(steps);
 68  6
     }
 69  
 
 70  
     /**
 71  
      * @deprecated Use {@link #stepsFactory()}
 72  
      */
 73  
     public List<CandidateSteps> candidateSteps() {
 74  7
         return candidateSteps;
 75  
     }
 76  
 
 77  
     public void useStepsFactory(InjectableStepsFactory stepsFactory){
 78  2
         this.stepsFactory = stepsFactory;        
 79  2
     }
 80  
     
 81  
     public InjectableStepsFactory stepsFactory(){
 82  6
         return stepsFactory;
 83  
     }
 84  
 
 85  
     public Embedder configuredEmbedder() {
 86  7
         embedder.useConfiguration(configuration());
 87  7
         embedder.useCandidateSteps(candidateSteps());
 88  7
         embedder.useStepsFactory(stepsFactory());
 89  7
         return embedder;
 90  
     }
 91  
 
 92  
 }