diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java index 71cb8b9edc..57f18f4d84 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -29,7 +28,6 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanUtils; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationUtils; @@ -110,9 +108,6 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot getCacheAwareContextLoaderDelegate()); } - /** - * {@inheritDoc} - */ @Override public final List getTestExecutionListeners() { Class clazz = getBootstrapContext().getTestClass(); @@ -165,48 +160,36 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot } } + Collection> classesToUse = classesList; // Remove possible duplicates if we loaded default listeners. if (usingDefaults) { - Set> classesSet = new HashSet<>(); - classesSet.addAll(classesList); - classesList.clear(); - classesList.addAll(classesSet); + classesToUse = new LinkedHashSet<>(classesList); } - List listeners = instantiateListeners(classesList); - + List listeners = instantiateListeners(classesToUse); // Sort by Ordered/@Order if we loaded default listeners. if (usingDefaults) { AnnotationAwareOrderComparator.sort(listeners); } if (logger.isInfoEnabled()) { - logger.info(String.format("Using TestExecutionListeners: %s", listeners)); + logger.info("Using TestExecutionListeners: " + listeners); } return listeners; } - private List instantiateListeners(List> classesList) { + private List instantiateListeners(Collection> classesList) { List listeners = new ArrayList<>(classesList.size()); for (Class listenerClass : classesList) { - NoClassDefFoundError ncdfe = null; try { listeners.add(BeanUtils.instantiateClass(listenerClass)); } catch (NoClassDefFoundError err) { - ncdfe = err; - } - catch (BeanInstantiationException ex) { - if (ex.getCause() instanceof NoClassDefFoundError) { - ncdfe = (NoClassDefFoundError) ex.getCause(); - } - } - if (ncdfe != null) { - if (logger.isInfoEnabled()) { - logger.info(String.format("Could not instantiate TestExecutionListener [%s]. " + + if (logger.isDebugEnabled()) { + logger.debug(String.format("Could not instantiate TestExecutionListener [%s]. " + "Specify custom listener classes or make the default listener classes " + "(and their required dependencies) available. Offending class: [%s]", - listenerClass.getName(), ncdfe.getMessage())); + listenerClass.getName(), err.getMessage())); } } }