Coverage Report - org.jbehave.core.steps.BeforeOrAfterStep
 
Classes in this File Line Coverage Branch Coverage Complexity
BeforeOrAfterStep
100%
18/18
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.model.Meta;
 13  
 import org.jbehave.core.steps.StepCollector.Stage;
 14  
 
 15  
 /**
 16  
  * A BeforeOrAfterStep is associated to a Java method annotated with
 17  
  * {@link BeforeStory}, {@link AfterStory}, {@link BeforeScenario} or
 18  
  * {@link AfterScenario} in a {@link CandidateSteps} instance class. The
 19  
  * BeforeOrAfterStep is responsible for the creation of the executable step via
 20  
  * the {@link StepCreator}.
 21  
  */
 22  
 public class BeforeOrAfterStep {
 23  
 
 24  
     private final Stage stage;
 25  
     private final Method method;
 26  
     private final StepCreator stepCreator;
 27  
     private final Outcome outcome;
 28  50
     private StepMonitor stepMonitor = new SilentStepMonitor();
 29  
 
 30  
     public BeforeOrAfterStep(Stage stage, Method method, StepCreator stepCreator) {
 31  2
         this(stage, method, Outcome.ANY, stepCreator);
 32  2
     }
 33  
 
 34  50
     public BeforeOrAfterStep(Stage stage, Method method, Outcome outcome, StepCreator stepCreator) {
 35  50
         this.stage = stage;
 36  50
         this.method = method;
 37  50
         this.outcome = outcome;
 38  50
         this.stepCreator = stepCreator;
 39  50
     }
 40  
 
 41  
     public Stage getStage() {
 42  28
         return stage;
 43  
     }
 44  
 
 45  
     public Method getMethod() {
 46  4
         return method;
 47  
     }
 48  
 
 49  
     public Step createStep() {
 50  15
         return createStepWith(Meta.EMPTY);
 51  
     }
 52  
 
 53  
     public Step createStepWith(Meta meta) {
 54  22
         return stepCreator.createBeforeOrAfterStep(method, meta);
 55  
     }
 56  
 
 57  
     public Step createStepUponOutcome(Meta storyAndScenarioMeta) {
 58  14
         return stepCreator.createAfterStepUponOutcome(method, outcome, storyAndScenarioMeta);
 59  
     }
 60  
 
 61  
     public void useStepMonitor(StepMonitor stepMonitor) {
 62  1
         this.stepMonitor = stepMonitor;
 63  1
         this.stepCreator.useStepMonitor(stepMonitor);
 64  1
     }
 65  
 
 66  
     @Override
 67  
     public String toString() {
 68  1
         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append(stage).append(method).append(outcome)
 69  
                 .append(stepMonitor).toString();
 70  
     }
 71  
 }