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