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  /**
23   * Ensures that the current thread has a RunListener instance attached, and forwards calls to it.
24   * @author Kristian Rosenvold
25   */
26  public class ThreadLocalRunListener implements RunListener
27  {
28      private final InheritableThreadLocal target = new InheritableThreadLocal();
29  
30      private final ReporterFactory reporterFactory;
31  
32  
33      public RunListener getTarget()
34      {
35          Object o = target.get();
36          if (o == null){
37              o = reporterFactory.createReporter();
38              target.set(o);
39          }
40          return (RunListener) o;
41      }
42  
43      public ThreadLocalRunListener(ReporterFactory reporterFactory)
44      {
45          this.reporterFactory = reporterFactory;
46      }
47  
48      public void testSetStarting( ReportEntry report )
49      {
50          getTarget().testSetStarting( report );
51      }
52  
53      public void testSetCompleted( ReportEntry report )
54      {
55          getTarget().testSetCompleted( report );
56      }
57  
58      public void testStarting( ReportEntry report )
59      {
60          getTarget().testStarting( report );
61      }
62  
63      public void testSucceeded( ReportEntry report )
64      {
65          getTarget().testSucceeded( report );
66      }
67  
68      public void testAssumptionFailure( ReportEntry report )
69      {
70          getTarget().testAssumptionFailure( report );
71      }
72  
73      public void testError( ReportEntry report )
74      {
75          getTarget().testError( report );
76      }
77  
78      public void testFailed( ReportEntry report )
79      {
80          getTarget().testFailed( report );
81      }
82  
83      public void testSkipped( ReportEntry report )
84      {
85          getTarget().testSkipped( report );
86      }
87  
88  }