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 java.util.ArrayList;
23  import java.util.List;
24  import java.util.concurrent.atomic.AtomicInteger;
25  import org.apache.maven.surefire.report.ConsoleOutputReceiver;
26  import org.apache.maven.surefire.report.ConsoleLogger;
27  import org.apache.maven.surefire.report.ReportEntry;
28  import org.apache.maven.surefire.report.RunListener;
29  
30  /**
31   * Internal use only
32   */
33  public class MockReporter
34      implements RunListener, ConsoleLogger, ConsoleOutputReceiver
35  {
36      private final List events = new ArrayList();
37  
38      private final List data = new ArrayList();
39  
40      public static final String SET_STARTING = "SET_STARTED";
41  
42      public static final String SET_COMPLETED = "SET_COMPLETED";
43  
44      public static final String TEST_STARTING = "TEST_STARTED";
45  
46      public static final String TEST_SUCCEEDED = "TEST_COMPLETED";
47  
48      public static final String TEST_FAILED = "TEST_FAILED";
49  
50      public static final String TEST_ERROR = "TEST_ERROR";
51  
52      public static final String TEST_SKIPPED = "TEST_SKIPPED";
53  
54      public static final String TEST_ASSUMPTION_FAIL = "TEST_ASSUMPTION_SKIPPED";
55  
56      public static final String CONSOLE_OUTPUT = "CONSOLE_OUTPUT";
57  
58      public static final String STDOUT = "STDOUT";
59  
60      public static final String STDERR = "STDERR";
61  
62      private final AtomicInteger testSucceeded = new AtomicInteger();
63  
64      private final AtomicInteger testIgnored = new AtomicInteger();
65  
66      private final AtomicInteger testFailed = new AtomicInteger();
67  
68      public MockReporter()
69      {
70      }
71  
72      public void testSetStarting( ReportEntry report )
73      {
74          events.add( SET_STARTING );
75          data.add( report );
76      }
77  
78      public void testSetCompleted( ReportEntry report )
79      {
80          events.add( SET_COMPLETED );
81          data.add( report );
82      }
83  
84      public void testStarting( ReportEntry report )
85      {
86          events.add( TEST_STARTING );
87          data.add( report );
88      }
89  
90      public void testSucceeded( ReportEntry report )
91      {
92          events.add( TEST_SUCCEEDED );
93          testSucceeded.incrementAndGet();
94          data.add( report );
95      }
96  
97      public void testError( ReportEntry report )
98      {
99          events.add( TEST_ERROR );
100         data.add( report );
101         testFailed.incrementAndGet();
102     }
103 
104     public void testFailed( ReportEntry report )
105     {
106         events.add( TEST_FAILED );
107         data.add( report );
108         testFailed.incrementAndGet();
109     }
110 
111 
112     public void testSkipped( ReportEntry report )
113     {
114         events.add( TEST_SKIPPED );
115         data.add( report );
116         testIgnored.incrementAndGet();
117     }
118 
119 
120     public List getEvents()
121     {
122         return events;
123     }
124 
125     public List getData()
126     {
127         return data;
128     }
129 
130     public String getFirstEvent()
131     {
132         return (String) events.get( 0 );
133     }
134 
135     public ReportEntry getFirstData()
136     {
137         return (ReportEntry) data.get( 0 );
138     }
139 
140 
141     public void testAssumptionFailure( ReportEntry report )
142     {
143         events.add( TEST_ASSUMPTION_FAIL );
144         data.add( report );
145         testIgnored.incrementAndGet();
146 
147     }
148 
149     public void info( String message )
150     {
151         events.add( CONSOLE_OUTPUT );
152         data.add( message );
153         //To change body of implemented methods use File | Settings | File Templates.
154     }
155 
156     public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
157     {
158         events.add( stdout ? STDOUT : STDERR );
159         data.add( new String( buf, off, len ) );
160     }
161 }