1 | |
package org.apache.maven.plugin.surefire.report; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.BufferedOutputStream; |
23 | |
import java.io.OutputStreamWriter; |
24 | |
import java.io.PrintStream; |
25 | |
import java.io.PrintWriter; |
26 | |
import java.util.List; |
27 | |
import org.apache.maven.surefire.report.ReportEntry; |
28 | |
import org.apache.maven.surefire.report.ReporterException; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class ConsoleReporter |
37 | |
{ |
38 | |
public static final String BRIEF = "brief"; |
39 | |
|
40 | |
public static final String PLAIN = "plain"; |
41 | |
|
42 | |
private static final String TEST_SET_STARTING_PREFIX = "Running "; |
43 | |
|
44 | |
private static final String TEST_SET_STARTING_GROUP_PREFIX = " (of "; |
45 | |
|
46 | |
private static final String TEST_SET_STARTING_GROUP_SUFIX = ")"; |
47 | |
|
48 | |
private static final int BUFFER_SIZE = 4096; |
49 | |
|
50 | |
private final PrintWriter writer; |
51 | |
|
52 | |
|
53 | |
public ConsoleReporter( PrintStream originalSystemOut ) |
54 | 0 | { |
55 | 0 | OutputStreamWriter out = new OutputStreamWriter( new BufferedOutputStream( originalSystemOut, BUFFER_SIZE ) ); |
56 | 0 | this.writer = new PrintWriter( out ); |
57 | 0 | } |
58 | |
|
59 | |
public void testSetStarting( ReportEntry report ) |
60 | |
throws ReporterException |
61 | |
{ |
62 | 0 | writeMessage( getTestSetStartingMessage( report ) ); |
63 | 0 | } |
64 | |
|
65 | |
public void writeMessage( String message ) |
66 | |
{ |
67 | 0 | if ( writer != null ) |
68 | |
{ |
69 | 0 | writer.print( message ); |
70 | |
|
71 | 0 | writer.flush(); |
72 | |
} |
73 | 0 | } |
74 | |
|
75 | |
public void writeLnMessage( String message ) |
76 | |
{ |
77 | 0 | if ( writer != null ) |
78 | |
{ |
79 | 0 | writer.println( message ); |
80 | |
|
81 | 0 | writer.flush(); |
82 | |
} |
83 | 0 | } |
84 | |
|
85 | |
public void testSetCompleted( WrappedReportEntry report, TestSetStats testSetStats, List<String> testResults ) |
86 | |
throws ReporterException |
87 | |
{ |
88 | 0 | writeMessage( testSetStats.getTestSetSummary( report ) ); |
89 | |
|
90 | 0 | if ( testResults != null ) |
91 | |
{ |
92 | 0 | for ( String testResult : testResults ) |
93 | |
{ |
94 | 0 | writeLnMessage( testResult ); |
95 | |
} |
96 | |
} |
97 | 0 | } |
98 | |
|
99 | |
|
100 | |
public void reset() |
101 | |
{ |
102 | 0 | if ( writer != null ) |
103 | |
{ |
104 | 0 | writer.flush(); |
105 | |
} |
106 | 0 | } |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
static String getTestSetStartingMessage( ReportEntry report ) |
116 | |
{ |
117 | 0 | StringBuilder message = new StringBuilder(); |
118 | 0 | message.append( TEST_SET_STARTING_PREFIX ); |
119 | 0 | message.append( report.getName() ); |
120 | |
|
121 | 0 | if ( report.getGroup() != null && !report.getName().equals( report.getGroup() ) ) |
122 | |
{ |
123 | 0 | message.append( TEST_SET_STARTING_GROUP_PREFIX ); |
124 | 0 | message.append( report.getGroup() ); |
125 | 0 | message.append( TEST_SET_STARTING_GROUP_SUFIX ); |
126 | |
} |
127 | |
|
128 | 0 | message.append( "\n" ); |
129 | 0 | return message.toString(); |
130 | |
} |
131 | |
|
132 | |
|
133 | |
} |