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