Coverage Report - org.jbehave.core.configuration.Configuration
 
Classes in this File Line Coverage Branch Coverage Complexity
Configuration
98%
78/79
100%
2/2
1.053
 
 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.failures.FailingUponPendingStep;
 10  
 import org.jbehave.core.failures.FailureStrategy;
 11  
 import org.jbehave.core.failures.PassingUponPendingStep;
 12  
 import org.jbehave.core.failures.PendingStepStrategy;
 13  
 import org.jbehave.core.failures.RethrowingFailure;
 14  
 import org.jbehave.core.failures.SilentlyAbsorbingFailure;
 15  
 import org.jbehave.core.i18n.LocalizedKeywords;
 16  
 import org.jbehave.core.io.LoadFromClasspath;
 17  
 import org.jbehave.core.io.StoryLoader;
 18  
 import org.jbehave.core.io.StoryPathResolver;
 19  
 import org.jbehave.core.io.UnderscoredCamelCaseResolver;
 20  
 import org.jbehave.core.parsers.RegexPrefixCapturingPatternParser;
 21  
 import org.jbehave.core.parsers.RegexStoryParser;
 22  
 import org.jbehave.core.parsers.StepPatternParser;
 23  
 import org.jbehave.core.parsers.StoryParser;
 24  
 import org.jbehave.core.reporters.ConsoleOutput;
 25  
 import org.jbehave.core.reporters.FreemarkerViewGenerator;
 26  
 import org.jbehave.core.reporters.PrintStreamStepdocReporter;
 27  
 import org.jbehave.core.reporters.StepdocReporter;
 28  
 import org.jbehave.core.reporters.StoryReporter;
 29  
 import org.jbehave.core.reporters.StoryReporterBuilder;
 30  
 import org.jbehave.core.reporters.ViewGenerator;
 31  
 import org.jbehave.core.steps.MarkUnmatchedStepsAsPending;
 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 java.util.HashMap;
 40  
 import java.util.Map;
 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  202
 public abstract class Configuration {
 58  
 
 59  
     /**
 60  
      * Dry run is switched off by default
 61  
      */
 62  202
     private boolean dryRun = false;
 63  
 
 64  
     /**
 65  
      * Use English language for keywords
 66  
      */
 67  202
     private Keywords keywords = new LocalizedKeywords();
 68  
 
 69  
     /**
 70  
      * Provides pending steps where unmatched steps exist.
 71  
      */
 72  202
     private StepCollector stepCollector = new MarkUnmatchedStepsAsPending();
 73  
 
 74  
     /**
 75  
      * Parses the textual representation via pattern matching of keywords
 76  
      */
 77  202
     private StoryParser storyParser = new RegexStoryParser(keywords);
 78  
 
 79  
     /**
 80  
      * Loads story content from classpath
 81  
      */
 82  202
     private StoryLoader storyLoader = new LoadFromClasspath();
 83  
 
 84  
     /**
 85  
      * Resolves story paths from class names using underscored camel case with
 86  
      * ".story" extension
 87  
      */
 88  202
     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  202
     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  202
     private PendingStepStrategy pendingStepStrategy = new PassingUponPendingStep();
 109  
 
 110  
     /**
 111  
      * Reports stories to console output
 112  
      */
 113  202
     private StoryReporter defaultStoryReporter = new ConsoleOutput();
 114  
 
 115  
     /**
 116  
      * Collects story reporters by story path
 117  
      */
 118  202
     private Map<String, StoryReporter> storyReporters = new HashMap<String, StoryReporter>();
 119  
 
 120  
     /**
 121  
      * The story reporter builder
 122  
      */
 123  202
     private StoryReporterBuilder storyReporterBuilder = new StoryReporterBuilder();
 124  
 
 125  
     /**
 126  
      * Finder of matching candidate steps
 127  
      */
 128  202
     private StepFinder stepFinder = new StepFinder();
 129  
 
 130  
     /**
 131  
      * Report candidate steps found to System.out
 132  
      */
 133  202
     private StepdocReporter stepdocReporter = new PrintStreamStepdocReporter();
 134  
 
 135  
     /**
 136  
      * Pattern build that uses prefix for identifying parameters
 137  
      */
 138  202
     private StepPatternParser stepPatternParser = new RegexPrefixCapturingPatternParser();
 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  202
     private StepMonitor stepMonitor = new SilentStepMonitor();
 146  
 
 147  
     /**
 148  
      * Paranamer is switched off by default
 149  
      */
 150  202
     private Paranamer paranamer = new NullParanamer();
 151  
 
 152  
     /**
 153  
      * Use default built-in parameter converters
 154  
      */
 155  202
     private ParameterConverters parameterConverters = new ParameterConverters();
 156  
 
 157  
     /**
 158  
      * Use Freemarker-based view generator
 159  
      */
 160  202
     private ViewGenerator viewGenerator = new FreemarkerViewGenerator();
 161  
 
 162  
     public boolean dryRun() {
 163  61
         return dryRun;
 164  
     }
 165  
 
 166  
     public Keywords keywords() {
 167  250
         return keywords;
 168  
     }
 169  
 
 170  
     public StoryParser storyParser() {
 171  3
         return storyParser;
 172  
     }
 173  
 
 174  
     public StoryLoader storyLoader() {
 175  3
         return storyLoader;
 176  
     }
 177  
 
 178  
     public StoryPathResolver storyPathResolver() {
 179  22
         return storyPathResolver;
 180  
     }
 181  
 
 182  
     public FailureStrategy failureStrategy() {
 183  15
         return failureStrategy;
 184  
     }
 185  
 
 186  
     public PendingStepStrategy pendingStepStrategy() {
 187  16
         return pendingStepStrategy;
 188  
     }
 189  
 
 190  
     public StoryReporter defaultStoryReporter() {
 191  19
         return defaultStoryReporter;
 192  
     }
 193  
 
 194  
     public StoryReporter storyReporter(String storyPath) {
 195  19
         StoryReporter storyReporter = storyReporters.get(storyPath);
 196  19
         if (storyReporter != null) {
 197  4
             return storyReporter;
 198  
         }
 199  
         // fall back on default story reporter
 200  15
         return defaultStoryReporter();
 201  
     }
 202  
 
 203  
     public StoryReporterBuilder storyReporterBuilder() {
 204  34
         return storyReporterBuilder;
 205  
     }
 206  
 
 207  
     public StepCollector stepCollector() {
 208  17
         return stepCollector;
 209  
     }
 210  
 
 211  
     public StepFinder stepFinder() {
 212  4
         return stepFinder;
 213  
     }
 214  
 
 215  
     public StepdocReporter stepdocReporter() {
 216  4
         return stepdocReporter;
 217  
     }
 218  
 
 219  
     public StepPatternParser stepPatternParser() {
 220  49
         return stepPatternParser;
 221  
     }
 222  
 
 223  
     public StepMonitor stepMonitor() {
 224  49
         return stepMonitor;
 225  
     }
 226  
 
 227  
     public Paranamer paranamer() {
 228  49
         return paranamer;
 229  
     }
 230  
 
 231  
     public ParameterConverters parameterConverters() {
 232  62
         return parameterConverters;
 233  
     }
 234  
     
 235  
     public ViewGenerator viewGenerator() {
 236  20
         return viewGenerator;
 237  
     }
 238  
 
 239  
     public Configuration doDryRun(Boolean dryRun) {
 240  202
         this.dryRun = dryRun;
 241  202
         return this;
 242  
     }
 243  
 
 244  
     public Configuration useKeywords(Keywords keywords) {
 245  211
         this.keywords = keywords;
 246  211
         return this;
 247  
     }
 248  
 
 249  
     public Configuration usePendingStepStrategy(PendingStepStrategy pendingStepStrategy) {
 250  222
         this.pendingStepStrategy = pendingStepStrategy;
 251  222
         return this;
 252  
     }
 253  
 
 254  
     public Configuration useFailureStrategy(FailureStrategy failureStrategy) {
 255  222
         this.failureStrategy = failureStrategy;
 256  222
         return this;
 257  
     }
 258  
 
 259  
     public Configuration useStoryParser(StoryParser storyParser) {
 260  222
         this.storyParser = storyParser;
 261  222
         return this;
 262  
     }
 263  
 
 264  
     public Configuration useStoryLoader(StoryLoader storyLoader) {
 265  222
         this.storyLoader = storyLoader;
 266  222
         return this;
 267  
     }
 268  
 
 269  
     public Configuration useStoryPathResolver(StoryPathResolver storyPathResolver) {
 270  11
         this.storyPathResolver = storyPathResolver;
 271  11
         return this;
 272  
     }
 273  
 
 274  
     public Configuration useDefaultStoryReporter(StoryReporter storyReporter) {
 275  222
         this.defaultStoryReporter = storyReporter;
 276  222
         return this;
 277  
     }
 278  
 
 279  
     public Configuration useStoryReporter(String storyPath, StoryReporter storyReporter) {
 280  4
         this.storyReporters.put(storyPath, storyReporter);
 281  4
         return this;
 282  
     }
 283  
 
 284  
     public Configuration useStoryReporters(Map<String, StoryReporter> storyReporters) {
 285  18
         this.storyReporters.putAll(storyReporters);
 286  18
         return this;
 287  
     }
 288  
 
 289  
     public Configuration useStoryReporterBuilder(StoryReporterBuilder storyReporterBuilder) {
 290  10
         this.storyReporterBuilder = storyReporterBuilder;
 291  10
         return this;
 292  
     }
 293  
 
 294  
     public Configuration useStepCollector(StepCollector stepCollector) {
 295  222
         this.stepCollector = stepCollector;
 296  222
         return this;
 297  
     }
 298  
 
 299  
     public Configuration useStepFinder(StepFinder stepFinder) {
 300  212
         this.stepFinder = stepFinder;
 301  212
         return this;
 302  
     }
 303  
 
 304  
     public Configuration useStepdocReporter(StepdocReporter stepdocReporter) {
 305  212
         this.stepdocReporter = stepdocReporter;
 306  212
         return this;
 307  
     }
 308  
 
 309  
     public Configuration useStepPatternParser(StepPatternParser stepPatternParser) {
 310  208
         this.stepPatternParser = stepPatternParser;
 311  208
         return this;
 312  
     }
 313  
 
 314  
     public Configuration useStepMonitor(StepMonitor stepMonitor) {
 315  208
         this.stepMonitor = stepMonitor;
 316  208
         return this;
 317  
     }
 318  
 
 319  
     public Configuration useParanamer(Paranamer paranamer) {
 320  208
         this.paranamer = paranamer;
 321  208
         return this;
 322  
     }
 323  
 
 324  
     public Configuration useParanamer() {
 325  0
         return useParanamer(new CachingParanamer(new BytecodeReadingParanamer()));
 326  
     }
 327  
 
 328  
     public Configuration useParameterConverters(ParameterConverters parameterConverters) {
 329  9
         this.parameterConverters = parameterConverters;
 330  9
         return this;
 331  
     }
 332  
 
 333  
     public Configuration useViewGenerator(ViewGenerator viewGenerator) {
 334  213
         this.viewGenerator = viewGenerator;
 335  213
         return this;
 336  
     }
 337  
 
 338  
 
 339  
 }