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, DirectConsoleReporter
31  {
32      private final List events = new ArrayList();
33  
34      private final List data = new ArrayList();
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 MockReporter( ReporterConfiguration reporterConfiguration )
71      {
72  
73      }
74  
75      public void testSetStarting( ReportEntry report )
76      {
77          events.add( SET_STARTING );
78          data.add( report );
79      }
80  
81      public void testSetCompleted( ReportEntry report )
82      {
83          events.add( SET_COMPLETED );
84          data.add( report );
85      }
86  
87      public void testStarting( ReportEntry report )
88      {
89          events.add( TEST_STARTING );
90          data.add( report );
91      }
92  
93      public void testSucceeded( ReportEntry report )
94      {
95          events.add( TEST_SUCCEEDED );
96          testSucceeded.incrementAndGet();
97          data.add( report );
98      }
99  
100     public void testError( ReportEntry report )
101     {
102         events.add( TEST_ERROR );
103         data.add( report );
104         testFailed.incrementAndGet();
105     }
106 
107     public void testFailed( ReportEntry report )
108     {
109         events.add( TEST_FAILED );
110         data.add( report );
111         testFailed.incrementAndGet();
112     }
113 
114 
115     public void testSkipped( ReportEntry report )
116     {
117         events.add( TEST_SKIPPED );
118         data.add( report );
119         testIgnored.incrementAndGet();
120     }
121 
122 
123     public List getEvents()
124     {
125         return events;
126     }
127 
128     public List getData()
129     {
130         return data;
131     }
132 
133     public String getFirstEvent()
134     {
135         return (String) events.get( 0 );
136     }
137 
138     public ReportEntry getFirstData()
139     {
140         return (ReportEntry) data.get( 0 );
141     }
142 
143     public String getFirstStringData()
144     {
145         return (String) data.get( 0 );
146     }
147 
148     public int getTestSucceeded()
149     {
150         return testSucceeded.get();
151     }
152 
153     public int getTestIgnored()
154     {
155         return testIgnored.get();
156     }
157 
158     public int getTestFailed()
159     {
160         return testFailed.get();
161     }
162 
163 
164     public void testAssumptionFailure( ReportEntry report )
165     {
166         events.add( TEST_ASSUMPTION_FAIL );
167         data.add( report );
168         testIgnored.incrementAndGet();
169 
170     }
171 
172     public void writeTestOutput( String output, boolean stdout )
173     {
174         //To change body of implemented methods use File | Settings | File Templates.
175     }
176 
177     public void writeMessage( String message )
178     {
179         events.add( CONSOLE_OUTPUT );
180         data.add( message );
181         //To change body of implemented methods use File | Settings | File Templates.
182     }
183 
184     public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
185     {
186         events.add( stdout ? STDOUT : STDERR );
187         data.add( new String( buf, off, len ) );
188     }
189 }