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