| 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 | |
import org.jbehave.core.model.StepPattern; |
| 7 | |
import org.jbehave.core.reporters.Format; |
| 8 | |
|
| 9 | |
import static java.text.MessageFormat.format; |
| 10 | |
import static java.util.Arrays.asList; |
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | 752 | this(System.out); |
| 37 | 752 | } |
| 38 | |
|
| 39 | 753 | public PrintStreamStepMonitor(PrintStream output) { |
| 40 | 753 | this.output = output; |
| 41 | 753 | } |
| 42 | |
|
| 43 | |
public void stepMatchesType(String step, String previous, boolean matches, |
| 44 | |
StepType stepType, Method method, Object stepsInstance) { |
| 45 | 68 | String message = format(STEP_MATCHES_TYPE, step, previous, |
| 46 | |
(matches ? MATCHES : DOES_NOT_MATCH), stepType, method, |
| 47 | |
asList(method.getAnnotations()), stepsInstance); |
| 48 | 68 | print(output, message); |
| 49 | 68 | } |
| 50 | |
|
| 51 | |
public void stepMatchesPattern(String step, boolean matches, |
| 52 | |
StepPattern stepPattern, Method method, Object stepsInstance) { |
| 53 | 62 | String message = format(STEP_MATCHES_PATTERN, step, (matches ? MATCHES |
| 54 | |
: DOES_NOT_MATCH), stepPattern, method, asList(method |
| 55 | |
.getAnnotations()), stepsInstance); |
| 56 | 62 | print(output, message); |
| 57 | 62 | } |
| 58 | |
|
| 59 | |
public void convertedValueOfType(String value, Type type, Object converted, |
| 60 | |
Class<?> converterClass) { |
| 61 | 45 | print(output, format(CONVERTED_VALUE_OF_TYPE, value, type, |
| 62 | |
converted, converterClass)); |
| 63 | 45 | } |
| 64 | |
|
| 65 | |
public void performing(String step, boolean dryRun) { |
| 66 | 84 | print(output, format(PERFORMING, step, (dryRun ? DRY_RUN : ""))); |
| 67 | 84 | } |
| 68 | |
|
| 69 | |
public void usingAnnotatedNameForParameter(String name, int position) { |
| 70 | 27 | print(output, format(USING_NAME_FOR_PARAMETER, ANNOTATED, name, position)); |
| 71 | 27 | } |
| 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 | 19 | print(output, format(USING_NAME_FOR_PARAMETER, TABLE_ANNOTATED, name, |
| 79 | |
position)); |
| 80 | 19 | } |
| 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 | 31 | print(output, format(USING_NATURAL_ORDER_FOR_PARAMETER, position)); |
| 89 | 31 | } |
| 90 | |
|
| 91 | |
public void foundParameter(String parameter, int position) { |
| 92 | 73 | print(output, format(FOUND_PARAMETER, parameter, position)); |
| 93 | 73 | } |
| 94 | |
|
| 95 | |
protected void print(PrintStream output, String message) { |
| 96 | 2 | Format.println(output, message); |
| 97 | 2 | } |
| 98 | |
|
| 99 | |
} |