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.ConsoleLogger;
26  import org.apache.maven.surefire.report.ConsoleOutputReceiver;
27  import org.apache.maven.surefire.report.ReportEntry;
28  import org.apache.maven.surefire.report.RunListener;
29  
30  /**
31   * Internal tests use only.
32   */
33  public class MockReporter
34      implements RunListener, ConsoleLogger, ConsoleOutputReceiver
35  {
36      private final List<String> events = new ArrayList<String>();
37  
38      private final List<Object> data = new ArrayList<Object>();
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 void testSetStarting( ReportEntry report )
69      {
70          events.add( SET_STARTING );
71          data.add( report );
72      }
73  
74      public void testSetCompleted( ReportEntry report )
75      {
76          events.add( SET_COMPLETED );
77          data.add( report );
78      }
79  
80      public void testStarting( ReportEntry report )
81      {
82          events.add( TEST_STARTING );
83          data.add( report );
84      }
85  
86      public void testSucceeded( ReportEntry report )
87      {
88          events.add( TEST_SUCCEEDED );
89          testSucceeded.incrementAndGet();
90          data.add( report );
91      }
92  
93      public void testError( ReportEntry report )
94      {
95          events.add( TEST_ERROR );
96          data.add( report );
97          testFailed.incrementAndGet();
98      }
99  
100     public void testFailed( ReportEntry report )
101     {
102         events.add( TEST_FAILED );
103         data.add( report );
104         testFailed.incrementAndGet();
105     }
106 
107     public void testSkipped( ReportEntry report )
108     {
109         events.add( TEST_SKIPPED );
110         data.add( report );
111         testIgnored.incrementAndGet();
112     }
113 
114     public void testExecutionSkippedByUser()
115     {
116     }
117 
118     public void testSkippedByUser( ReportEntry report )
119     {
120         testSkipped( report );
121     }
122 
123     public List<String> getEvents()
124     {
125         return events;
126     }
127 
128     public List getData()
129     {
130         return data;
131     }
132 
133     public String getFirstEvent()
134     {
135         return events.get( 0 );
136     }
137 
138     public ReportEntry getFirstData()
139     {
140         return (ReportEntry) data.get( 0 );
141     }
142 
143     public void testAssumptionFailure( ReportEntry report )
144     {
145         events.add( TEST_ASSUMPTION_FAIL );
146         data.add( report );
147         testIgnored.incrementAndGet();
148     }
149 
150     public void info( String message )
151     {
152         events.add( CONSOLE_OUTPUT );
153         data.add( message );
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 }