1 package org.apache.maven.surefire.report;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24
25
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 }