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 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
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 | 18 | private StepMonitor stepMonitor = new SilentStepMonitor(); |
28 | |
|
29 | |
public BeforeOrAfterStep(Stage stage, Method method, Object instance) { |
30 | 12 | this(stage, method, instance, Outcome.ANY); |
31 | 12 | } |
32 | |
|
33 | 18 | public BeforeOrAfterStep(Stage stage, Method method, Object instance, Outcome outcome) { |
34 | 18 | this.stage = stage; |
35 | 18 | this.method = method; |
36 | 18 | this.outcome = outcome; |
37 | 18 | this.stepCreator = new StepCreator(instance, stepMonitor); |
38 | 18 | } |
39 | |
|
40 | |
public Stage getStage() { |
41 | 4 | return stage; |
42 | |
} |
43 | |
|
44 | |
public Method getMethod() { |
45 | 4 | return method; |
46 | |
} |
47 | |
|
48 | |
public Step createStep() { |
49 | 10 | return stepCreator.createBeforeOrAfterStep(method); |
50 | |
} |
51 | |
|
52 | |
public Step createStepUponOutcome() { |
53 | 6 | return stepCreator.createAfterStepUponOutcome(method, outcome); |
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 | |
} |