1 | |
package org.jbehave.core.reporters; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.List; |
5 | |
import java.util.Map; |
6 | |
|
7 | |
import org.jbehave.core.model.ExamplesTable; |
8 | |
import org.jbehave.core.model.GivenStories; |
9 | |
import org.jbehave.core.model.Lifecycle; |
10 | |
import org.jbehave.core.model.Meta; |
11 | |
import org.jbehave.core.model.Narrative; |
12 | |
import org.jbehave.core.model.OutcomesTable; |
13 | |
import org.jbehave.core.model.Scenario; |
14 | |
import org.jbehave.core.model.Story; |
15 | |
import org.jbehave.core.model.StoryDuration; |
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | 33 | public class SilentSuccessFilter implements StoryReporter { |
22 | |
|
23 | |
private final StoryReporter delegate; |
24 | 3 | private State runState = State.SILENT; |
25 | 3 | private State beforeStoryState = State.SILENT; |
26 | 3 | private State afterStoryState = State.SILENT; |
27 | 3 | private State scenarioState = State.SILENT; |
28 | 3 | private List<Todo> scenarioTodos = new ArrayList<Todo>(); |
29 | |
private boolean givenStory; |
30 | |
|
31 | 3 | public SilentSuccessFilter(StoryReporter delegate) { |
32 | 3 | this.delegate = delegate; |
33 | 3 | } |
34 | |
|
35 | |
public void dryRun() { |
36 | 1 | runState = new State(){ |
37 | |
public void report(){ |
38 | 1 | delegate.dryRun(); |
39 | 1 | } |
40 | |
}; |
41 | 1 | runState.report(); |
42 | 1 | } |
43 | |
|
44 | |
public void pendingMethods(final List<String> methods) { |
45 | 0 | runState = new State(){ |
46 | |
public void report(){ |
47 | 0 | delegate.pendingMethods(methods); |
48 | 0 | } |
49 | |
}; |
50 | 0 | runState.report(); |
51 | 0 | } |
52 | |
|
53 | |
public void restarted(String step, Throwable cause) { |
54 | 0 | } |
55 | |
|
56 | |
public void restartedStory(Story story, Throwable cause) { |
57 | 0 | } |
58 | |
|
59 | |
public void storyCancelled(Story story, StoryDuration storyDuration) { |
60 | 0 | } |
61 | |
|
62 | |
public void beforeStory(final Story story, final boolean givenStory) { |
63 | 1 | this.givenStory = givenStory; |
64 | 1 | beforeStoryState = new State() { |
65 | |
public void report() { |
66 | 1 | delegate.beforeStory(story, givenStory); |
67 | 1 | beforeStoryState = State.SILENT; |
68 | 1 | } |
69 | |
}; |
70 | 1 | } |
71 | |
|
72 | |
public void narrative(final Narrative narrative) { |
73 | 0 | beforeStoryState = new State() { |
74 | |
public void report() { |
75 | 0 | delegate.narrative(narrative); |
76 | 0 | } |
77 | |
}; |
78 | 0 | beforeStoryState.report(); |
79 | 0 | } |
80 | |
|
81 | |
public void lifecyle(final Lifecycle lifecycle) { |
82 | 0 | beforeStoryState = new State() { |
83 | |
public void report() { |
84 | 0 | delegate.lifecyle(lifecycle); |
85 | 0 | } |
86 | |
}; |
87 | 0 | beforeStoryState.report(); |
88 | 0 | } |
89 | |
|
90 | |
public void storyNotAllowed(final Story story, final String filter) { |
91 | 1 | beforeStoryState = new State() { |
92 | |
public void report() { |
93 | 1 | delegate.storyNotAllowed(story, filter); |
94 | 1 | } |
95 | |
}; |
96 | 1 | beforeStoryState.report(); |
97 | 1 | } |
98 | |
|
99 | |
public void afterStory(boolean givenStory) { |
100 | 1 | afterStoryState.report(); |
101 | 1 | } |
102 | |
|
103 | |
public void beforeStep(String step) { |
104 | 0 | } |
105 | |
|
106 | |
public void ignorable(final String step) { |
107 | 2 | scenarioTodos.add(new Todo() { |
108 | |
public void doNow() { |
109 | 1 | delegate.ignorable(step); |
110 | 1 | } |
111 | |
}); |
112 | 2 | } |
113 | |
|
114 | |
public void failed(final String step, final Throwable cause) { |
115 | 1 | scenarioTodos.add(new Todo() { |
116 | |
public void doNow() { |
117 | 1 | delegate.failed(step, cause); |
118 | 1 | } |
119 | |
}); |
120 | 1 | setStateToNoisy(); |
121 | 1 | } |
122 | |
|
123 | |
public void failedOutcomes(final String step, final OutcomesTable table) { |
124 | 1 | scenarioTodos.add(new Todo() { |
125 | |
public void doNow() { |
126 | 1 | delegate.failedOutcomes(step, table); |
127 | 1 | } |
128 | |
}); |
129 | 1 | setStateToNoisy(); |
130 | 1 | } |
131 | |
|
132 | |
public void notPerformed(final String step) { |
133 | 1 | scenarioTodos.add(new Todo() { |
134 | |
public void doNow() { |
135 | 1 | delegate.notPerformed(step); |
136 | 1 | } |
137 | |
}); |
138 | 1 | setStateToNoisy(); |
139 | 1 | } |
140 | |
|
141 | |
public void pending(final String step) { |
142 | 1 | scenarioTodos.add(new Todo() { |
143 | |
public void doNow() { |
144 | 1 | delegate.pending(step); |
145 | 1 | } |
146 | |
}); |
147 | 1 | setStateToNoisy(); |
148 | 1 | } |
149 | |
|
150 | |
public void successful(final String step) { |
151 | 9 | scenarioTodos.add(new Todo() { |
152 | |
public void doNow() { |
153 | 3 | delegate.successful(step); |
154 | 3 | } |
155 | |
}); |
156 | 9 | } |
157 | |
|
158 | |
public void afterScenario() { |
159 | 4 | scenarioTodos.add(new Todo() { |
160 | |
public void doNow() { |
161 | 2 | delegate.afterScenario(); |
162 | 2 | } |
163 | |
}); |
164 | 4 | scenarioState.report(); |
165 | 4 | } |
166 | |
|
167 | |
public void beforeScenario(final String scenarioTitle) { |
168 | 4 | scenarioTodos = new ArrayList<Todo>(); |
169 | 4 | scenarioTodos.add(new Todo() { |
170 | |
public void doNow() { |
171 | 2 | delegate.beforeScenario(scenarioTitle); |
172 | 2 | } |
173 | |
}); |
174 | 4 | } |
175 | |
|
176 | |
public void scenarioNotAllowed(final Scenario scenario, final String filter) { |
177 | 1 | scenarioState = new State() { |
178 | |
public void report() { |
179 | 1 | delegate.scenarioNotAllowed(scenario, filter); |
180 | 1 | } |
181 | |
}; |
182 | 1 | scenarioState.report(); |
183 | 1 | } |
184 | |
|
185 | |
public void scenarioMeta(final Meta meta) { |
186 | 1 | scenarioTodos = new ArrayList<Todo>(); |
187 | 1 | scenarioTodos.add(new Todo() { |
188 | |
public void doNow() { |
189 | 0 | delegate.scenarioMeta(meta); |
190 | 0 | } |
191 | |
}); |
192 | 1 | } |
193 | |
|
194 | |
public void givenStories(final GivenStories givenStories) { |
195 | 1 | scenarioTodos.add(new Todo() { |
196 | |
public void doNow() { |
197 | 1 | delegate.givenStories(givenStories); |
198 | 1 | } |
199 | |
}); |
200 | 1 | } |
201 | |
|
202 | |
public void givenStories(final List<String> storyPaths) { |
203 | 1 | scenarioTodos.add(new Todo() { |
204 | |
public void doNow() { |
205 | 1 | delegate.givenStories(storyPaths); |
206 | 1 | } |
207 | |
}); |
208 | 1 | } |
209 | |
|
210 | |
public void beforeExamples(final List<String> steps, final ExamplesTable table) { |
211 | 1 | scenarioTodos.add(new Todo() { |
212 | |
public void doNow() { |
213 | 1 | delegate.beforeExamples(steps, table); |
214 | 1 | } |
215 | |
}); |
216 | 1 | } |
217 | |
|
218 | |
public void example(final Map<String, String> tableRow) { |
219 | 1 | scenarioTodos.add(new Todo() { |
220 | |
public void doNow() { |
221 | 1 | delegate.example(tableRow); |
222 | 1 | } |
223 | |
}); |
224 | 1 | } |
225 | |
|
226 | |
public void afterExamples() { |
227 | 1 | scenarioTodos.add(new Todo() { |
228 | |
public void doNow() { |
229 | 1 | delegate.afterExamples(); |
230 | 1 | } |
231 | |
}); |
232 | 1 | } |
233 | |
|
234 | |
private static interface Todo { |
235 | |
void doNow(); |
236 | |
} |
237 | |
|
238 | |
private interface State { |
239 | 1 | State SILENT = new State() { |
240 | |
public void report() { |
241 | 3 | } |
242 | |
}; |
243 | |
|
244 | |
void report(); |
245 | |
} |
246 | |
|
247 | |
private void setStateToNoisy() { |
248 | 4 | scenarioState = new State() { |
249 | |
public void report() { |
250 | 2 | beforeStoryState.report(); |
251 | 2 | for (Todo todo : scenarioTodos) { |
252 | 17 | todo.doNow(); |
253 | 17 | } |
254 | 2 | afterStoryState = new State() { |
255 | |
public void report() { |
256 | 1 | delegate.afterStory(givenStory); |
257 | 1 | afterStoryState = State.SILENT; |
258 | 1 | } |
259 | |
}; |
260 | 2 | scenarioState = State.SILENT; |
261 | 2 | } |
262 | |
}; |
263 | 4 | } |
264 | |
|
265 | |
} |