PropertyBasedConfiguration.java

  1. package org.jbehave.core.configuration;

  2. import org.jbehave.core.failures.FailingUponPendingStep;
  3. import org.jbehave.core.failures.PendingStepStrategy;
  4. import org.jbehave.core.reporters.SilentSuccessFilter;
  5. import org.jbehave.core.reporters.StoryReporter;

  6. /**
  7.  * PropertyBasedConfiguration is backed by MostUsefulConfiguration as default,
  8.  * but has different behaviour if certain system properties are set:
  9.  * <ul>
  10.  * <li>{@link #FAIL_ON_PENDING}: uses {@link FailingUponPendingStep}</li>
  11.  * <li>{@link #SILENT_SUCCESS}: uses {@link SilentSuccessFilter} decorator</li>
  12.  * </ul>
  13.  */
  14. public class PropertyBasedConfiguration extends MostUsefulConfiguration {

  15.     public static final String FAIL_ON_PENDING = "org.jbehave.core.configuration.failonpending";
  16.     public static final String SILENT_SUCCESS = "org.jbehave.core.configuration.silentsuccess";

  17.     /**
  18.      * <p>
  19.      * If the system property {@link #SILENT_SUCCESS} is set, uses a
  20.      * {@link SilentSuccessFilter} to decorate the default StoryReporter.
  21.      * </p>
  22.      * <p>
  23.      * Setting {@link #SILENT_SUCCESS} will only show the steps for all stories
  24.      * if the stories fail.
  25.      * </p>
  26.      */
  27.     @Override
  28.     public StoryReporter defaultStoryReporter() {
  29.         StoryReporter storyReporter = super.defaultStoryReporter();
  30.         if (System.getProperty(SILENT_SUCCESS) == null) {
  31.             return storyReporter;
  32.         } else {
  33.             return new SilentSuccessFilter(storyReporter);
  34.         }
  35.     }
  36.    
  37.     /**
  38.      * <p>
  39.      * If the system property {@link #FAIL_ON_PENDING} is set, returns
  40.      * {@link FailingUponPendingStep} otherwise returns the default.
  41.      * </p>
  42.      * <p>
  43.      * Setting {@link #FAIL_ON_PENDING} will cause pending steps to fail story
  44.      * execution, so you can see if any steps don't match or are still to be
  45.      * implemented.
  46.      * </p>
  47.      */
  48.     @Override
  49.     public PendingStepStrategy pendingStepStrategy() {
  50.         if (System.getProperty(FAIL_ON_PENDING) == null) {
  51.             return super.pendingStepStrategy();
  52.         }
  53.         return new FailingUponPendingStep();
  54.     }

  55. }