Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SynchronizedReporterManager |
|
| 1.0;1 |
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 | 0 | { |
67 | 0 | this.target = target; |
68 | 0 | } |
69 | ||
70 | public synchronized void testSetStarting( ReportEntry report ) | |
71 | throws ReporterException | |
72 | { | |
73 | 0 | target.testSetStarting( report ); |
74 | 0 | } |
75 | ||
76 | public synchronized void testSetCompleted( ReportEntry report ) | |
77 | throws ReporterException | |
78 | { | |
79 | 0 | target.testSetCompleted( report ); |
80 | 0 | } |
81 | ||
82 | public synchronized void testStarting( ReportEntry report ) | |
83 | { | |
84 | 0 | target.testStarting( report ); |
85 | 0 | } |
86 | ||
87 | public synchronized void testSucceeded( ReportEntry report ) | |
88 | { | |
89 | 0 | target.testSucceeded( report ); |
90 | 0 | } |
91 | ||
92 | public synchronized void testSkipped( ReportEntry report ) | |
93 | { | |
94 | 0 | target.testSkipped( report ); |
95 | 0 | } |
96 | ||
97 | ||
98 | public synchronized void testError( ReportEntry reportEntry ) | |
99 | { | |
100 | 0 | target.testError( reportEntry ); |
101 | 0 | } |
102 | ||
103 | public synchronized void testFailed( ReportEntry reportEntry ) | |
104 | { | |
105 | 0 | target.testFailed( reportEntry ); |
106 | 0 | } |
107 | ||
108 | public synchronized void testAssumptionFailure( ReportEntry report ) | |
109 | { | |
110 | 0 | target.testAssumptionFailure( report ); |
111 | 0 | } |
112 | } |