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 junit.framework.TestCase;
23  
24  /**
25   * @author Kristian Rosenvold
26   */
27  public class AsynchRunListenerTest
28      extends TestCase
29  {
30  
31      class MockConsoleOutputReceiver
32          implements ConsoleOutputReceiver
33      {
34          byte[] buf;
35  
36  
37          int len;
38  
39          boolean stdout;
40  
41          public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
42          {
43              this.buf = buf;
44              this.len = len;
45              this.stdout = stdout;
46          }
47  
48          public byte[] getBuf()
49          {
50              return buf;
51          }
52  
53          public int getLen()
54          {
55              return len;
56          }
57      }
58  
59      public void testCombiner()
60      {
61          final MockConsoleOutputReceiver consoleOutputReceiver = new MockConsoleOutputReceiver();
62          AsynchRunListener.JoinableTestOutput joinableTestOutput =
63              new AsynchRunListener.JoinableTestOutput( "ABC".getBytes(), 0, 3, true, consoleOutputReceiver );
64          AsynchRunListener.JoinableTestOutput joinableTestOutput2 =
65              new AsynchRunListener.JoinableTestOutput( "DEF".getBytes(), 0, 3, true, consoleOutputReceiver );
66  
67          final AsynchRunListener.JoinableTestOutput append = joinableTestOutput.append( joinableTestOutput2 );
68  
69          append.run();
70          final byte[] expected = "ABCDEF".getBytes();
71          for ( int i = 0; i < expected.length; i++ )
72          {
73              assertEquals( expected[i], consoleOutputReceiver.getBuf()[i] );
74          }
75          assertEquals( expected.length, consoleOutputReceiver.getLen() );
76      }
77  }