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