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

Classes in this File | Line Coverage | Branch Coverage | Complexity
Format |
93% | 15/16
N/A | N/A
| 1.0;1
Format$1 |
100% | 2/2
N/A | N/A
| 1.0;1
Format$2 |
50% | 1/2
N/A | N/A
| 1.0;1
Format$3 |
100% | 2/2
N/A | N/A
| 1.0;1
Format$4 |
100% | 3/3
N/A | N/A
| 1.0;1
Format$5 |
100% | 3/3
N/A | N/A
| 1.0;1
Format$6 |
33% | 1/3
N/A | N/A
| 1.0;1
Format$7 |
100% | 3/3
N/A | N/A
| 1.0;1
Format$8 |
33% | 1/3
N/A | N/A
| 1.0;1
Format$9 |
100% | 3/3
N/A | N/A
| 1.0;1

1 |  |
     package org.jbehave.core.reporters;
2 |  |
3 |  |
     import java.io.PrintStream;
4 |  |
5 |  |
     import org.jbehave.core.reporters.StoryReporterBuilder.ProvidedFormat;
6 |  |
7 |  |
     /**
8 |  |
      * A Format is a {@link StoryReporter} factory, allowing named-based pre-defined
9 |  |
      * story reporters to be configured via the
10 |  |
      * {@link StoryReporterBuilder#withFormats(Format...)} method. Users wanting to
11 |  |
      * configure their custom defined story reporters, can do so via the
12 |  |
      * {@link StoryReporterBuilder#withReporters(StoryReporter...)} method, or use
13 |  |
      * the {@link ProvidedFormat} wrapper.
14 |  |
      */
15 |  |
     public abstract class Format {
16 |  |
17 | 1 |
         public static final Format CONSOLE = new Format("CONSOLE") {
18 |  |
             @Override
19 |  |
             public StoryReporter createStoryReporter(FilePrintStreamFactory factory,
20 |  |
                     StoryReporterBuilder storyReporterBuilder) {
21 | 6 |
                 return new ConsoleOutput(storyReporterBuilder.keywords()).doReportFailureTrace(
22 |  |
                         storyReporterBuilder.reportFailureTrace()).doCompressFailureTrace(
23 |  |
                         storyReporterBuilder.compressFailureTrace());
24 |  |
             }
25 |  |
         };
26 |  |
27 | 1 |
         public static final Format ANSI_CONSOLE = new Format("ANSI_CONSOLE") {
28 |  |
             @Override
29 |  |
             public StoryReporter createStoryReporter(FilePrintStreamFactory factory,
30 |  |
                     StoryReporterBuilder storyReporterBuilder) {
31 | 0 |
                 return new ANSIConsoleOutput(storyReporterBuilder.keywords()).doReportFailureTrace(
32 |  |
                         storyReporterBuilder.reportFailureTrace()).doCompressFailureTrace(
33 |  |
                         storyReporterBuilder.compressFailureTrace());
34 |  |
             }
35 |  |
         };
36 |  |
37 | 1 |
         public static final Format IDE_CONSOLE = new Format("IDE_CONSOLE") {
38 |  |
             @Override
39 |  |
             public StoryReporter createStoryReporter(FilePrintStreamFactory factory,
40 |  |
                     StoryReporterBuilder storyReporterBuilder) {
41 | 2 |
                 return new IdeOnlyConsoleOutput(storyReporterBuilder.keywords()).doReportFailureTrace(
42 |  |
                         storyReporterBuilder.reportFailureTrace()).doCompressFailureTrace(
43 |  |
                         storyReporterBuilder.compressFailureTrace());
44 |  |
             }
45 |  |
         };
46 |  |
47 | 1 |
         public static final Format TXT = new Format("TXT") {
48 |  |
             @Override
49 |  |
             public StoryReporter createStoryReporter(FilePrintStreamFactory factory,
50 |  |
                     StoryReporterBuilder storyReporterBuilder) {
51 | 8 |
                 factory.useConfiguration(storyReporterBuilder.fileConfiguration("txt"));
52 | 8 |
                 return new TxtOutput(factory.createPrintStream(), storyReporterBuilder.keywords()).doReportFailureTrace(
53 |  |
                         storyReporterBuilder.reportFailureTrace()).doCompressFailureTrace(
54 |  |
                         storyReporterBuilder.compressFailureTrace());
55 |  |
             }
56 |  |
         };
57 |  |
58 | 1 |
         public static final Format HTML = new Format("HTML") {
59 |  |
60 |  |
             @Override
61 |  |
             public StoryReporter createStoryReporter(FilePrintStreamFactory factory,
62 |  |
                     StoryReporterBuilder storyReporterBuilder) {
63 | 8 |
                 factory.useConfiguration(storyReporterBuilder.fileConfiguration("html"));
64 | 8 |
                 return new HtmlOutput(factory.createPrintStream(), storyReporterBuilder.keywords()).doReportFailureTrace(
65 |  |
                         storyReporterBuilder.reportFailureTrace()).doCompressFailureTrace(
66 |  |
                         storyReporterBuilder.compressFailureTrace());
67 |  |
             }
68 |  |
         };
69 |  |
70 | 1 |
         public static final Format HTML_TEMPLATE = new Format("HTML") {
71 |  |
             @Override
72 |  |
             public StoryReporter createStoryReporter(FilePrintStreamFactory factory,
73 |  |
                     StoryReporterBuilder storyReporterBuilder) {
74 | 0 |
                 factory.useConfiguration(storyReporterBuilder.fileConfiguration("html"));
75 | 0 |
                 return new HtmlTemplateOutput(factory.getOutputFile(), storyReporterBuilder.keywords());
76 |  |
             }
77 |  |
         };
78 |  |
79 | 1 |
         public static final Format XML = new Format("XML") {
80 |  |
             @Override
81 |  |
             public StoryReporter createStoryReporter(FilePrintStreamFactory factory,
82 |  |
                     StoryReporterBuilder storyReporterBuilder) {
83 | 6 |
                 factory.useConfiguration(storyReporterBuilder.fileConfiguration("xml"));
84 | 6 |
                 return new XmlOutput(factory.createPrintStream(), storyReporterBuilder.keywords()).doReportFailureTrace(
85 |  |
                         storyReporterBuilder.reportFailureTrace()).doCompressFailureTrace(
86 |  |
                         storyReporterBuilder.compressFailureTrace());
87 |  |
             }
88 |  |
         };
89 |  |
90 | 1 |
         public static final Format XML_TEMPLATE = new Format("XML") {
91 |  |
             @Override
92 |  |
             public StoryReporter createStoryReporter(FilePrintStreamFactory factory,
93 |  |
                     StoryReporterBuilder storyReporterBuilder) {
94 | 0 |
                 factory.useConfiguration(storyReporterBuilder.fileConfiguration("xml"));
95 | 0 |
                 return new XmlTemplateOutput(factory.getOutputFile(), storyReporterBuilder.keywords());
96 |  |
             }
97 |  |
         };
98 |  |
99 |  |
         /**
100 |  |
          * STATS is not just about output formats, it is needed by the final
101 |  |
          * reports.html summary page.
102 |  |
          */
103 | 1 |
         public static final Format STATS = new Format("STATS") {
104 |  |
             @Override
105 |  |
             public StoryReporter createStoryReporter(FilePrintStreamFactory factory,
106 |  |
                     StoryReporterBuilder storyReporterBuilder) {
107 | 8 |
                 factory.useConfiguration(storyReporterBuilder.fileConfiguration("stats"));
108 | 8 |
                 return new PostStoryStatisticsCollector(factory.createPrintStream());
109 |  |
             }
110 |  |
         };
111 |  |
112 |  |
         private final String name;
113 |  |
114 | 16 |
         public Format(String name) {
115 | 16 |
             this.name = name;
116 | 16 |
         }
117 |  |
118 |  |
         public String name() {
119 | 39 |
             return name;
120 |  |
         }
121 |  |
122 |  |
         public abstract StoryReporter createStoryReporter(FilePrintStreamFactory factory,
123 |  |
                 StoryReporterBuilder storyReporterBuilder);
124 |  |
125 |  |
         public static void println(PrintStream writer, Object what) {
126 | 160 |
             writer.println(what);
127 | 160 |
         }
128 |  |
129 |  |
         @Override
130 |  |
         public String toString() {
131 | 0 |
             return name;
132 |  |
         }
133 |  |
134 |  |
     }