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 ignorable(final String step) { |
92 | 2 | scenarioTodos.add(new Todo() { |
93 | |
public void doNow() { |
94 | 1 | delegate.ignorable(step); |
95 | 1 | } |
96 | |
}); |
97 | 2 | } |
98 | |
|
99 | |
public void failed(final String step, final Throwable cause) { |
100 | 1 | scenarioTodos.add(new Todo() { |
101 | |
public void doNow() { |
102 | 1 | delegate.failed(step, cause); |
103 | 1 | } |
104 | |
}); |
105 | 1 | setStateToNoisy(); |
106 | 1 | } |
107 | |
|
108 | |
public void failedOutcomes(final String step, final OutcomesTable table) { |
109 | 1 | scenarioTodos.add(new Todo() { |
110 | |
public void doNow() { |
111 | 1 | delegate.failedOutcomes(step, table); |
112 | 1 | } |
113 | |
}); |
114 | 1 | setStateToNoisy(); |
115 | 1 | } |
116 | |
|
117 | |
public void notPerformed(final String step) { |
118 | 1 | scenarioTodos.add(new Todo() { |
119 | |
public void doNow() { |
120 | 1 | delegate.notPerformed(step); |
121 | 1 | } |
122 | |
}); |
123 | 1 | setStateToNoisy(); |
124 | 1 | } |
125 | |
|
126 | |
public void pending(final String step) { |
127 | 1 | scenarioTodos.add(new Todo() { |
128 | |
public void doNow() { |
129 | 1 | delegate.pending(step); |
130 | 1 | } |
131 | |
}); |
132 | 1 | setStateToNoisy(); |
133 | 1 | } |
134 | |
|
135 | |
public void successful(final String step) { |
136 | 9 | scenarioTodos.add(new Todo() { |
137 | |
public void doNow() { |
138 | 3 | delegate.successful(step); |
139 | 3 | } |
140 | |
}); |
141 | 9 | } |
142 | |
|
143 | |
public void afterScenario() { |
144 | 4 | scenarioTodos.add(new Todo() { |
145 | |
public void doNow() { |
146 | 2 | delegate.afterScenario(); |
147 | 2 | } |
148 | |
}); |
149 | 4 | scenarioState.report(); |
150 | 4 | } |
151 | |
|
152 | |
public void beforeScenario(final String scenarioTitle) { |
153 | 4 | scenarioTodos = new ArrayList<Todo>(); |
154 | 4 | scenarioTodos.add(new Todo() { |
155 | |
public void doNow() { |
156 | 2 | delegate.beforeScenario(scenarioTitle); |
157 | 2 | } |
158 | |
}); |
159 | 4 | } |
160 | |
|
161 | |
public void scenarioNotAllowed(final Scenario scenario, final String filter) { |
162 | 1 | scenarioState = new State() { |
163 | |
public void report() { |
164 | 1 | delegate.scenarioNotAllowed(scenario, filter); |
165 | 1 | } |
166 | |
}; |
167 | 1 | scenarioState.report(); |
168 | 1 | } |
169 | |
|
170 | |
public void scenarioMeta(final Meta meta) { |
171 | 1 | scenarioTodos = new ArrayList<Todo>(); |
172 | 1 | scenarioTodos.add(new Todo() { |
173 | |
public void doNow() { |
174 | 0 | delegate.scenarioMeta(meta); |
175 | 0 | } |
176 | |
}); |
177 | 1 | } |
178 | |
|
179 | |
public void givenStories(final GivenStories givenStories) { |
180 | 1 | scenarioTodos.add(new Todo() { |
181 | |
public void doNow() { |
182 | 1 | delegate.givenStories(givenStories); |
183 | 1 | } |
184 | |
}); |
185 | 1 | } |
186 | |
|
187 | |
public void givenStories(final List<String> storyPaths) { |
188 | 1 | scenarioTodos.add(new Todo() { |
189 | |
public void doNow() { |
190 | 1 | delegate.givenStories(storyPaths); |
191 | 1 | } |
192 | |
}); |
193 | 1 | } |
194 | |
|
195 | |
public void beforeExamples(final List<String> steps, final ExamplesTable table) { |
196 | 1 | scenarioTodos.add(new Todo() { |
197 | |
public void doNow() { |
198 | 1 | delegate.beforeExamples(steps, table); |
199 | 1 | } |
200 | |
}); |
201 | 1 | } |
202 | |
|
203 | |
public void example(final Map<String, String> tableRow) { |
204 | 1 | scenarioTodos.add(new Todo() { |
205 | |
public void doNow() { |
206 | 1 | delegate.example(tableRow); |
207 | 1 | } |
208 | |
}); |
209 | 1 | } |
210 | |
|
211 | |
public void afterExamples() { |
212 | 1 | scenarioTodos.add(new Todo() { |
213 | |
public void doNow() { |
214 | 1 | delegate.afterExamples(); |
215 | 1 | } |
216 | |
}); |
217 | 1 | } |
218 | |
|
219 | |
private static interface Todo { |
220 | |
void doNow(); |
221 | |
} |
222 | |
|
223 | |
private interface State { |
224 | 1 | State SILENT = new State() { |
225 | |
public void report() { |
226 | 3 | } |
227 | |
}; |
228 | |
|
229 | |
void report(); |
230 | |
} |
231 | |
|
232 | |
private void setStateToNoisy() { |
233 | 4 | scenarioState = new State() { |
234 | |
public void report() { |
235 | 2 | beforeStoryState.report(); |
236 | 2 | for (Todo todo : scenarioTodos) { |
237 | 17 | todo.doNow(); |
238 | |
} |
239 | 2 | afterStoryState = new State() { |
240 | |
public void report() { |
241 | 1 | delegate.afterStory(givenStory); |
242 | 1 | afterStoryState = State.SILENT; |
243 | 1 | } |
244 | |
}; |
245 | 2 | scenarioState = State.SILENT; |
246 | 2 | } |
247 | |
}; |
248 | 4 | } |
249 | |
|
250 | |
} |