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