View Javadoc

1   package org.apache.maven.surefire.report;
2   
3   /*
4    * Copyright 2001-2005 The Codehaus.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.io.BufferedOutputStream;
20  import java.io.OutputStreamWriter;
21  import java.io.PrintWriter;
22  
23  public class ConsoleReporter
24      extends AbstractReporter
25  {
26      protected static final int BUFFER_SIZE = 4096;
27  
28      protected PrintWriter writer;
29      
30      protected long batteryStartTime;
31  
32      public ConsoleReporter()
33      {
34          writer = new PrintWriter( new OutputStreamWriter( new BufferedOutputStream( System.out, BUFFER_SIZE ) ) );
35      }
36  
37      // ----------------------------------------------------------------------
38      //
39      // ----------------------------------------------------------------------
40  
41      public void println( String message )
42      {
43          writer.println( message );
44  
45          writer.flush();
46      }
47  
48      public void print( String message )
49      {
50          writer.print( message );
51  
52          writer.flush();
53      }
54  
55      // ----------------------------------------------------------------------
56      // Run
57      // ----------------------------------------------------------------------
58  
59      public void runStarting( int testCount )
60      {
61          println( "" );
62          println( "-------------------------------------------------------" );
63          println( " T E S T S" );
64          println( "-------------------------------------------------------" );
65      }
66  
67      public void runAborted( ReportEntry report )
68      {
69          println( "RUN ABORTED" );
70          println( report.getSource().getClass().getName() );
71          println( report.getName() );
72          println( report.getMessage() );
73          println( report.getThrowable().getMessage() );
74      }
75      public void batteryAborted( ReportEntry report )
76      {
77          println( "BATTERY ABORTED" );
78          println( report.getSource().getClass().getName() );
79          println( report.getName() );
80          println( report.getMessage() );
81          println( report.getThrowable().getMessage() );
82      }
83  
84      // ----------------------------------------------------------------------
85      // Battery
86      // ----------------------------------------------------------------------
87  
88      public void batteryStarting( ReportEntry report )
89          throws Exception
90      {
91          batteryStartTime = System.currentTimeMillis();
92          
93          println( "[surefire] Running " + report.getName() );
94      }
95  
96      public void batteryCompleted( ReportEntry report )
97      {
98          long runTime = System.currentTimeMillis() - batteryStartTime;
99  
100         print( "[surefire] Tests run: " + completedCount +
101                              ", Failures: " + failures +
102                              ", Errors: " + errors +
103                              ", Time elapsed: " + elapsedTimeAsString( runTime ) + " sec" );
104 
105         if ( failures > 0 || errors > 0 )
106         {
107             writer.print( " <<<<<<<< FAILURE !! " );
108         }
109         
110         writer.println( "" );
111 
112         writer.flush();
113 
114         completedCount = 0;
115 
116         errors = 0;
117 
118         failures = 0;
119     }
120 }