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