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