DelegatingStepMonitor.java

  1. package org.jbehave.core.steps;

  2. import static java.util.Arrays.asList;

  3. import java.lang.reflect.Method;
  4. import java.lang.reflect.Type;
  5. import java.util.Collection;
  6. import java.util.Queue;

  7. import org.jbehave.core.model.StepPattern;

  8. /**
  9.  * Monitor which collects other {@link StepMonitor}s and delegates all invocations to the collected monitors.
  10.  */
  11. public class DelegatingStepMonitor implements StepMonitor {

  12.     private final Collection<StepMonitor> delegates;

  13.     /**
  14.      * Creates DelegatingStepMonitor with a given collections of delegates
  15.      *
  16.      * @param delegates the StepMonitor-s to delegate to
  17.      */
  18.     public DelegatingStepMonitor(Collection<StepMonitor> delegates) {
  19.         this.delegates = delegates;
  20.     }

  21.     /**
  22.      * Creates DelegatingStepMonitor with a given varargs of delegates
  23.      *
  24.      * @param delegates the StepMonitor-s to delegate to
  25.      */
  26.     public DelegatingStepMonitor(StepMonitor... delegates) {
  27.         this(asList(delegates));
  28.     }

  29.     @Override
  30.     public void convertedValueOfType(String value, Type type, Object converted, Queue<Class<?>> converterClasses) {
  31.         for (StepMonitor monitor : delegates) {
  32.             monitor.convertedValueOfType(value, type, converted, converterClasses);
  33.         }
  34.     }

  35.     @Override
  36.     public void stepMatchesType(String stepAsString, String previousAsString, boolean matchesType, StepType stepType,
  37.             Method method, Object stepsInstance) {
  38.         for (StepMonitor monitor : delegates) {
  39.             monitor.stepMatchesType(stepAsString, previousAsString, matchesType, stepType, method, stepsInstance);
  40.         }
  41.     }

  42.     @Override
  43.     public void stepMatchesPattern(String step, boolean matches, StepPattern stepPattern, Method method,
  44.             Object stepsInstance) {
  45.         for (StepMonitor monitor : delegates) {
  46.             monitor.stepMatchesPattern(step, matches, stepPattern, method, stepsInstance);
  47.         }
  48.     }

  49.     @Override
  50.     public void foundParameter(String parameter, int position) {
  51.         for (StepMonitor monitor : delegates) {
  52.             monitor.foundParameter(parameter, position);
  53.         }
  54.     }

  55.     @Override
  56.     public void beforePerforming(String step, boolean dryRun, Method method) {
  57.         for (StepMonitor monitor : delegates) {
  58.             monitor.beforePerforming(step, dryRun, method);
  59.         }
  60.     }

  61.     @Override
  62.     public void afterPerforming(String step, boolean dryRun, Method method) {
  63.         for (StepMonitor monitor : delegates) {
  64.             monitor.afterPerforming(step, dryRun, method);
  65.         }
  66.     }

  67.     @Override
  68.     public void usingAnnotatedNameForParameter(String name, int position) {
  69.         for (StepMonitor monitor : delegates) {
  70.             monitor.usingAnnotatedNameForParameter(name, position);
  71.         }
  72.     }

  73.     @Override
  74.     public void usingNaturalOrderForParameter(int position) {
  75.         for (StepMonitor monitor : delegates) {
  76.             monitor.usingNaturalOrderForParameter(position);
  77.         }
  78.     }

  79.     @Override
  80.     public void usingParameterNameForParameter(String name, int position) {
  81.         for (StepMonitor monitor : delegates) {
  82.             monitor.usingParameterNameForParameter(name, position);
  83.         }
  84.     }

  85.     @Override
  86.     public void usingTableAnnotatedNameForParameter(String name, int position) {
  87.         for (StepMonitor monitor : delegates) {
  88.             monitor.usingTableAnnotatedNameForParameter(name, position);
  89.         }
  90.     }

  91.     @Override
  92.     public void usingTableParameterNameForParameter(String name, int position) {
  93.         for (StepMonitor monitor : delegates) {
  94.             monitor.usingTableParameterNameForParameter(name, position);
  95.         }
  96.     }

  97.     @Override
  98.     public void usingStepsContextParameter(String parameter) {
  99.         for (StepMonitor monitor : delegates) {
  100.             monitor.usingStepsContextParameter(parameter);
  101.         }
  102.     }
  103. }