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