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