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 
118     public String getFirstEvent()
119     {
120         return events.get( 0 );
121     }
122 
123     public ReportEntry getFirstData()
124     {
125         return (ReportEntry) data.get( 0 );
126     }
127 
128     public String getFirstStringData()
129     {
130         return (String) data.get( 0 );
131     }
132 
133     public int getTestSucceeded()
134     {
135         return testSucceeded.get();
136     }
137 
138     public int getTestIgnored()
139     {
140         return testIgnored.get();
141     }
142 
143     public int getTestFailed()
144     {
145         return testFailed.get();
146     }
147 
148 
149     public void testAssumptionFailure( ReportEntry report )
150     {
151         events.add( TEST_ASSUMPTION_FAIL );
152         data.add( report );
153         testIgnored.incrementAndGet();
154 
155     }
156 
157     public void writeTestOutput()
158     {
159         //To change body of implemented methods use File | Settings | File Templates.
160     }
161 
162     public void info( String message )
163     {
164         events.add( CONSOLE_OUTPUT );
165         data.add( message );
166         //To change body of implemented methods use File | Settings | File Templates.
167     }
168 
169     public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
170     {
171         events.add( stdout ? STDOUT : STDERR );
172         data.add( new String( buf, off, len ) );
173     }
174 }