1 | |
package org.jbehave.core.reporters; |
2 | |
|
3 | |
import java.io.PrintStream; |
4 | |
|
5 | |
import org.jbehave.core.reporters.StoryReporterBuilder.ProvidedFormat; |
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
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 | 5 | 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 | 7 | factory.useConfiguration(storyReporterBuilder.fileConfiguration("html")); |
64 | 7 | 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 | 5 | factory.useConfiguration(storyReporterBuilder.fileConfiguration("xml")); |
84 | 5 | 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 XmlTemplateOuput(factory.getOutputFile(), storyReporterBuilder.keywords()); |
96 | |
} |
97 | |
}; |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
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 | 168 | writer.println(what); |
127 | 168 | } |
128 | |
|
129 | |
@Override |
130 | |
public String toString() { |
131 | 0 | return name; |
132 | |
} |
133 | |
|
134 | |
} |