View Javadoc

1   package org.apache.maven.plugin.surefire.booterclient;
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.plugin.surefire.booterclient.output.OutputConsumer;
23  import org.apache.maven.surefire.report.CategorizedReportEntry;
24  import org.apache.maven.surefire.report.ForkingConsoleReporter;
25  import org.apache.maven.surefire.report.ReportEntry;
26  import org.jmock.Mock;
27  import org.jmock.MockObjectTestCase;
28  
29  /**
30   * Test for {@link ForkingStreamConsumer}
31   *
32   * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
33   * @version $Id: ForkingStreamConsumerTest.java 1056406 2011-01-07 17:34:39Z krosenvold $
34   */
35  public class ForkingStreamConsumerTest
36      extends MockObjectTestCase
37  {
38  
39      private ForkingStreamConsumer streamConsumer;
40  
41      private Mock outputConsumerMock;
42  
43      private String message;
44  
45      private ReportEntry reportEntry;
46  
47      protected void setUp()
48          throws Exception
49      {
50          super.setUp();
51          outputConsumerMock = new Mock( OutputConsumer.class );
52          streamConsumer = new ForkingStreamConsumer( (OutputConsumer) outputConsumerMock.proxy() );
53          message = "message";
54          reportEntry = CategorizedReportEntry.nameGroup( "name", "group" );
55      }
56  
57      public void testConsumeHeaderLine()
58      {
59          String message = "message";
60          String line = ForkingConsoleReporter.FORKING_PREFIX_HEADING + message;
61          outputConsumerMock.expects( once() ).method( "consumeHeaderLine" ).with( eq( message ) );
62          streamConsumer.consumeLine( line );
63      }
64  
65      public void testConsumeMessageLine()
66      {
67          String message = "message";
68          String line = ForkingConsoleReporter.FORKING_PREFIX_STANDARD + message;
69          outputConsumerMock.expects( once() ).method( "consumeMessageLine" ).with( eq( message ) );
70          streamConsumer.consumeLine( line );
71      }
72  
73      public void testConsumeFooterLine()
74      {
75          String message = "message";
76          String line = ForkingConsoleReporter.FORKING_PREFIX_FOOTER + message;
77          outputConsumerMock.expects( once() ).method( "consumeFooterLine" ).with( eq( message ) );
78          streamConsumer.consumeLine( line );
79      }
80  
81      public void testConsumeOutputLine()
82      {
83          String line = message;
84          outputConsumerMock.expects( once() ).method( "consumeOutputLine" ).with( eq( message ) );
85          streamConsumer.consumeLine( line );
86      }
87  
88      public void testTestSetStarting()
89      {
90          message = ForkingConsoleReporter.getTestSetStartingMessage( reportEntry );
91          String line = ForkingConsoleReporter.FORKING_PREFIX_STANDARD + message;
92          outputConsumerMock.expects( once() ).method( "testSetStarting" ).with( eq( reportEntry ) );
93          outputConsumerMock.expects( once() ).method( "consumeMessageLine" ).with( eq( message ) );
94          streamConsumer.consumeLine( line );
95      }
96  
97      public void testTestSetCompleted()
98      {
99          message = "Tests run: xxxx";
100         String line = ForkingConsoleReporter.FORKING_PREFIX_STANDARD + message;
101         outputConsumerMock.expects( once() ).method( "testSetCompleted" );
102         outputConsumerMock.expects( once() ).method( "consumeMessageLine" ).with( eq( message ) );
103         streamConsumer.consumeLine( line );
104     }
105 
106 }