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