View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.surefire.junit;
20  
21  import org.apache.maven.surefire.api.report.OutputReportEntry;
22  import org.apache.maven.surefire.api.report.ReportEntry;
23  import org.apache.maven.surefire.api.report.RunListener;
24  import org.apache.maven.surefire.api.report.RunMode;
25  import org.apache.maven.surefire.api.report.TestOutputReceiver;
26  import org.apache.maven.surefire.api.report.TestOutputReportEntry;
27  import org.apache.maven.surefire.api.report.TestReportListener;
28  import org.apache.maven.surefire.api.report.TestSetReportEntry;
29  import org.apache.maven.surefire.report.ClassMethodIndexer;
30  import org.apache.maven.surefire.report.RunModeSetter;
31  
32  /**
33   * This implementation of {@link RunListener} handles {@link OutputReportEntry} in the
34   * {@link TestOutputReceiver output receiver}, downcasting to {@link TestOutputReportEntry}, and
35   * delegates the report entry to the {@link TestReportListener}.
36   * This object necessarily requires setting the {@link RunMode} in order to behave properly.
37   */
38  final class JUnit3Reporter implements RunListener, TestOutputReceiver<OutputReportEntry>, RunModeSetter {
39      private final ClassMethodIndexer classMethodIndexer = new ClassMethodIndexer();
40      private final TestReportListener<TestOutputReportEntry> reporter;
41      private volatile RunMode runMode;
42  
43      JUnit3Reporter(TestReportListener<TestOutputReportEntry> reporter) {
44          this.reporter = reporter;
45      }
46  
47      ClassMethodIndexer getClassMethodIndexer() {
48          return classMethodIndexer;
49      }
50  
51      @Override
52      public void setRunMode(RunMode runMode) {
53          this.runMode = runMode;
54      }
55  
56      @Override
57      public void testSetStarting(TestSetReportEntry report) {
58          reporter.testSetStarting(report);
59      }
60  
61      @Override
62      public void testSetCompleted(TestSetReportEntry report) {
63          reporter.testSetCompleted(report);
64      }
65  
66      @Override
67      public void testStarting(ReportEntry report) {
68          reporter.testStarting(report);
69      }
70  
71      @Override
72      public void testSucceeded(ReportEntry report) {
73          reporter.testSucceeded(report);
74      }
75  
76      @Override
77      public void testAssumptionFailure(ReportEntry report) {
78          reporter.testAssumptionFailure(report);
79      }
80  
81      @Override
82      public void testError(ReportEntry report) {
83          reporter.testError(report);
84      }
85  
86      @Override
87      public void testFailed(ReportEntry report) {
88          reporter.testFailed(report);
89      }
90  
91      @Override
92      public void testSkipped(ReportEntry report) {
93          reporter.testSkipped(report);
94      }
95  
96      @Override
97      public void testExecutionSkippedByUser() {
98          reporter.testExecutionSkippedByUser();
99      }
100 
101     @Override
102     public void writeTestOutput(OutputReportEntry reportEntry) {
103         Long testRunId = classMethodIndexer.getLocalIndex();
104         reporter.writeTestOutput(new TestOutputReportEntry(reportEntry, runMode, testRunId));
105     }
106 }