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