26
26
27
27
import org .junit .jupiter .api .Disabled ;
28
28
import org .junit .jupiter .api .Test ;
29
+ import org .junit .platform .engine .TestSource ;
29
30
import org .junit .platform .engine .discovery .ClassNameFilter ;
30
31
import org .junit .platform .engine .support .descriptor .ClassSource ;
32
+ import org .junit .platform .engine .support .descriptor .MethodSource ;
31
33
import org .junit .platform .launcher .LauncherDiscoveryRequest ;
32
34
import org .junit .platform .launcher .TestIdentifier ;
33
35
import org .junit .platform .launcher .core .LauncherDiscoveryRequestBuilder ;
@@ -176,18 +178,7 @@ private static void runTestsInAotMode(long expectedNumTests, List<Class<?>> test
176
178
summary .printTo (new PrintWriter (System .err ));
177
179
}
178
180
if (summary .getTotalFailureCount () > 0 ) {
179
- System .err .println ("Failing Test Classes:" );
180
- summary .getFailures ().stream ()
181
- .map (Failure ::getTestIdentifier )
182
- .map (TestIdentifier ::getSource )
183
- .flatMap (Optional ::stream )
184
- .filter (ClassSource .class ::isInstance )
185
- .map (ClassSource .class ::cast )
186
- .map (AotIntegrationTests ::getJavaClass )
187
- .flatMap (Optional ::stream )
188
- .map (Class ::getName )
189
- .forEach (System .err ::println );
190
- System .err .println ();
181
+ printFailingTestClasses (summary );
191
182
List <Throwable > exceptions = summary .getFailures ().stream ().map (Failure ::getException ).toList ();
192
183
throw new MultipleFailuresError ("Test execution failures" , exceptions );
193
184
}
@@ -200,6 +191,30 @@ private static void runTestsInAotMode(long expectedNumTests, List<Class<?>> test
200
191
}
201
192
}
202
193
194
+ private static void printFailingTestClasses (TestExecutionSummary summary ) {
195
+ System .err .println ("Failing Test Classes:" );
196
+ summary .getFailures ().stream ()
197
+ .map (Failure ::getTestIdentifier )
198
+ .map (TestIdentifier ::getSource )
199
+ .flatMap (Optional ::stream )
200
+ .map (TestSource .class ::cast )
201
+ .map (source -> {
202
+ if (source instanceof ClassSource classSource ) {
203
+ return getJavaClass (classSource );
204
+ }
205
+ else if (source instanceof MethodSource methodSource ) {
206
+ return getJavaClass (methodSource );
207
+ }
208
+ return Optional .<Class <?>> empty ();
209
+ })
210
+ .flatMap (Optional ::stream )
211
+ .map (Class ::getName )
212
+ .distinct ()
213
+ .sorted ()
214
+ .forEach (System .err ::println );
215
+ System .err .println ();
216
+ }
217
+
203
218
private static Optional <Class <?>> getJavaClass (ClassSource classSource ) {
204
219
try {
205
220
return Optional .of (classSource .getJavaClass ());
@@ -210,6 +225,16 @@ private static Optional<Class<?>> getJavaClass(ClassSource classSource) {
210
225
}
211
226
}
212
227
228
+ private static Optional <Class <?>> getJavaClass (MethodSource methodSource ) {
229
+ try {
230
+ return Optional .of (methodSource .getJavaClass ());
231
+ }
232
+ catch (Exception ex ) {
233
+ // ignore exception
234
+ return Optional .empty ();
235
+ }
236
+ }
237
+
213
238
private static TestClassScanner createTestClassScanner () {
214
239
String classpathRoot = System .getProperty (CLASSPATH_ROOT );
215
240
assertThat (classpathRoot ).as (CLASSPATH_ROOT ).isNotNull ();
0 commit comments