View Javadoc
1   package org.apache.maven.plugin.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 org.apache.maven.surefire.api.report.TestOutputReportEntry;
23  import org.apache.maven.surefire.api.report.TestSetReportEntry;
24  
25  import java.io.PrintStream;
26  
27  import static java.util.Objects.requireNonNull;
28  
29  /**
30   * Outputs test system out/system err directly to the console
31   * <br>
32   * Just a step on the road to getting the separation of reporting concerns
33   * operating properly.
34   *
35   * @author Kristian Rosenvold
36   */
37  public class DirectConsoleOutput
38      implements TestcycleConsoleOutputReceiver
39  {
40      private final PrintStream out;
41  
42      private final PrintStream err;
43  
44      public DirectConsoleOutput( PrintStream out, PrintStream err )
45      {
46          this.out = requireNonNull( out );
47          this.err = requireNonNull( err );
48      }
49  
50      @Override
51      public void writeTestOutput( TestOutputReportEntry reportEntry )
52      {
53          PrintStream stream = reportEntry.isStdOut() ? out : err;
54          if ( reportEntry.isNewLine() )
55          {
56              stream.println( reportEntry.getLog() );
57          }
58          else
59          {
60              stream.print( reportEntry.getLog() );
61          }
62      }
63  
64      @Override
65      public void testSetStarting( TestSetReportEntry reportEntry )
66      {
67      }
68  
69      @Override
70      public void testSetCompleted( TestSetReportEntry report )
71      {
72      }
73  
74      @Override
75      public void close()
76      {
77      }
78  }