Coverage Report - org.jbehave.core.steps.BeforeOrAfterStep
 
Classes in this File Line Coverage Branch Coverage Complexity
BeforeOrAfterStep
100%
17/17
N/A
1
 
 1  
 package org.jbehave.core.steps;
 2  
 
 3  
 import java.lang.reflect.Method;
 4  
 
 5  
 import org.apache.commons.lang.builder.ToStringBuilder;
 6  
 import org.apache.commons.lang.builder.ToStringStyle;
 7  
 import org.jbehave.core.annotations.AfterScenario;
 8  
 import org.jbehave.core.annotations.AfterStory;
 9  
 import org.jbehave.core.annotations.BeforeScenario;
 10  
 import org.jbehave.core.annotations.BeforeStory;
 11  
 import org.jbehave.core.annotations.AfterScenario.Outcome;
 12  
 import org.jbehave.core.steps.StepCollector.Stage;
 13  
 
 14  
 /**
 15  
  * A BeforeOrAfterStep is associated to a Java method annotated with
 16  
  * {@link BeforeStory}, {@link AfterStory}, {@link BeforeScenario} or
 17  
  * {@link AfterScenario} in a {@link CandidatesSteps} instance class. The
 18  
  * BeforeOrAfterStep is responsible for the creation of the executable step via
 19  
  * the {@link StepCreator}.
 20  
  */
 21  
 public class BeforeOrAfterStep {
 22  
 
 23  
     private final Stage stage;
 24  
     private final Method method;
 25  
     private final StepCreator stepCreator;
 26  
     private final Outcome outcome;
 27  30
     private StepMonitor stepMonitor = new SilentStepMonitor();
 28  
 
 29  
     public BeforeOrAfterStep(Stage stage, Method method, Object instance) {
 30  17
         this(stage, method, instance, Outcome.ANY);
 31  17
     }
 32  
 
 33  30
     public BeforeOrAfterStep(Stage stage, Method method, Object instance, Outcome outcome) {
 34  30
         this.stage = stage;
 35  30
         this.method = method;
 36  30
         this.outcome = outcome;
 37  30
         this.stepCreator = new StepCreator(instance, stepMonitor);
 38  30
     }
 39  
 
 40  
     public Stage getStage() {
 41  12
         return stage;
 42  
     }
 43  
 
 44  
     public Method getMethod() {
 45  4
         return method;
 46  
     }
 47  
 
 48  
     public Step createStep() {
 49  13
         return stepCreator.createBeforeOrAfterStep(method);
 50  
     }
 51  
 
 52  
     public Step createStepUponOutcome(boolean failureOccured) {
 53  11
         return stepCreator.createAfterStepUponOutcome(method, outcome, failureOccured);
 54  
     }
 55  
 
 56  
     public void useStepMonitor(StepMonitor stepMonitor) {
 57  1
         this.stepMonitor = stepMonitor;
 58  1
         this.stepCreator.useStepMonitor(stepMonitor);
 59  1
     }
 60  
 
 61  
     @Override
 62  
     public String toString() {
 63  1
         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append(stage).append(method).append(outcome)
 64  
                 .append(stepMonitor).toString();
 65  
     }
 66  
 
 67  
 }