Coverage Report - org.jbehave.core.embedder.PrintStreamEmbedderMonitor
 
Classes in this File Line Coverage Branch Coverage Complexity
PrintStreamEmbedderMonitor
70%
66/94
50%
4/8
1.105
 
 1  
 package org.jbehave.core.embedder;
 2  
 
 3  
 import java.io.File;
 4  
 import java.io.PrintStream;
 5  
 import java.util.List;
 6  
 import java.util.Properties;
 7  
 import java.util.concurrent.ExecutorService;
 8  
 
 9  
 import org.apache.commons.lang.builder.ToStringBuilder;
 10  
 import org.apache.commons.lang.builder.ToStringStyle;
 11  
 import org.jbehave.core.ConfigurableEmbedder;
 12  
 import org.jbehave.core.failures.BatchFailures;
 13  
 import org.jbehave.core.model.Meta;
 14  
 import org.jbehave.core.model.Scenario;
 15  
 import org.jbehave.core.model.Story;
 16  
 import org.jbehave.core.model.StoryDuration;
 17  
 import org.jbehave.core.model.StoryMaps;
 18  
 import org.jbehave.core.reporters.Format;
 19  
 import org.jbehave.core.reporters.ReportsCount;
 20  
 
 21  
 /**
 22  
  * Monitor that reports to a {@link PrintStream}, defaulting to
 23  
  * {@link System.out}
 24  
  */
 25  
 public class PrintStreamEmbedderMonitor extends NullEmbedderMonitor {
 26  
     private PrintStream output;
 27  
 
 28  
     public PrintStreamEmbedderMonitor() {
 29  75
         this(System.out);
 30  75
     }
 31  
 
 32  137
     public PrintStreamEmbedderMonitor(PrintStream output) {
 33  137
         this.output = output;
 34  137
     }
 35  
 
 36  
     public void batchFailed(BatchFailures failures) {
 37  2
         print("Failed to run batch " + failures);
 38  2
     }
 39  
 
 40  
     public void beforeOrAfterStoriesFailed() {
 41  0
         print("Failed to run before or after stories steps");
 42  0
     }
 43  
 
 44  
     public void embeddableFailed(String name, Throwable cause) {
 45  1
         print("Failed to run embeddable " + name);
 46  1
         printStackTrace(cause);
 47  1
     }
 48  
 
 49  
     public void embeddableNotConfigurable(String name) {
 50  0
         print("Embeddable " + name + " must be an instance of " + ConfigurableEmbedder.class);
 51  0
     }
 52  
 
 53  
     public void embeddablesSkipped(List<String> classNames) {
 54  1
         print("Skipped embeddables " + classNames);
 55  1
     }
 56  
 
 57  
     public void metaNotAllowed(Meta meta, MetaFilter filter) {
 58  29
         print(meta + " excluded by filter '" + filter.asString() + "'");
 59  29
     }
 60  
 
 61  
     public void runningEmbeddable(String name) {
 62  31
         print("Running embeddable " + name);
 63  31
     }
 64  
 
 65  
     public void runningStory(String path) {
 66  46
         print("Running story " + path);
 67  46
     }
 68  
 
 69  
     public void storyFailed(String path, Throwable cause) {
 70  5
         print("Failed to run story " + path);
 71  5
         printStackTrace(cause);
 72  5
     }
 73  
 
 74  
     public void storiesSkipped(List<String> storyPaths) {
 75  1
         print("Skipped stories " + storyPaths);
 76  1
     }
 77  
 
 78  
     public void storiesNotAllowed(List<Story> stories, MetaFilter filter, boolean verbose) {
 79  1
         StringBuffer sb = new StringBuffer();
 80  1
         sb.append(stories.size() + " stories excluded by filter: " + filter.asString() + "\n");
 81  1
         if (verbose) {
 82  0
             for (Story story : stories) {
 83  0
                 sb.append(story.getPath()).append("\n");
 84  0
             }
 85  
         }
 86  1
         print(sb.toString());
 87  1
     }
 88  
 
 89  
         public void scenarioNotAllowed(Scenario scenario, MetaFilter filter) {
 90  0
         StringBuffer sb = new StringBuffer();
 91  0
         sb.append("Scenario '"+scenario.getTitle()+"' excluded by filter: " + filter.asString() + "\n");
 92  0
         print(sb.toString());
 93  0
         }
 94  
 
 95  
         public void runningWithAnnotatedEmbedderRunner(String className) {
 96  4
         print("Running with AnnotatedEmbedderRunner '" + className + "'");
 97  4
     }
 98  
 
 99  
     public void annotatedInstanceNotOfType(Object annotatedInstance, Class<?> type) {
 100  1
         print("Annotated instance " + annotatedInstance + " if not of type " + type);
 101  1
     }
 102  
 
 103  
     public void generatingReportsView(File outputDirectory, List<String> formats, Properties viewProperties) {
 104  29
         print("Generating reports view to '" + outputDirectory + "' using formats '" + formats + "'"
 105  
                 + " and view properties '" + viewProperties + "'");
 106  29
     }
 107  
 
 108  
     public void reportsViewGenerationFailed(File outputDirectory, List<String> formats, Properties viewProperties,
 109  
             Throwable cause) {
 110  1
         print("Failed to generate reports view to '" + outputDirectory + "' using formats '" + formats
 111  
                 + "' and view properties '" + viewProperties + "'");
 112  1
     }
 113  
 
 114  
     public void reportsViewGenerated(ReportsCount count) {
 115  56
         print("Reports view generated with " + count.getStories() + " stories (of which " + count.getStoriesPending()
 116  28
                 + " pending) containing " + count.getScenarios() + " scenarios (of which " + count.getScenariosPending() + " pending)");
 117  28
         if (count.getStoriesNotAllowed() > 0 || count.getScenariosNotAllowed() > 0) {
 118  4
             print("Meta filters excluded " + count.getStoriesNotAllowed() + " stories and  "
 119  2
                     + count.getScenariosNotAllowed() + " scenarios");
 120  
         }
 121  28
     }
 122  
 
 123  
     public void reportsViewFailures(ReportsCount count) {
 124  1
         print("Failures in reports view: " + count.getScenariosFailed() + " scenarios failed");
 125  1
     }
 126  
 
 127  
     public void reportsViewNotGenerated() {
 128  1
         print("Reports view not generated");
 129  1
     }
 130  
 
 131  
     public void mappingStory(String storyPath, List<String> metaFilters) {
 132  2
         print("Mapping story " + storyPath + " with meta filters " + metaFilters);
 133  2
     }
 134  
 
 135  
     public void generatingMapsView(File outputDirectory, StoryMaps storyMaps, Properties viewProperties) {
 136  1
         print("Generating maps view to '" + outputDirectory + "' using story maps '" + storyMaps + "'"
 137  
                 + " and view properties '" + viewProperties + "'");
 138  1
     }
 139  
 
 140  
     public void mapsViewGenerationFailed(File outputDirectory, StoryMaps storyMaps, Properties viewProperties,
 141  
             Throwable cause) {
 142  0
         print("Failed to generating maps view to '" + outputDirectory + "' using story maps '" + storyMaps + "'"
 143  
                 + " and view properties '" + viewProperties + "'");
 144  0
         printStackTrace(cause);
 145  0
     }
 146  
 
 147  
     public void generatingNavigatorView(File outputDirectory, Properties viewProperties) {
 148  0
         print("Generating navigator view to '" + outputDirectory + "' using view properties '" + viewProperties + "'");
 149  0
     }
 150  
 
 151  
     public void navigatorViewGenerationFailed(File outputDirectory, Properties viewProperties, Throwable cause) {
 152  0
         print("Failed to generating navigator view to '" + outputDirectory + "' using view properties '"
 153  
                 + viewProperties + "'");
 154  0
         printStackTrace(cause);
 155  0
     }
 156  
 
 157  
     public void navigatorViewNotGenerated() {
 158  0
         print("Navigator view not generated, as the CrossReference has not been declared in the StoryReporterBuilder");
 159  0
     }
 160  
 
 161  
     public void processingSystemProperties(Properties properties) {
 162  26
         print("Processing system properties " + properties);
 163  26
     }
 164  
 
 165  
     public void systemPropertySet(String name, String value) {
 166  2
         print("System property '" + name + "' set to '" + value + "'");
 167  2
     }
 168  
 
 169  
     public void storyTimeout(Story story, StoryDuration storyDuration) {
 170  18
         print("Story " + story.getPath() + " duration of " + storyDuration.getDurationInSecs()
 171  9
                 + " seconds has exceeded timeout of " + storyDuration.getTimeoutInSecs() + " seconds");
 172  9
     }
 173  
 
 174  
     public void usingThreads(int threads) {
 175  0
         print("Using " + threads + " threads");
 176  0
     }
 177  
 
 178  
     public void usingExecutorService(ExecutorService executorService) {
 179  0
         print("Using executor service " + executorService);
 180  0
     }
 181  
 
 182  
     public void usingControls(EmbedderControls embedderControls) {
 183  50
         print("Using controls " + embedderControls);
 184  50
     }
 185  
     
 186  
     
 187  
     public void invalidTimeoutFormat(String path) {
 188  0
             print("Failed to set specific story timeout for story " + path + " because 'storyTimeoutInSecsByPath' has incorrect format");
 189  0
             print("'storyTimeoutInSecsByPath' must be a CSV of regex expressions matching story paths. E.g. \"*/long/*.story:5000,*/short/*.story:200\"");
 190  0
     }
 191  
 
 192  
     public void usingTimeout(String path, long timeout) {
 193  26
             print("Using timeout for story " + path + " of "+timeout+" secs.");
 194  26
     }
 195  
 
 196  
      @Override
 197  
     public String toString() {
 198  2
         return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
 199  
     }
 200  
 
 201  
     protected void print(String message) {
 202  283
         Format.println(output, message);
 203  283
     }
 204  
 
 205  
     protected void printStackTrace(Throwable e) {
 206  6
         e.printStackTrace(output);
 207  6
     }
 208  
 
 209  
 }