View Javadoc
1   package org.apache.maven.surefire.junit4;
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.ReportEntry;
26  import org.apache.maven.surefire.report.RunListener;
27  import org.apache.maven.surefire.report.TestSetReportEntry;
28  
29  /**
30   * Internal tests use only.
31   */
32  public class MockReporter
33      implements RunListener
34  {
35      private final List<String> events = new ArrayList<String>();
36  
37      public static final String SET_STARTED = "SET_STARTED";
38  
39      public static final String SET_COMPLETED = "SET_COMPLETED";
40  
41      public static final String TEST_STARTED = "TEST_STARTED";
42  
43      public static final String TEST_COMPLETED = "TEST_COMPLETED";
44  
45      public static final String TEST_SKIPPED = "TEST_SKIPPED";
46  
47      private final AtomicInteger testSucceeded = new AtomicInteger();
48  
49      private final AtomicInteger testIgnored = new AtomicInteger();
50  
51      private final AtomicInteger testFailed = new AtomicInteger();
52  
53      private final AtomicInteger testError = new AtomicInteger();
54  
55      public MockReporter()
56      {
57      }
58  
59      @Override
60      public void testSetStarting( TestSetReportEntry report )
61      {
62          events.add( SET_STARTED );
63      }
64  
65      @Override
66      public void testSetCompleted( TestSetReportEntry report )
67      {
68          events.add( SET_COMPLETED );
69      }
70  
71      @Override
72      public void testStarting( ReportEntry report )
73      {
74          events.add( TEST_STARTED );
75      }
76  
77      @Override
78      public void testSucceeded( ReportEntry report )
79      {
80          events.add( TEST_COMPLETED );
81          testSucceeded.incrementAndGet();
82      }
83  
84      @Override
85      public void testSkipped( ReportEntry report )
86      {
87          events.add( TEST_SKIPPED );
88          testIgnored.incrementAndGet();
89      }
90  
91      @Override
92      public void testExecutionSkippedByUser()
93      {
94      }
95  
96      public void testSkippedByUser( ReportEntry report )
97      {
98          testSkipped( report );
99      }
100 
101     public int getTestSucceeded()
102     {
103         return testSucceeded.get();
104     }
105 
106     public int getTestFailed()
107     {
108         return testFailed.get();
109     }
110 
111     @Override
112     public void testError( ReportEntry report )
113     {
114         testError.incrementAndGet();
115     }
116 
117     @Override
118     public void testFailed( ReportEntry report )
119     {
120         testFailed.incrementAndGet();
121     }
122 
123     @Override
124     public void testAssumptionFailure( ReportEntry report )
125     {
126     }
127 
128     public boolean containsNotification( String event )
129     {
130         return events.contains( event );
131     }
132 }