1 | |
package org.jbehave.core.steps; |
2 | |
|
3 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
4 | |
import org.apache.commons.lang.builder.ToStringStyle; |
5 | |
import org.jbehave.core.failures.PendingStepFound; |
6 | |
import org.jbehave.core.model.OutcomesTable.OutcomesFailed; |
7 | |
import org.jbehave.core.reporters.StoryReporter; |
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
public abstract class AbstractStepResult implements StepResult { |
21 | |
|
22 | |
public static class Failed extends AbstractStepResult { |
23 | |
|
24 | |
public Failed(String step, Throwable throwable) { |
25 | 9 | super(step, throwable); |
26 | 9 | } |
27 | |
|
28 | |
public void describeTo(StoryReporter reporter) { |
29 | 6 | if ( throwable instanceof OutcomesFailed ){ |
30 | 1 | reporter.failedOutcomes(parametrisedStep(), ((OutcomesFailed)throwable).outcomesTable()); |
31 | |
} else { |
32 | 5 | reporter.failed(parametrisedStep(), throwable); |
33 | |
} |
34 | 6 | } |
35 | |
} |
36 | |
|
37 | |
public static class NotPerformed extends AbstractStepResult { |
38 | |
|
39 | |
public NotPerformed(String step) { |
40 | 8 | super(step); |
41 | 8 | } |
42 | |
|
43 | |
public void describeTo(StoryReporter reporter) { |
44 | 7 | reporter.notPerformed(parametrisedStep()); |
45 | 7 | } |
46 | |
} |
47 | |
|
48 | |
|
49 | |
public static class Pending extends AbstractStepResult { |
50 | |
public Pending(String step) { |
51 | 12 | this(step, new PendingStepFound(step)); |
52 | 12 | } |
53 | |
|
54 | |
public Pending(String step, PendingStepFound e) { |
55 | 13 | super(step, e); |
56 | 13 | } |
57 | |
|
58 | |
public void describeTo(StoryReporter reporter) { |
59 | 9 | reporter.pending(parametrisedStep()); |
60 | 9 | } |
61 | |
} |
62 | |
|
63 | |
public static class Successful extends AbstractStepResult { |
64 | |
|
65 | |
public Successful(String string) { |
66 | 68 | super(string); |
67 | 68 | } |
68 | |
|
69 | |
public void describeTo(StoryReporter reporter) { |
70 | 15 | reporter.successful(parametrisedStep()); |
71 | 15 | } |
72 | |
|
73 | |
} |
74 | |
|
75 | |
public static class Ignorable extends AbstractStepResult { |
76 | |
public Ignorable(String step) { |
77 | 4 | super(step); |
78 | 4 | } |
79 | |
|
80 | |
public void describeTo(StoryReporter reporter) { |
81 | 1 | reporter.ignorable(step); |
82 | 1 | } |
83 | |
} |
84 | |
|
85 | |
public static class Skipped extends AbstractStepResult { |
86 | |
|
87 | |
public Skipped() { |
88 | 16 | super(""); |
89 | 16 | } |
90 | |
|
91 | |
public void describeTo(StoryReporter reporter) { |
92 | 1 | } |
93 | |
} |
94 | |
|
95 | |
protected final String step; |
96 | |
private String parametrisedStep; |
97 | |
protected final Throwable throwable; |
98 | |
|
99 | |
public AbstractStepResult(String step) { |
100 | 96 | this(step, null); |
101 | 96 | } |
102 | |
|
103 | 118 | public AbstractStepResult(String step, Throwable throwable) { |
104 | 118 | this.step = step; |
105 | 118 | this.throwable = throwable; |
106 | 118 | } |
107 | |
|
108 | |
public String parametrisedStep() { |
109 | 41 | return parametrisedStep != null ? parametrisedStep : step; |
110 | |
} |
111 | |
|
112 | |
public StepResult withParameterValues(String parametrisedStep) { |
113 | 64 | this.parametrisedStep = parametrisedStep; |
114 | 64 | return this; |
115 | |
} |
116 | |
|
117 | |
public Throwable getFailure() { |
118 | 26 | return throwable; |
119 | |
} |
120 | |
|
121 | |
@Override |
122 | |
public String toString() { |
123 | 2 | return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append(parametrisedStep()).toString(); |
124 | |
} |
125 | |
|
126 | |
public static StepResult successful(String step) { |
127 | 68 | return new Successful(step); |
128 | |
} |
129 | |
|
130 | |
public static StepResult ignorable(String step) { |
131 | 4 | return new Ignorable(step); |
132 | |
} |
133 | |
|
134 | |
public static StepResult pending(String step) { |
135 | 12 | return new Pending(step); |
136 | |
} |
137 | |
|
138 | |
public static StepResult pending(String step, PendingStepFound e) { |
139 | 1 | return new Pending(step, e); |
140 | |
} |
141 | |
|
142 | |
public static StepResult notPerformed(String step) { |
143 | 8 | return new NotPerformed(step); |
144 | |
} |
145 | |
|
146 | |
public static StepResult failed(String step, Throwable e) { |
147 | 9 | return new Failed(step, e); |
148 | |
} |
149 | |
|
150 | |
public static StepResult skipped(){ |
151 | 16 | return new Skipped(); |
152 | |
} |
153 | |
|
154 | |
} |