|
1 | 1 | /* |
2 | | - * Copyright 2002-2017 the original author or authors. |
| 2 | + * Copyright 2002-2018 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
20 | 20 | import java.util.Arrays; |
21 | 21 | import java.util.Collection; |
22 | 22 | import java.util.Collections; |
23 | | -import java.util.HashSet; |
24 | 23 | import java.util.LinkedHashSet; |
25 | 24 | import java.util.List; |
26 | 25 | import java.util.Map; |
|
29 | 28 | import org.apache.commons.logging.Log; |
30 | 29 | import org.apache.commons.logging.LogFactory; |
31 | 30 |
|
32 | | -import org.springframework.beans.BeanInstantiationException; |
33 | 31 | import org.springframework.beans.BeanUtils; |
34 | 32 | import org.springframework.core.annotation.AnnotationAwareOrderComparator; |
35 | 33 | import org.springframework.core.annotation.AnnotationUtils; |
@@ -110,9 +108,6 @@ public TestContext buildTestContext() { |
110 | 108 | getCacheAwareContextLoaderDelegate()); |
111 | 109 | } |
112 | 110 |
|
113 | | - /** |
114 | | - * {@inheritDoc} |
115 | | - */ |
116 | 111 | @Override |
117 | 112 | public final List<TestExecutionListener> getTestExecutionListeners() { |
118 | 113 | Class<?> clazz = getBootstrapContext().getTestClass(); |
@@ -165,48 +160,36 @@ public final List<TestExecutionListener> getTestExecutionListeners() { |
165 | 160 | } |
166 | 161 | } |
167 | 162 |
|
| 163 | + Collection<Class<? extends TestExecutionListener>> classesToUse = classesList; |
168 | 164 | // Remove possible duplicates if we loaded default listeners. |
169 | 165 | 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); |
174 | 167 | } |
175 | 168 |
|
176 | | - List<TestExecutionListener> listeners = instantiateListeners(classesList); |
177 | | - |
| 169 | + List<TestExecutionListener> listeners = instantiateListeners(classesToUse); |
178 | 170 | // Sort by Ordered/@Order if we loaded default listeners. |
179 | 171 | if (usingDefaults) { |
180 | 172 | AnnotationAwareOrderComparator.sort(listeners); |
181 | 173 | } |
182 | 174 |
|
183 | 175 | if (logger.isInfoEnabled()) { |
184 | | - logger.info(String.format("Using TestExecutionListeners: %s", listeners)); |
| 176 | + logger.info("Using TestExecutionListeners: " + listeners); |
185 | 177 | } |
186 | 178 | return listeners; |
187 | 179 | } |
188 | 180 |
|
189 | | - private List<TestExecutionListener> instantiateListeners(List<Class<? extends TestExecutionListener>> classesList) { |
| 181 | + private List<TestExecutionListener> instantiateListeners(Collection<Class<? extends TestExecutionListener>> classesList) { |
190 | 182 | List<TestExecutionListener> listeners = new ArrayList<>(classesList.size()); |
191 | 183 | for (Class<? extends TestExecutionListener> listenerClass : classesList) { |
192 | | - NoClassDefFoundError ncdfe = null; |
193 | 184 | try { |
194 | 185 | listeners.add(BeanUtils.instantiateClass(listenerClass)); |
195 | 186 | } |
196 | 187 | 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]. " + |
207 | 190 | "Specify custom listener classes or make the default listener classes " + |
208 | 191 | "(and their required dependencies) available. Offending class: [%s]", |
209 | | - listenerClass.getName(), ncdfe.getMessage())); |
| 192 | + listenerClass.getName(), err.getMessage())); |
210 | 193 | } |
211 | 194 | } |
212 | 195 | } |
|
0 commit comments