View Javadoc

1   package org.apache.maven.surefire.testng;
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 org.apache.maven.surefire.report.ReportEntry;
23  import org.apache.maven.surefire.report.RunListener;
24  import org.apache.maven.surefire.report.ReporterException;
25  
26  /**
27   * A proxy that imposes synchronization on the Reporter.
28   * <p/>
29   * <p/>
30   * At the moment this class only provides "compatible" synchronization that the testng runner can use,
31   * and provides the same (faulty) level of synchronization as the <2.6 versions of surefire.
32   * <p/>
33   * In the "future"  when the concurrent junit provider is rid of all problems of childhood,
34   * it should probably replace the entire reporting secion for testng too.
35   * <p/>
36   * <p/>
37   * <p/>
38   * This design is really only good for single-threaded test execution. Although it is currently
39   * used by testng provider, the design does not really make sense (and is buggy).
40   * <p/>
41   * This is because to get correct results, the client basically needs to do something like this:
42   * synchronized( ReporterManger.getClass()){
43   * reporterManager.runStarted()
44   * reporterManager.testSetStarting()
45   * reporterManager.testStarting()
46   * reporterManager.testSucceeded()
47   * reporterManager.testSetCompleted()
48   * reporterManager.runCompleted()
49   * }
50   * <p/>
51   * This is because the underlying providers are singletons and keep state, if you remove the outer synchronized
52   * block, you may get mixups between results from different tests; although the end result (total test count etc)
53   * should probably be correct.
54   * <p/>
55   * <p/>
56   *
57   * @noinspection deprecation
58   */
59  class SynchronizedReporterManager
60      implements RunListener
61  {
62  
63      private final RunListener target;
64  
65      public SynchronizedReporterManager( RunListener target )
66      {
67          this.target = target;
68      }
69  
70      public synchronized void testSetStarting( ReportEntry report )
71          throws ReporterException
72      {
73          target.testSetStarting( report );
74      }
75  
76      public synchronized void testSetCompleted( ReportEntry report )
77          throws ReporterException
78      {
79          target.testSetCompleted( report );
80      }
81  
82      public synchronized void testStarting( ReportEntry report )
83      {
84          target.testStarting( report );
85      }
86  
87      public synchronized void testSucceeded( ReportEntry report )
88      {
89          target.testSucceeded( report );
90      }
91  
92      public synchronized void testSkipped( ReportEntry report )
93      {
94          target.testSkipped( report );
95      }
96  
97  
98      public synchronized void testError( ReportEntry reportEntry )
99      {
100         target.testError( reportEntry );
101     }
102 
103     public synchronized void testFailed( ReportEntry reportEntry )
104     {
105         target.testFailed( reportEntry );
106     }
107 
108     public synchronized void testAssumptionFailure( ReportEntry report )
109     {
110         target.testAssumptionFailure( report );
111     }
112 }