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