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