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