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