@@ -47,238 +47,14 @@ public class TreePrinter {
4747
4848 private static final int $ = 36 ;
4949 private final ConsoleLogger consoleLogger ;
50- private final List <WrappedReportEntry > classResults ;
51- private final List <WrappedReportEntry > testSetStats ;
52- private final List <String > sourceNames ;
53- private final Set <String > distinctSourceName ;
5450 private final ReporterOptions options ;
5551
56- public TreePrinter (ConsoleLogger consoleLogger , List < WrappedReportEntry > classResults , List < WrappedReportEntry > testSetStats , ReporterOptions options ) {
52+ public TreePrinter (ConsoleLogger consoleLogger , ReporterOptions options ) {
5753 this .consoleLogger = consoleLogger ;
58- this .classResults = classResults ;
59- this .testSetStats = testSetStats ;
60- this .sourceNames = getSourceNames ();
61- this .distinctSourceName = getDistinctSourceNames ();
6254 this .options = options ;
6355 }
6456
65- private List <String > getSourceNames () {
66- return testSetStats
67- .stream ()
68- .map (WrappedReportEntry ::getSourceName )
69- .collect (toList ());
70- }
71-
72- private Set <String > getDistinctSourceNames () {
73- return testSetStats
74- .stream ()
75- .map (WrappedReportEntry ::getSourceName )
76- .collect (toSet ());
77- }
78-
7957 public void printTests () {
80- // testSetStats
81- // .stream()
82- // .map(TestPrinter::new)
83- // .forEach(printer -> {
84- // printer.printTest(isSuccessPrintAllowed());
85- // printer.printDetails();
86- // });
8758 new ActualTreePrinter (Node .getRoot (), consoleLogger , options ).print ();
8859 }
89-
90- private boolean isSuccessPrintAllowed () {
91- return !options .isHideResultsOnSuccess ();
92- }
93-
94- private class TestPrinter {
95-
96- private final WrappedReportEntry testResult ;
97- private final int treeLength ;
98- private final Theme theme ;
99-
100- public TestPrinter (WrappedReportEntry testResult ) {
101- this .testResult = testResult ;
102- this .treeLength = getTreeLength ();
103- this .theme = options .getTheme ();
104- }
105-
106- private void printDetails () {
107- boolean isSuccess = testResult .getReportEntryType () == ReportEntryType .SUCCESS ;
108- boolean isError = testResult .getReportEntryType () == ReportEntryType .ERROR ;
109- boolean isFailure = testResult .getReportEntryType () == ReportEntryType .FAILURE ;
110-
111- boolean printStackTrace = options .isPrintStacktraceOnError () && isError
112- || options .isPrintStacktraceOnFailure () && isFailure ;
113- boolean printStdOut = options .isPrintStdoutOnSuccess () && isSuccess
114- || options .isPrintStdoutOnError () && isError
115- || options .isPrintStdoutOnFailure () && isFailure ;
116- boolean printStdErr = options .isPrintStderrOnSuccess () && isSuccess
117- || options .isPrintStderrOnError () && isError
118- || options .isPrintStderrOnFailure () && isFailure ;
119-
120- if (printStackTrace || printStdOut || printStdErr ) {
121- printPreambleDetails ();
122- if (printStackTrace ) {
123- printStackTrace ();
124- }
125- if (printStdOut ) {
126- printStdOut ();
127- }
128- if (printStdErr ) {
129- printStdErr ();
130- }
131- }
132- }
133-
134- private void printTest (boolean isPrintSuccessAllowed ) {
135- printClass ();
136- if (testResult .isErrorOrFailure ()) {
137- printFailure ();
138- } else if (testResult .isSkipped ()) {
139- printSkipped ();
140- } else if (isPrintSuccessAllowed && testResult .isSucceeded ()) {
141- printSuccess ();
142- }
143- }
144-
145- private void printSuccess () {
146- println (buffer ()
147- .success (theme .successful () + abbreviateName (testResult .getReportName ())));
148- }
149-
150- private void printSkipped () {
151- println (buffer ()
152- .warning (theme .skipped () + getSkippedReport ())
153- .warning (getSkippedMessage ()));
154- }
155-
156- private String getSkippedReport () {
157- if (!isBlank (testResult .getReportName ())) {
158- return abbreviateName (testResult .getReportName ());
159- } else {
160- return testResult .getReportSourceName ();
161- }
162- }
163-
164- private String getSkippedMessage () {
165- if (!isBlank (testResult .getMessage ())) {
166- return " (" + testResult .getMessage () + ")" ;
167- } else {
168- return "" ;
169- }
170- }
171-
172- private void printPreambleDetails () {
173- println ("" );
174- if (testResult .isSucceeded ()) {
175- println (buffer ().success (theme .details ()).success (abbreviateName (testResult .getReportName ())).toString ());
176- } else {
177- println (buffer ().failure (theme .details ()).failure (abbreviateName (testResult .getReportName ())).toString ());
178- }
179- }
180-
181- private void printStdOut () {
182- println ("" );
183- println (buffer ().strong ("Standard out" ).toString ());
184- try {
185- testResult .getStdout ().writeTo (System .out );
186- } catch (final IOException ignored ) {
187- }
188- }
189-
190- private void printStdErr () {
191- println ("" );
192- println (buffer ().strong ("Standard error" ).toString ());
193- try {
194- testResult .getStdErr ().writeTo (System .err );
195- } catch (final IOException ignored ) {
196- }
197- }
198-
199- private void printStackTrace () {
200- println ("" );
201- println (buffer ().strong ("Stack trace" ).toString ());
202- String stackTrace = testResult .getStackTrace (false );
203- if (stackTrace != null && !StringUtils .isBlank (stackTrace )) {
204- println (testResult .getStackTrace (false ));
205- } else {
206- println ("[No stack trace available]" );
207- }
208- }
209-
210- private void printFailure () {
211- println (buffer ()
212- .failure (theme .failed () + abbreviateName (testResult .getReportName ())));
213- }
214-
215- private void printClass () {
216- if (!distinctSourceName .contains (testResult .getSourceName ())) return ;
217- distinctSourceName .remove (testResult .getSourceName ());
218-
219- MessageBuilder builder = buffer ();
220- if (treeLength > 0 ) {
221- if (treeLength > 1 ) {
222- builder .a (theme .pipe ());
223- LongStream .rangeClosed (0 , treeLength - 3 )
224- .forEach (i -> builder .a (theme .blank ()));
225- builder .a (theme .end ());
226- } else {
227- builder .a (theme .entry ());
228- }
229- if (sourceNames .stream ().distinct ().count () > 1 ) {
230- builder .a (theme .down ());
231- } else {
232- builder .a (theme .dash ());
233- }
234- } else {
235- builder .a (theme .entry ());
236- }
237-
238- concatenateWithTestGroup (builder , testResult , !isBlank (testResult .getReportNameWithGroup ()));
239- builder .a (" - " + classResults .get (treeLength ).elapsedTimeAsString ());
240-
241- println (builder .toString ());
242- }
243-
244- private MessageBuilder getTestPrefix () {
245- MessageBuilder builder = buffer ().a (theme .pipe ());
246- if (treeLength > 0 ) {
247- LongStream .rangeClosed (0 , treeLength - 2 )
248- .forEach (i -> builder .a (theme .blank ()));
249- if (sourceNames .stream ().distinct ().count () > 1 ) {
250- builder .a (theme .pipe ());
251- } else {
252- builder .a (theme .blank ());
253- }
254- }
255- sourceNames .remove (testResult .getSourceName ());
256- if (sourceNames .contains (testResult .getSourceName ())) {
257- builder .a (theme .entry ());
258- } else {
259- builder .a (theme .end ());
260- }
261- return builder ;
262- }
263-
264- private int getTreeLength () {
265- return (int ) testResult .getSourceName ()
266- .chars ()
267- .filter (c -> c == $ )
268- .count ();
269- }
270-
271- private void println (MessageBuilder builder ) {
272- println (getTestPrefix ()
273- .a (builder )
274- .a (" - " + testResult .elapsedTimeAsString ())
275- .toString ());
276- }
277-
278- private void println (String message ) {
279- consoleLogger .info (message );
280- }
281-
282- }
283-
28460}
0 commit comments