Skip to content

Commit a15975d

Browse files
committed
Log non-loadable TestExecutionListener classes at debug level only
Issue: SPR-16369
1 parent 93f6458 commit a15975d

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
2020
import java.util.Arrays;
2121
import java.util.Collection;
2222
import java.util.Collections;
23-
import java.util.HashSet;
2423
import java.util.LinkedHashSet;
2524
import java.util.List;
2625
import java.util.Map;
@@ -29,7 +28,6 @@
2928
import org.apache.commons.logging.Log;
3029
import org.apache.commons.logging.LogFactory;
3130

32-
import org.springframework.beans.BeanInstantiationException;
3331
import org.springframework.beans.BeanUtils;
3432
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
3533
import org.springframework.core.annotation.AnnotationUtils;
@@ -110,9 +108,6 @@ public TestContext buildTestContext() {
110108
getCacheAwareContextLoaderDelegate());
111109
}
112110

113-
/**
114-
* {@inheritDoc}
115-
*/
116111
@Override
117112
public final List<TestExecutionListener> getTestExecutionListeners() {
118113
Class<?> clazz = getBootstrapContext().getTestClass();
@@ -165,48 +160,36 @@ public final List<TestExecutionListener> getTestExecutionListeners() {
165160
}
166161
}
167162

163+
Collection<Class<? extends TestExecutionListener>> classesToUse = classesList;
168164
// Remove possible duplicates if we loaded default listeners.
169165
if (usingDefaults) {
170-
Set<Class<? extends TestExecutionListener>> classesSet = new HashSet<>();
171-
classesSet.addAll(classesList);
172-
classesList.clear();
173-
classesList.addAll(classesSet);
166+
classesToUse = new LinkedHashSet<>(classesList);
174167
}
175168

176-
List<TestExecutionListener> listeners = instantiateListeners(classesList);
177-
169+
List<TestExecutionListener> listeners = instantiateListeners(classesToUse);
178170
// Sort by Ordered/@Order if we loaded default listeners.
179171
if (usingDefaults) {
180172
AnnotationAwareOrderComparator.sort(listeners);
181173
}
182174

183175
if (logger.isInfoEnabled()) {
184-
logger.info(String.format("Using TestExecutionListeners: %s", listeners));
176+
logger.info("Using TestExecutionListeners: " + listeners);
185177
}
186178
return listeners;
187179
}
188180

189-
private List<TestExecutionListener> instantiateListeners(List<Class<? extends TestExecutionListener>> classesList) {
181+
private List<TestExecutionListener> instantiateListeners(Collection<Class<? extends TestExecutionListener>> classesList) {
190182
List<TestExecutionListener> listeners = new ArrayList<>(classesList.size());
191183
for (Class<? extends TestExecutionListener> listenerClass : classesList) {
192-
NoClassDefFoundError ncdfe = null;
193184
try {
194185
listeners.add(BeanUtils.instantiateClass(listenerClass));
195186
}
196187
catch (NoClassDefFoundError err) {
197-
ncdfe = err;
198-
}
199-
catch (BeanInstantiationException ex) {
200-
if (ex.getCause() instanceof NoClassDefFoundError) {
201-
ncdfe = (NoClassDefFoundError) ex.getCause();
202-
}
203-
}
204-
if (ncdfe != null) {
205-
if (logger.isInfoEnabled()) {
206-
logger.info(String.format("Could not instantiate TestExecutionListener [%s]. " +
188+
if (logger.isDebugEnabled()) {
189+
logger.debug(String.format("Could not instantiate TestExecutionListener [%s]. " +
207190
"Specify custom listener classes or make the default listener classes " +
208191
"(and their required dependencies) available. Offending class: [%s]",
209-
listenerClass.getName(), ncdfe.getMessage()));
192+
listenerClass.getName(), err.getMessage()));
210193
}
211194
}
212195
}

0 commit comments

Comments
 (0)