Coverage Report - org.jbehave.core.reporters.PrintStreamStepdocReporter
 
Classes in this File Line Coverage Branch Coverage Complexity
PrintStreamStepdocReporter
100%
26/26
100%
8/8
1.571
 
 1  
 package org.jbehave.core.reporters;
 2  
 
 3  
 import static java.text.MessageFormat.format;
 4  
 
 5  
 import java.io.PrintStream;
 6  
 import java.util.List;
 7  
 
 8  
 import org.jbehave.core.steps.Stepdoc;
 9  
 
 10  
 public class PrintStreamStepdocReporter implements StepdocReporter {
 11  
 
 12  
         private static final String STEP_MATCHED_BY = "Step ''{0}'' is matched by annotated patterns:";
 13  
         private static final String STEP_NOT_MATCHED = "Step ''{0}'' is not matched by any pattern";
 14  
         private static final String STEPDOC = "''{0} {1}''";
 15  
         
 16  
         private PrintStream output;
 17  
 
 18  
         public PrintStreamStepdocReporter() {
 19  450
                 this(System.out);
 20  450
         }
 21  
 
 22  454
         public PrintStreamStepdocReporter(PrintStream output) {
 23  454
                 this.output = output;
 24  454
         }
 25  
 
 26  
         public void stepdocsMatching(String stepAsString,
 27  
                         List<Stepdoc> stepdocs, List<Object> stepsInstances) {
 28  3
                 if (stepdocs.size() > 0) {
 29  1
                         output(format(STEP_MATCHED_BY, stepAsString));
 30  1
                         outputStepdocs(stepdocs);
 31  
                 } else {
 32  2
                         output(format(STEP_NOT_MATCHED, stepAsString));
 33  
                 }
 34  3
                 outputStepsInstances(stepsInstances);
 35  3
         }
 36  
 
 37  
         public void stepdocs(List<Stepdoc> stepdocs, List<Object> stepsInstances) {
 38  1
             outputStepdocs(stepdocs);
 39  1
                 outputStepsInstances(stepsInstances);
 40  1
         }
 41  
 
 42  
         private void outputStepdocs(List<Stepdoc> stepdocs) {
 43  2
                 for (Stepdoc stepdoc : stepdocs) {
 44  4
                         output(format(STEPDOC, stepdoc.getStartingWord(), stepdoc.getPattern()));
 45  4
                         output(stepdoc.getMethodSignature());
 46  
                 }
 47  2
         }
 48  
         
 49  
         private void outputStepsInstances(List<Object> stepsInstances) {
 50  4
                 if (stepsInstances.size() > 0) {
 51  3
                         output("from steps instances:");
 52  3
                         for (Object stepsInstance : stepsInstances) {
 53  3
                                 output(stepsInstance.getClass().getName());
 54  
                         }
 55  
                 } else {
 56  1
                         output("as no steps instances are provided");                        
 57  
                 }
 58  4
         }
 59  
         
 60  
         private void output(Object object) {
 61  18
                 output.println(object);
 62  18
         }
 63  
 
 64  
 }