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