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