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 | |
import org.junit.runner.Description; |
28 | |
import org.junit.runner.Result; |
29 | |
import org.junit.runner.notification.Failure; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class NonConcurrentRunListener |
37 | |
extends JUnit4RunListener |
38 | |
implements ConsoleOutputReceiver |
39 | |
{ |
40 | |
|
41 | |
private Description currentTestSetDescription; |
42 | |
|
43 | |
private Description lastFinishedDescription; |
44 | |
|
45 | |
public NonConcurrentRunListener( RunListener reporter ) |
46 | |
throws TestSetFailedException |
47 | |
{ |
48 | 0 | super( reporter ); |
49 | 0 | } |
50 | |
|
51 | |
public synchronized void writeTestOutput( byte[] buf, int off, int len, boolean stdout ) |
52 | |
{ |
53 | |
|
54 | 0 | ( (ConsoleOutputReceiver) reporter ).writeTestOutput( buf, off, len, stdout ); |
55 | 0 | } |
56 | |
|
57 | |
protected SimpleReportEntry createReportEntry( Description description ) |
58 | |
{ |
59 | 0 | return new SimpleReportEntry( description.getClassName(), description.getDisplayName() |
60 | |
|
61 | |
|
62 | |
|
63 | |
); |
64 | |
} |
65 | |
|
66 | |
protected SimpleReportEntry createReportEntryForTestSet( Description description ) |
67 | |
{ |
68 | 0 | return new SimpleReportEntry( description.getClassName(), description.getClassName() |
69 | |
|
70 | |
|
71 | |
|
72 | |
); |
73 | |
} |
74 | |
|
75 | |
@Override |
76 | |
public void testStarted( Description description ) |
77 | |
throws Exception |
78 | |
{ |
79 | 0 | finishLastTestSetIfNeccessary( description ); |
80 | 0 | super.testStarted( description ); |
81 | 0 | } |
82 | |
|
83 | |
private void finishLastTestSetIfNeccessary( Description description ) |
84 | |
{ |
85 | 0 | if ( describesNewTestSet( description ) ) |
86 | |
{ |
87 | 0 | currentTestSetDescription = description; |
88 | 0 | if ( lastFinishedDescription != null ) |
89 | |
{ |
90 | 0 | reporter.testSetCompleted( createReportEntryForTestSet( lastFinishedDescription ) ); |
91 | 0 | lastFinishedDescription = null; |
92 | |
} |
93 | 0 | reporter.testSetStarting( createReportEntryForTestSet( description ) ); |
94 | |
} |
95 | 0 | } |
96 | |
|
97 | |
private boolean describesNewTestSet( Description description ) |
98 | |
{ |
99 | 0 | if ( currentTestSetDescription != null ) |
100 | |
{ |
101 | 0 | if ( null != description.getTestClass() ) |
102 | |
{ |
103 | 0 | return !description.getTestClass().equals( currentTestSetDescription.getTestClass() ); |
104 | |
} |
105 | 0 | else if ( description.isSuite() ) |
106 | |
{ |
107 | 0 | return description.getChildren().equals( currentTestSetDescription.getChildren() ); |
108 | |
} |
109 | |
|
110 | 0 | return false; |
111 | |
} |
112 | |
|
113 | 0 | return true; |
114 | |
} |
115 | |
|
116 | |
@Override |
117 | |
public void testFinished( Description description ) |
118 | |
throws Exception |
119 | |
{ |
120 | 0 | super.testFinished( description ); |
121 | 0 | this.lastFinishedDescription = description; |
122 | 0 | } |
123 | |
|
124 | |
@Override |
125 | |
public void testIgnored( Description description ) |
126 | |
throws Exception |
127 | |
{ |
128 | 0 | finishLastTestSetIfNeccessary( description ); |
129 | |
|
130 | 0 | super.testIgnored( description ); |
131 | 0 | this.lastFinishedDescription = description; |
132 | 0 | } |
133 | |
|
134 | |
@Override |
135 | |
public void testFailure( Failure failure ) |
136 | |
throws Exception |
137 | |
{ |
138 | 0 | super.testFailure( failure ); |
139 | 0 | this.lastFinishedDescription = failure.getDescription(); |
140 | 0 | } |
141 | |
|
142 | |
@Override |
143 | |
public void testAssumptionFailure( Failure failure ) |
144 | |
{ |
145 | 0 | super.testAssumptionFailure( failure ); |
146 | 0 | this.lastFinishedDescription = failure.getDescription(); |
147 | 0 | } |
148 | |
|
149 | |
@Override |
150 | |
public void testRunStarted( Description description ) |
151 | |
throws Exception |
152 | |
{ |
153 | 0 | } |
154 | |
|
155 | |
@Override |
156 | |
public void testRunFinished( Result result ) |
157 | |
throws Exception |
158 | |
{ |
159 | 0 | if ( lastFinishedDescription != null ) |
160 | |
{ |
161 | 0 | reporter.testSetCompleted( createReportEntryForTestSet( lastFinishedDescription ) ); |
162 | 0 | lastFinishedDescription = null; |
163 | |
} |
164 | 0 | } |
165 | |
} |