Coverage Report - org.jbehave.core.steps.PrintStreamStepMonitor
 
Classes in this File Line Coverage Branch Coverage Complexity
PrintStreamStepMonitor
100%
29/29
100%
6/6
1.231
 
 1  
 package org.jbehave.core.steps;
 2  
 
 3  
 import java.io.PrintStream;
 4  
 import java.lang.reflect.Method;
 5  
 import java.lang.reflect.Type;
 6  
 
 7  
 import org.jbehave.core.model.StepPattern;
 8  
 
 9  
 import static java.text.MessageFormat.format;
 10  
 import static java.util.Arrays.asList;
 11  
 
 12  
 /**
 13  
  * StepMonitor that prints to a {@link PrintStream}, defaulting to
 14  
  * {@link System.out}.
 15  
  */
 16  
 public class PrintStreamStepMonitor implements StepMonitor {
 17  
 
 18  
         private static final String CONVERTED_VALUE_OF_TYPE = "Converted value ''{0}'' of type ''{1}'' to ''{2}'' with converter ''{3}''";
 19  
         private static final String STEP_MATCHES_TYPE = "Step ''{0}'' (with previous step ''{1}'') ''{2}'' type ''{3}'' for method ''{4}'' with annotations ''{5}'' in steps instance ''{6}''";
 20  
         private static final String STEP_MATCHES_PATTERN = "Step ''{0}'' {1} pattern ''{2}'' for method ''{3}'' with annotations ''{4}'' in steps instance ''{5}''";
 21  
         private static final String PERFORMING = "Performing step ''{0}'' {1}";
 22  
         private static final String DRY_RUN = "(DRY RUN)";
 23  
         private static final String MATCHES = "matches";
 24  
         private static final String DOES_NOT_MATCH = "does not match";
 25  
         private static final String USING_NAME_FOR_PARAMETER = "Using {0} name ''{1}'' for parameter position {2}";
 26  
         private static final String ANNOTATED = "annotated";
 27  
         private static final String PARAMETER = "parameter";
 28  
         private static final String TABLE_ANNOTATED = "table annotated";
 29  
         private static final String TABLE_PARAMETER = "table parameter";
 30  
         private static final String USING_NATURAL_ORDER_FOR_PARAMETER = "Using natural order for parameter position {0}";
 31  
         private static final String FOUND_PARAMETER = "Found parameter ''{0}'' for position {1}";
 32  
 
 33  
         private final PrintStream output;
 34  
 
 35  
         public PrintStreamStepMonitor() {
 36  1362
                 this(System.out);
 37  1362
         }
 38  
 
 39  1363
         public PrintStreamStepMonitor(PrintStream output) {
 40  1363
                 this.output = output;
 41  1363
         }
 42  
 
 43  
         public void stepMatchesType(String step, String previous, boolean matches,
 44  
                         StepType stepType, Method method, Object stepsInstance) {
 45  14
                 String message = format(STEP_MATCHES_TYPE, step, previous,
 46  
                                 (matches ? MATCHES : DOES_NOT_MATCH), stepType, method,
 47  
                                 asList(method.getAnnotations()), stepsInstance);
 48  14
                 print(output, message);
 49  14
         }
 50  
 
 51  
         public void stepMatchesPattern(String step, boolean matches,
 52  
                         StepPattern stepPattern, Method method, Object stepsInstance) {
 53  10
                 String message = format(STEP_MATCHES_PATTERN, step, (matches ? MATCHES
 54  
                                 : DOES_NOT_MATCH), stepPattern, method, asList(method
 55  
                                 .getAnnotations()), stepsInstance);
 56  10
                 print(output, message);
 57  10
         }
 58  
 
 59  
         public void convertedValueOfType(String value, Type type, Object converted,
 60  
                         Class<?> converterClass) {
 61  27
                 print(output, format(CONVERTED_VALUE_OF_TYPE, value, type,
 62  
                                 converted, converterClass));
 63  27
         }
 64  
 
 65  
         public void performing(String step, boolean dryRun) {
 66  60
                 print(output, format(PERFORMING, step, (dryRun ? DRY_RUN : "")));
 67  60
         }
 68  
 
 69  
         public void usingAnnotatedNameForParameter(String name, int position) {
 70  10
                 print(output, format(USING_NAME_FOR_PARAMETER, ANNOTATED, name, position));
 71  10
         }
 72  
 
 73  
         public void usingParameterNameForParameter(String name, int position) {
 74  4
                 print(output, format(USING_NAME_FOR_PARAMETER, PARAMETER, name, position));
 75  4
         }
 76  
 
 77  
         public void usingTableAnnotatedNameForParameter(String name, int position) {
 78  8
                 print(output, format(USING_NAME_FOR_PARAMETER, TABLE_ANNOTATED, name,
 79  
                                 position));
 80  8
         }
 81  
 
 82  
         public void usingTableParameterNameForParameter(String name, int position) {
 83  2
                 print(output, format(USING_NAME_FOR_PARAMETER, TABLE_PARAMETER, name,
 84  
                                 position));
 85  2
         }
 86  
 
 87  
         public void usingNaturalOrderForParameter(int position) {
 88  24
                 print(output, format(USING_NATURAL_ORDER_FOR_PARAMETER, position));
 89  24
         }
 90  
 
 91  
         public void foundParameter(String parameter, int position) {
 92  47
                 print(output, format(FOUND_PARAMETER, parameter, position));
 93  47
         }
 94  
 
 95  
         protected void print(PrintStream output, String message) {
 96  2
                 output.println(message);
 97  2
         }
 98  
 
 99  
 }