1 package org.apache.maven.plugin.surefire.booterclient.output;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.jmock.core.constraint.IsEqual;
23 import org.jmock.core.matcher.InvokeOnceMatcher;
24
25 import java.io.BufferedReader;
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.InputStreamReader;
29
30
31
32
33
34
35
36 public class FileOutputConsumerProxyTest
37 extends OutputConsumerProxyTest
38 {
39
40 private static final String USER_DIR = System.getProperty( "user.dir" );
41 File targetDir;
42
43 protected void setUp()
44 throws Exception
45 {
46 super.setUp();
47 targetDir = new File ( USER_DIR, "target" );
48 if ( !targetDir.exists() ) targetDir = new File( USER_DIR );
49 setOutputConsumer( new FileOutputConsumerProxy( (OutputConsumer) getOutputConsumerMock().proxy(), targetDir ) );
50 }
51
52 public void testConsumeOutputLine()
53 throws Exception
54 {
55
56 File reportFile = new File( targetDir, getReportEntry().getName() + "-output.txt" );
57 reportFile.delete();
58
59 getOutputConsumerMock().expects( new InvokeOnceMatcher() ).method( "testSetStarting" )
60 .with( new IsEqual( getReportEntry() ) );
61 getOutputConsumerMock().expects( new InvokeOnceMatcher() ).method( "testSetCompleted" );
62 getOutputConsumer().testSetStarting( getReportEntry() );
63 getOutputConsumer().consumeOutputLine( getLine() );
64 getOutputConsumer().testSetCompleted();
65 getOutputConsumerMock().verify();
66
67 assertTrue( reportFile.exists() );
68
69 BufferedReader in = null;
70 try
71 {
72 in = new BufferedReader( new InputStreamReader( new FileInputStream( reportFile ) ) );
73 String content = in.readLine();
74 assertEquals( getLine(), content );
75 assertNull( in.readLine() );
76 }
77 finally
78 {
79 if ( in != null )
80 {
81 in.close();
82 }
83 }
84
85 reportFile.deleteOnExit();
86 }
87
88 }