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  import java.util.Iterator;
23  import java.util.List;
24  
25  /**
26   * A reporter that broadcasts to other reporters
27   *
28   * @author Kristian Rosenvold
29   */
30  public class MulticastingReporter
31      implements RunReporter, Reporter
32  {
33      private final List target;
34  
35      public MulticastingReporter( List target )
36      {
37          this.target = target;
38      }
39  
40      public void testSetStarting( ReportEntry report )
41          throws ReporterException
42      {
43          for ( Iterator it = target.iterator(); it.hasNext(); )
44          {
45              ( (Reporter) it.next() ).testSetStarting( report );
46          }
47      }
48  
49      public void testSetCompleted( ReportEntry report )
50      {
51          for ( Iterator it = target.iterator(); it.hasNext(); )
52          {
53              try
54              {
55                  ( (Reporter) it.next() ).testSetCompleted( report );
56              }
57              catch ( ReporterException e )
58              {
59                  // Added in commit r331325 in ReporterManager. This smells fishy. What's this about ?
60              }
61  
62          }
63      }
64  
65  
66      public void runStarting()
67      {
68          for ( Iterator it = target.iterator(); it.hasNext(); )
69          {
70              Object next = it.next();
71              if ( next instanceof RunReporter )
72              {
73                  ( (RunReporter) next ).runStarting();
74              }
75          }
76      }
77  
78      public void runCompleted()
79      {
80          for ( Iterator it = target.iterator(); it.hasNext(); )
81          {
82              Object next = it.next();
83              if ( next instanceof RunReporter )
84              {
85                  ( (RunReporter) next ).runCompleted();
86              }
87          }
88      }
89  
90  
91      public void testStarting( ReportEntry report )
92      {
93          for ( Iterator it = target.iterator(); it.hasNext(); )
94          {
95              ( (Reporter) it.next() ).testStarting( report );
96          }
97      }
98  
99      public void testSucceeded( ReportEntry report )
100     {
101         for ( Iterator it = target.iterator(); it.hasNext(); )
102         {
103             ( (Reporter) it.next() ).testSucceeded( report );
104         }
105     }
106 
107     public void testError( ReportEntry report, String stdOut, String stdErr )
108     {
109         for ( Iterator it = target.iterator(); it.hasNext(); )
110         {
111             ( (Reporter) it.next() ).testError( report, stdOut, stdErr );
112         }
113     }
114 
115     public void testFailed( ReportEntry report, String stdOut, String stdErr )
116     {
117         for ( Iterator it = target.iterator(); it.hasNext(); )
118         {
119             ( (Reporter) it.next() ).testFailed( report, stdOut, stdErr );
120         }
121     }
122 
123     public void testSkipped( ReportEntry report )
124     {
125         for ( Iterator it = target.iterator(); it.hasNext(); )
126         {
127             ( (Reporter) it.next() ).testSkipped( report );
128         }
129     }
130 
131     public void writeDetailMessage( String message )
132     {
133         for ( Iterator it = target.iterator(); it.hasNext(); )
134         {
135             Reporter reporter = ( (Reporter) it.next() );
136             reporter.writeDetailMessage( message );
137         }
138     }
139 
140     public void writeMessage( String message )
141     {
142         for ( Iterator it = target.iterator(); it.hasNext(); )
143         {
144             ( (Reporter) it.next() ).writeMessage( message );
145         }
146     }
147 
148     public void writeFooter( String footer )
149     {
150         for ( Iterator it = target.iterator(); it.hasNext(); )
151         {
152             ( (Reporter) it.next() ).writeFooter( footer );
153         }
154     }
155 
156     public void reset()
157     {
158         for ( Iterator it = target.iterator(); it.hasNext(); )
159         {
160             ( (Reporter) it.next() ).reset();
161         }
162     }
163 
164     public void testError( ReportEntry report )
165     {
166         for ( Iterator it = target.iterator(); it.hasNext(); )
167         {
168             ( (Reporter) it.next() ).testError( report );
169         }
170     }
171 
172     public void testFailed( ReportEntry report )
173     {
174         for ( Iterator it = target.iterator(); it.hasNext(); )
175         {
176             ( (Reporter) it.next() ).testFailed( report );
177         }
178     }
179 
180 }