View Javadoc

1   package org.apache.maven.surefire.report;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.BufferedOutputStream;
23  import java.io.OutputStreamWriter;
24  import java.io.PrintStream;
25  import java.io.PrintWriter;
26  
27  /**
28   * Base class for console reporters.
29   *
30   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
31   */
32  public abstract class AbstractConsoleReporter
33      extends AbstractTextReporter
34  {
35      private static final String TEST_SET_STARTING_PREFIX = "Running ";
36  
37      private static final String TEST_SET_STARTING_GROUP_PREFIX = " (of ";
38  
39      private static final String TEST_SET_STARTING_GROUP_SUFIX = ")";
40  
41      private static final int BUFFER_SIZE = 4096;
42  
43      private static final PrintStream ORIGINAL_SYSTEM_OUT = System.out;
44  
45      AbstractConsoleReporter( boolean trimStackTrace, String format )
46      {
47          super( getPrintWriter(), trimStackTrace, format);
48      }
49  
50      private static PrintWriter getPrintWriter()
51      {
52          return new PrintWriter( new OutputStreamWriter( new BufferedOutputStream( ORIGINAL_SYSTEM_OUT, BUFFER_SIZE ) ) );
53      }
54  
55      public void testSetStarting( ReportEntry report )
56          throws ReporterException
57      {
58          super.testSetStarting( report );
59  
60          writeMessage( getTestSetStartingMessage( report ) );
61      }
62  
63      /**
64       * Get the test set starting message for a report.
65       * eg. "Running org.foo.BarTest ( of group )"
66       *
67       * @param report report whose test set is starting
68       * @return the message
69       */
70      static String getTestSetStartingMessage( ReportEntry report )
71      {
72          StringBuffer message = new StringBuffer();
73          message.append( TEST_SET_STARTING_PREFIX );
74          message.append( report.getName() );
75  
76          if ( report.getGroup() != null && !report.getName().equals( report.getGroup() ) )
77          {
78              message.append( TEST_SET_STARTING_GROUP_PREFIX );
79              message.append( report.getGroup() );
80              message.append( TEST_SET_STARTING_GROUP_SUFIX );
81          }
82  
83          message.append( "\n" );
84          return message.toString();
85      }
86  
87  }