Coverage Report - org.jbehave.core.configuration.Configuration
 
Classes in this File Line Coverage Branch Coverage Complexity
Configuration
96%
79/82
100%
2/2
1.05
 
 1  
 package org.jbehave.core.configuration;
 2  
 
 3  
 import com.thoughtworks.paranamer.BytecodeReadingParanamer;
 4  
 import com.thoughtworks.paranamer.CachingParanamer;
 5  
 import com.thoughtworks.paranamer.NullParanamer;
 6  
 import com.thoughtworks.paranamer.Paranamer;
 7  
 import org.jbehave.core.Embeddable;
 8  
 import org.jbehave.core.embedder.Embedder;
 9  
 import org.jbehave.core.embedder.StoryControls;
 10  
 import org.jbehave.core.failures.FailingUponPendingStep;
 11  
 import org.jbehave.core.failures.FailureStrategy;
 12  
 import org.jbehave.core.failures.PassingUponPendingStep;
 13  
 import org.jbehave.core.failures.PendingStepStrategy;
 14  
 import org.jbehave.core.failures.RethrowingFailure;
 15  
 import org.jbehave.core.failures.SilentlyAbsorbingFailure;
 16  
 import org.jbehave.core.i18n.LocalizedKeywords;
 17  
 import org.jbehave.core.io.LoadFromClasspath;
 18  
 import org.jbehave.core.io.StoryLoader;
 19  
 import org.jbehave.core.io.StoryPathResolver;
 20  
 import org.jbehave.core.io.UnderscoredCamelCaseResolver;
 21  
 import org.jbehave.core.parsers.RegexPrefixCapturingPatternParser;
 22  
 import org.jbehave.core.parsers.RegexStoryParser;
 23  
 import org.jbehave.core.parsers.StepPatternParser;
 24  
 import org.jbehave.core.parsers.StoryParser;
 25  
 import org.jbehave.core.reporters.ConsoleOutput;
 26  
 import org.jbehave.core.reporters.FreemarkerViewGenerator;
 27  
 import org.jbehave.core.reporters.PrintStreamStepdocReporter;
 28  
 import org.jbehave.core.reporters.StepdocReporter;
 29  
 import org.jbehave.core.reporters.StoryReporter;
 30  
 import org.jbehave.core.reporters.StoryReporterBuilder;
 31  
 import org.jbehave.core.reporters.ViewGenerator;
 32  
 import org.jbehave.core.steps.MarkUnmatchedStepsAsPending;
 33  
 import org.jbehave.core.steps.ParameterConverters;
 34  
 import org.jbehave.core.steps.PrintStreamStepMonitor;
 35  
 import org.jbehave.core.steps.SilentStepMonitor;
 36  
 import org.jbehave.core.steps.StepCollector;
 37  
 import org.jbehave.core.steps.StepFinder;
 38  
 import org.jbehave.core.steps.StepMonitor;
 39  
 
 40  
 import java.util.HashMap;
 41  
 import java.util.Map;
 42  
 
 43  
 /**
 44  
  * <p>
 45  
  * Provides the configuration used by the {@link Embedder} and the in the
 46  
  * {@link Embeddable} implementations to customise its runtime properties.
 47  
  * </p>
 48  
  * <p>
 49  
  * Configuration implements a <a
 50  
  * href="http://en.wikipedia.org/wiki/Builder_pattern">Builder</a> pattern so
 51  
  * that each element of the configuration can be specified individually, and
 52  
  * read well. All elements have default values, which can be overridden by the
 53  
  * "use" methods. The "use" methods allow to override the dependencies one by
 54  
  * one and play nicer with a Java hierarchical structure, in that does allow the
 55  
  * use of non-static member variables.
 56  
  * </p>
 57  
  */
 58  206
 public abstract class Configuration {
 59  
 
 60  
     /**
 61  
      * Use default story controls
 62  
      */
 63  206
     private StoryControls storyControls = new StoryControls();
 64  
 
 65  
     /**
 66  
      * Use English language for keywords
 67  
      */
 68  206
     private Keywords keywords = new LocalizedKeywords();
 69  
 
 70  
     /**
 71  
      * Provides pending steps where unmatched steps exist.
 72  
      */
 73  206
     private StepCollector stepCollector = new MarkUnmatchedStepsAsPending();
 74  
 
 75  
     /**
 76  
      * Parses the textual representation via pattern matching of keywords
 77  
      */
 78  206
     private StoryParser storyParser = new RegexStoryParser(keywords);
 79  
 
 80  
     /**
 81  
      * Loads story content from classpath
 82  
      */
 83  206
     private StoryLoader storyLoader = new LoadFromClasspath();
 84  
 
 85  
     /**
 86  
      * Resolves story paths from class names using underscored camel case with
 87  
      * ".story" extension
 88  
      */
 89  206
     private StoryPathResolver storyPathResolver = new UnderscoredCamelCaseResolver();
 90  
 
 91  
     /**
 92  
      * Handles errors by re-throwing them.
 93  
      * <p/>
 94  
      * If there are multiple scenarios in a single story, this could cause the
 95  
      * story to stop after the first failing scenario.
 96  
      * <p/>
 97  
      * Users wanting a different behaviour may use
 98  
      * {@link SilentlyAbsorbingFailure}.
 99  
      */
 100  206
     private FailureStrategy failureStrategy = new RethrowingFailure();
 101  
 
 102  
     /**
 103  
      * Allows pending steps to pass, so that steps that to do not match any
 104  
      * method will not cause failure.
 105  
      * <p/>
 106  
      * Uses wanting a stricter behaviour for pending steps may use
 107  
      * {@link FailingUponPendingStep}.
 108  
      */
 109  206
     private PendingStepStrategy pendingStepStrategy = new PassingUponPendingStep();
 110  
 
 111  
     /**
 112  
      * Reports stories to console output
 113  
      */
 114  206
     private StoryReporter defaultStoryReporter = new ConsoleOutput();
 115  
 
 116  
     /**
 117  
      * Collects story reporters by story path
 118  
      */
 119  206
     private Map<String, StoryReporter> storyReporters = new HashMap<String, StoryReporter>();
 120  
 
 121  
     /**
 122  
      * The story reporter builder
 123  
      */
 124  206
     private StoryReporterBuilder storyReporterBuilder = new StoryReporterBuilder();
 125  
 
 126  
     /**
 127  
      * Finder of matching candidate steps
 128  
      */
 129  206
     private StepFinder stepFinder = new StepFinder();
 130  
 
 131  
     /**
 132  
      * Report candidate steps found to System.out
 133  
      */
 134  206
     private StepdocReporter stepdocReporter = new PrintStreamStepdocReporter();
 135  
 
 136  
     /**
 137  
      * Pattern build that uses prefix for identifying parameters
 138  
      */
 139  206
     private StepPatternParser stepPatternParser = new RegexPrefixCapturingPatternParser();
 140  
 
 141  
     /**
 142  
      * Silent monitoring that does not produce any noise of the step matching.
 143  
      * </p> If needed, users can switch on verbose monitoring using
 144  
      * {@link PrintStreamStepMonitor}
 145  
      */
 146  206
     private StepMonitor stepMonitor = new SilentStepMonitor();
 147  
 
 148  
     /**
 149  
      * Paranamer is switched off by default
 150  
      */
 151  206
     private Paranamer paranamer = new NullParanamer();
 152  
 
 153  
     /**
 154  
      * Use default built-in parameter converters
 155  
      */
 156  206
     private ParameterConverters parameterConverters = new ParameterConverters();
 157  
 
 158  
     /**
 159  
      * Use Freemarker-based view generator
 160  
      */
 161  206
     private ViewGenerator viewGenerator = new FreemarkerViewGenerator();
 162  
 
 163  
     public Keywords keywords() {
 164  254
         return keywords;
 165  
     }
 166  
 
 167  
     public boolean dryRun() {
 168  2
         return storyControls.dryRun();
 169  
     }
 170  
     
 171  
     public StoryControls storyControls() {
 172  90
         return storyControls;
 173  
     }
 174  
 
 175  
     public StoryParser storyParser() {
 176  4
         return storyParser;
 177  
     }
 178  
 
 179  
     public StoryLoader storyLoader() {
 180  4
         return storyLoader;
 181  
     }
 182  
 
 183  
     public StoryPathResolver storyPathResolver() {
 184  22
         return storyPathResolver;
 185  
     }
 186  
 
 187  
     public FailureStrategy failureStrategy() {
 188  18
         return failureStrategy;
 189  
     }
 190  
 
 191  
     public PendingStepStrategy pendingStepStrategy() {
 192  19
         return pendingStepStrategy;
 193  
     }
 194  
 
 195  
     public StoryReporter defaultStoryReporter() {
 196  22
         return defaultStoryReporter;
 197  
     }
 198  
 
 199  
     public StoryReporter storyReporter(String storyPath) {
 200  22
         StoryReporter storyReporter = storyReporters.get(storyPath);
 201  22
         if (storyReporter != null) {
 202  4
             return storyReporter;
 203  
         }
 204  
         // fall back on default story reporter
 205  18
         return defaultStoryReporter();
 206  
     }
 207  
 
 208  
     public StoryReporterBuilder storyReporterBuilder() {
 209  34
         return storyReporterBuilder;
 210  
     }
 211  
 
 212  
     public StepCollector stepCollector() {
 213  20
         return stepCollector;
 214  
     }
 215  
 
 216  
     public StepFinder stepFinder() {
 217  4
         return stepFinder;
 218  
     }
 219  
 
 220  
     public StepdocReporter stepdocReporter() {
 221  4
         return stepdocReporter;
 222  
     }
 223  
 
 224  
     public StepPatternParser stepPatternParser() {
 225  49
         return stepPatternParser;
 226  
     }
 227  
 
 228  
     public StepMonitor stepMonitor() {
 229  49
         return stepMonitor;
 230  
     }
 231  
 
 232  
     public Paranamer paranamer() {
 233  49
         return paranamer;
 234  
     }
 235  
 
 236  
     public ParameterConverters parameterConverters() {
 237  62
         return parameterConverters;
 238  
     }
 239  
     
 240  
     public ViewGenerator viewGenerator() {
 241  20
         return viewGenerator;
 242  
     }
 243  
 
 244  
     public Configuration useKeywords(Keywords keywords) {
 245  215
         this.keywords = keywords;
 246  215
         return this;
 247  
     }
 248  
 
 249  
     public Configuration doDryRun(Boolean dryRun) {
 250  0
         this.storyControls.doDryRun(dryRun);
 251  0
         return this;
 252  
     }
 253  
     
 254  
     public Configuration useStoryControls(StoryControls storyControls){
 255  212
         this.storyControls = storyControls;
 256  212
         return this;
 257  
     }
 258  
     
 259  
     public Configuration usePendingStepStrategy(PendingStepStrategy pendingStepStrategy) {
 260  228
         this.pendingStepStrategy = pendingStepStrategy;
 261  228
         return this;
 262  
     }
 263  
 
 264  
     public Configuration useFailureStrategy(FailureStrategy failureStrategy) {
 265  228
         this.failureStrategy = failureStrategy;
 266  228
         return this;
 267  
     }
 268  
 
 269  
     public Configuration useStoryParser(StoryParser storyParser) {
 270  228
         this.storyParser = storyParser;
 271  228
         return this;
 272  
     }
 273  
 
 274  
     public Configuration useStoryLoader(StoryLoader storyLoader) {
 275  228
         this.storyLoader = storyLoader;
 276  228
         return this;
 277  
     }
 278  
 
 279  
     public Configuration useStoryPathResolver(StoryPathResolver storyPathResolver) {
 280  11
         this.storyPathResolver = storyPathResolver;
 281  11
         return this;
 282  
     }
 283  
 
 284  
     public Configuration useDefaultStoryReporter(StoryReporter storyReporter) {
 285  228
         this.defaultStoryReporter = storyReporter;
 286  228
         return this;
 287  
     }
 288  
 
 289  
     public Configuration useStoryReporter(String storyPath, StoryReporter storyReporter) {
 290  4
         this.storyReporters.put(storyPath, storyReporter);
 291  4
         return this;
 292  
     }
 293  
 
 294  
     public Configuration useStoryReporters(Map<String, StoryReporter> storyReporters) {
 295  18
         this.storyReporters.putAll(storyReporters);
 296  18
         return this;
 297  
     }
 298  
 
 299  
     public Configuration useStoryReporterBuilder(StoryReporterBuilder storyReporterBuilder) {
 300  10
         this.storyReporterBuilder = storyReporterBuilder;
 301  10
         return this;
 302  
     }
 303  
 
 304  
     public Configuration useStepCollector(StepCollector stepCollector) {
 305  228
         this.stepCollector = stepCollector;
 306  228
         return this;
 307  
     }
 308  
 
 309  
     public Configuration useStepFinder(StepFinder stepFinder) {
 310  216
         this.stepFinder = stepFinder;
 311  216
         return this;
 312  
     }
 313  
 
 314  
     public Configuration useStepdocReporter(StepdocReporter stepdocReporter) {
 315  216
         this.stepdocReporter = stepdocReporter;
 316  216
         return this;
 317  
     }
 318  
 
 319  
     public Configuration useStepPatternParser(StepPatternParser stepPatternParser) {
 320  212
         this.stepPatternParser = stepPatternParser;
 321  212
         return this;
 322  
     }
 323  
 
 324  
     public Configuration useStepMonitor(StepMonitor stepMonitor) {
 325  212
         this.stepMonitor = stepMonitor;
 326  212
         return this;
 327  
     }
 328  
 
 329  
     public Configuration useParanamer(Paranamer paranamer) {
 330  212
         this.paranamer = paranamer;
 331  212
         return this;
 332  
     }
 333  
 
 334  
     public Configuration useParanamer() {
 335  0
         return useParanamer(new CachingParanamer(new BytecodeReadingParanamer()));
 336  
     }
 337  
 
 338  
     public Configuration useParameterConverters(ParameterConverters parameterConverters) {
 339  9
         this.parameterConverters = parameterConverters;
 340  9
         return this;
 341  
     }
 342  
 
 343  
     public Configuration useViewGenerator(ViewGenerator viewGenerator) {
 344  217
         this.viewGenerator = viewGenerator;
 345  217
         return this;
 346  
     }
 347  
 
 348  
 }