Coverage Report - org.jbehave.core.reporters.SilentSuccessFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
SilentSuccessFilter
86%
60/69
N/A
1.02
SilentSuccessFilter$1
100%
3/3
N/A
1.02
SilentSuccessFilter$10
100%
3/3
N/A
1.02
SilentSuccessFilter$11
100%
3/3
N/A
1.02
SilentSuccessFilter$12
100%
3/3
N/A
1.02
SilentSuccessFilter$13
100%
3/3
N/A
1.02
SilentSuccessFilter$14
100%
3/3
N/A
1.02
SilentSuccessFilter$15
33%
1/3
N/A
1.02
SilentSuccessFilter$16
100%
3/3
N/A
1.02
SilentSuccessFilter$17
100%
3/3
N/A
1.02
SilentSuccessFilter$18
100%
3/3
N/A
1.02
SilentSuccessFilter$19
100%
3/3
N/A
1.02
SilentSuccessFilter$2
0%
0/3
N/A
1.02
SilentSuccessFilter$20
100%
3/3
N/A
1.02
SilentSuccessFilter$21
100%
7/7
100%
2/2
1.02
SilentSuccessFilter$21$1
100%
4/4
N/A
1.02
SilentSuccessFilter$3
100%
4/4
N/A
1.02
SilentSuccessFilter$4
0%
0/3
N/A
1.02
SilentSuccessFilter$5
100%
3/3
N/A
1.02
SilentSuccessFilter$6
100%
3/3
N/A
1.02
SilentSuccessFilter$7
100%
3/3
N/A
1.02
SilentSuccessFilter$8
100%
3/3
N/A
1.02
SilentSuccessFilter$9
100%
3/3
N/A
1.02
SilentSuccessFilter$State
N/A
N/A
1.02
SilentSuccessFilter$State$1
100%
2/2
N/A
1.02
SilentSuccessFilter$Todo
N/A
N/A
1.02
 
 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  
  * Filters out the reports from all stories that pass, The delegate receives
 18  
  * output only for failing or pending stories.
 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  
 }