Coverage Report - org.jbehave.core.ConfigurableEmbedder
 
Classes in this File Line Coverage Branch Coverage Complexity
ConfigurableEmbedder
100%
17/17
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  
 
 15  
 /**
 16  
  * <p>
 17  
  * Abstract implementation of {@link Embeddable} which allow to configure
 18  
  * the {@link Embedder} used to run the story or stories, using the
 19  
  * {@link Configuration} and the {@link CandidateSteps} specified.
 20  
  * </p>
 21  
  * <p>
 22  
  * By default {@link MostUsefulConfiguration}) is used and be overridden
 23  
  * via the {@link #useConfiguration(Configuration)} method.
 24  
  * </p>
 25  
  * <p>
 26  
  * Users need to add the {@link CandidateSteps} instances, via the
 27  
  * {@link #addSteps(CandidateSteps...)} or {@link
 28  
  * #addSteps(List<CandidateSteps>)} methods.
 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  26
 public abstract class ConfigurableEmbedder implements Embeddable {
 38  
 
 39  26
     private Embedder embedder = new Embedder();
 40  26
     private Configuration configuration = new MostUsefulConfiguration();
 41  26
     private List<CandidateSteps> candidateSteps = new ArrayList<CandidateSteps>();
 42  
 
 43  
     public void useEmbedder(Embedder embedder) {
 44  20
         this.embedder = embedder;
 45  20
     }
 46  
 
 47  
     public void useConfiguration(Configuration configuration) {
 48  6
         this.configuration = configuration;
 49  6
     }
 50  
 
 51  
     public void addSteps(CandidateSteps... steps) {
 52  4
         addSteps(asList(steps));
 53  4
     }
 54  
 
 55  
     public void addSteps(List<CandidateSteps> steps) {
 56  5
         this.candidateSteps.addAll(steps);
 57  5
     }
 58  
 
 59  
     public Configuration configuration() {
 60  17
         return configuration;
 61  
     }
 62  
 
 63  
     public List<CandidateSteps> candidateSteps() {
 64  15
         return candidateSteps;
 65  
     }
 66  
 
 67  
     public Embedder configuredEmbedder() {
 68  15
         embedder.useConfiguration(configuration());
 69  15
         embedder.useCandidateSteps(candidateSteps());
 70  15
         return embedder;
 71  
     }
 72  
 
 73  
 }