##### Coverage Report - org.jbehave.core.reporters.PrintStreamStepdocReporter

Classes in this File | Line Coverage | Branch Coverage | Complexity
PrintStreamStepdocReporter |
100% | 26/26
100% | 8/8
| 1.5714285714285714;1.571

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