@@ -152,7 +152,9 @@ public final List<TestExecutionListener> getTestExecutionListeners() {
152152listeners .addAll (getDefaultTestExecutionListeners ());
153153}
154154
155- listeners .addAll (0 , instantiateListeners (testExecutionListeners .listeners ()));
155+ if (testExecutionListeners .listeners ().length > 0 ) {
156+ listeners .addAll (0 , instantiateListeners (testExecutionListeners .listeners ()));
157+ }
156158
157159descriptor = (inheritListeners ? parentDescriptor : null );
158160}
@@ -316,17 +318,25 @@ private MergedContextConfiguration buildMergedContextConfiguration(Class<?> test
316318}
317319if (contextLoader instanceof SmartContextLoader smartContextLoader ) {
318320smartContextLoader .processContextConfiguration (configAttributes );
319- locations .addAll (0 , Arrays .asList (configAttributes .getLocations ()));
320- classes .addAll (0 , Arrays .asList (configAttributes .getClasses ()));
321+ if (configAttributes .getLocations ().length > 0 ) {
322+ locations .addAll (0 , Arrays .asList (configAttributes .getLocations ()));
323+ }
324+ if (configAttributes .getClasses ().length > 0 ) {
325+ classes .addAll (0 , Arrays .asList (configAttributes .getClasses ()));
326+ }
321327}
322328else {
323329@ SuppressWarnings ("deprecation" )
324330String [] processedLocations = contextLoader .processLocations (
325331configAttributes .getDeclaringClass (), configAttributes .getLocations ());
326- locations .addAll (0 , Arrays .asList (processedLocations ));
332+ if (processedLocations .length > 0 ) {
333+ locations .addAll (0 , Arrays .asList (processedLocations ));
334+ }
327335// Legacy ContextLoaders don't know how to process classes
328336}
329- initializers .addAll (0 , Arrays .asList (configAttributes .getInitializers ()));
337+ if (configAttributes .getInitializers ().length > 0 ) {
338+ initializers .addAll (0 , Arrays .asList (configAttributes .getInitializers ()));
339+ }
330340if (!configAttributes .isInheritLocations ()) {
331341break ;
332342}
@@ -401,7 +411,9 @@ private List<ContextCustomizerFactory> getContextCustomizerFactories(Class<?> te
401411
402412boolean inheritFactories = annotation .inheritFactories ();
403413AnnotationDescriptor <ContextCustomizerFactories > parentDescriptor = descriptor .next ();
404- factories .addAll (0 , instantiateCustomizerFactories (annotation .factories ()));
414+ if (annotation .factories ().length > 0 ) {
415+ factories .addAll (0 , instantiateCustomizerFactories (annotation .factories ()));
416+ }
405417
406418// If there are no factories to inherit, we might need to merge the
407419// locally declared factories with the defaults.
0 commit comments