1 | |
package org.apache.maven.surefire.junitcore; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.surefire.common.junit4.JUnit4RunListener; |
23 | |
import org.apache.maven.surefire.report.ConsoleOutputReceiver; |
24 | |
import org.apache.maven.surefire.report.RunListener; |
25 | |
import org.apache.maven.surefire.report.SimpleReportEntry; |
26 | |
import org.apache.maven.surefire.testset.TestSetFailedException; |
27 | |
|
28 | |
import org.junit.runner.Description; |
29 | |
import org.junit.runner.Result; |
30 | |
import org.junit.runner.notification.Failure; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class NonConcurrentRunListener |
38 | |
extends JUnit4RunListener |
39 | |
implements ConsoleOutputReceiver |
40 | |
{ |
41 | |
|
42 | |
private java.lang.Class<?> currentTestClass; |
43 | |
|
44 | |
private Description lastFinishedDescription; |
45 | |
|
46 | |
public NonConcurrentRunListener( RunListener reporter ) |
47 | |
throws TestSetFailedException |
48 | |
{ |
49 | 0 | super( reporter ); |
50 | 0 | } |
51 | |
|
52 | |
public synchronized void writeTestOutput( byte[] buf, int off, int len, boolean stdout ) |
53 | |
{ |
54 | |
|
55 | 0 | ( (ConsoleOutputReceiver) reporter ).writeTestOutput( buf, off, len, stdout ); |
56 | 0 | } |
57 | |
|
58 | |
protected SimpleReportEntry createReportEntry( Description description ) |
59 | |
{ |
60 | 0 | return new SimpleReportEntry( description.getClassName(), description.getDisplayName() |
61 | |
); |
62 | |
} |
63 | |
|
64 | |
protected SimpleReportEntry createReportEntryForTestSet( Description description ) |
65 | |
{ |
66 | 0 | return new SimpleReportEntry( description.getClassName(), description.getClassName() |
67 | |
); |
68 | |
} |
69 | |
|
70 | |
@Override |
71 | |
public void testStarted( Description description ) |
72 | |
throws Exception |
73 | |
{ |
74 | 0 | finishLastTestSetIfNeccessary( description ); |
75 | 0 | super.testStarted( description ); |
76 | 0 | } |
77 | |
|
78 | |
private void finishLastTestSetIfNeccessary( Description description ) |
79 | |
{ |
80 | 0 | if ( !description.getTestClass().equals( currentTestClass ) ) |
81 | |
{ |
82 | 0 | currentTestClass = description.getTestClass(); |
83 | 0 | if ( lastFinishedDescription != null ) |
84 | |
{ |
85 | 0 | reporter.testSetCompleted( createReportEntryForTestSet( lastFinishedDescription ) ); |
86 | 0 | lastFinishedDescription = null; |
87 | |
} |
88 | 0 | reporter.testSetStarting( createReportEntryForTestSet( description ) ); |
89 | |
} |
90 | 0 | } |
91 | |
|
92 | |
@Override |
93 | |
public void testFinished( Description description ) |
94 | |
throws Exception |
95 | |
{ |
96 | 0 | super.testFinished( description ); |
97 | 0 | this.lastFinishedDescription = description; |
98 | 0 | } |
99 | |
|
100 | |
@Override |
101 | |
public void testIgnored( Description description ) |
102 | |
throws Exception |
103 | |
{ |
104 | 0 | finishLastTestSetIfNeccessary( description ); |
105 | |
|
106 | 0 | super.testIgnored( description ); |
107 | 0 | this.lastFinishedDescription = description; |
108 | 0 | } |
109 | |
|
110 | |
@Override |
111 | |
public void testFailure( Failure failure ) |
112 | |
throws Exception |
113 | |
{ |
114 | 0 | super.testFailure( failure ); |
115 | 0 | this.lastFinishedDescription = failure.getDescription(); |
116 | 0 | } |
117 | |
|
118 | |
@Override |
119 | |
public void testAssumptionFailure( Failure failure ) |
120 | |
{ |
121 | 0 | super.testAssumptionFailure( failure ); |
122 | 0 | this.lastFinishedDescription = failure.getDescription(); |
123 | 0 | } |
124 | |
|
125 | |
@Override |
126 | |
public void testRunStarted( Description description ) |
127 | |
throws Exception |
128 | |
{ |
129 | 0 | } |
130 | |
|
131 | |
@Override |
132 | |
public void testRunFinished( Result result ) |
133 | |
throws Exception |
134 | |
{ |
135 | 0 | if ( lastFinishedDescription != null ) |
136 | |
{ |
137 | 0 | reporter.testSetCompleted( createReportEntryForTestSet( lastFinishedDescription ) ); |
138 | 0 | lastFinishedDescription = null; |
139 | |
} |
140 | 0 | } |
141 | |
} |