1
1
/*
2
- * Copyright 2002-2016 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 ;
@@ -82,17 +81,11 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
82
81
private BootstrapContext bootstrapContext ;
83
82
84
83
85
- /**
86
- * {@inheritDoc}
87
- */
88
84
@ Override
89
85
public void setBootstrapContext (BootstrapContext bootstrapContext ) {
90
86
this .bootstrapContext = bootstrapContext ;
91
87
}
92
88
93
- /**
94
- * {@inheritDoc}
95
- */
96
89
@ Override
97
90
public BootstrapContext getBootstrapContext () {
98
91
return this .bootstrapContext ;
@@ -113,9 +106,6 @@ public TestContext buildTestContext() {
113
106
getCacheAwareContextLoaderDelegate ());
114
107
}
115
108
116
- /**
117
- * {@inheritDoc}
118
- */
119
109
@ Override
120
110
public final List <TestExecutionListener > getTestExecutionListeners () {
121
111
Class <?> clazz = getBootstrapContext ().getTestClass ();
@@ -168,28 +158,25 @@ public final List<TestExecutionListener> getTestExecutionListeners() {
168
158
}
169
159
}
170
160
161
+ Collection <Class <? extends TestExecutionListener >> classesToUse = classesList ;
171
162
// Remove possible duplicates if we loaded default listeners.
172
163
if (usingDefaults ) {
173
- Set <Class <? extends TestExecutionListener >> classesSet = new HashSet <Class <? extends TestExecutionListener >>();
174
- classesSet .addAll (classesList );
175
- classesList .clear ();
176
- classesList .addAll (classesSet );
164
+ classesToUse = new LinkedHashSet <Class <? extends TestExecutionListener >>(classesList );
177
165
}
178
166
179
- List <TestExecutionListener > listeners = instantiateListeners (classesList );
180
-
167
+ List <TestExecutionListener > listeners = instantiateListeners (classesToUse );
181
168
// Sort by Ordered/@Order if we loaded default listeners.
182
169
if (usingDefaults ) {
183
170
AnnotationAwareOrderComparator .sort (listeners );
184
171
}
185
172
186
173
if (logger .isInfoEnabled ()) {
187
- logger .info (String . format ( "Using TestExecutionListeners: %s" , listeners ) );
174
+ logger .info ("Using TestExecutionListeners: " + listeners );
188
175
}
189
176
return listeners ;
190
177
}
191
178
192
- private List <TestExecutionListener > instantiateListeners (List <Class <? extends TestExecutionListener >> classesList ) {
179
+ private List <TestExecutionListener > instantiateListeners (Collection <Class <? extends TestExecutionListener >> classesList ) {
193
180
List <TestExecutionListener > listeners = new ArrayList <TestExecutionListener >(classesList .size ());
194
181
for (Class <? extends TestExecutionListener > listenerClass : classesList ) {
195
182
NoClassDefFoundError ncdfe = null ;
@@ -200,13 +187,14 @@ private List<TestExecutionListener> instantiateListeners(List<Class<? extends Te
200
187
ncdfe = err ;
201
188
}
202
189
catch (BeanInstantiationException ex ) {
203
- if (ex .getCause () instanceof NoClassDefFoundError ) {
204
- ncdfe = ( NoClassDefFoundError ) ex . getCause () ;
190
+ if (!( ex .getCause () instanceof NoClassDefFoundError ) ) {
191
+ throw ex ;
205
192
}
193
+ ncdfe = (NoClassDefFoundError ) ex .getCause ();
206
194
}
207
195
if (ncdfe != null ) {
208
- if (logger .isInfoEnabled ()) {
209
- logger .info (String .format ("Could not instantiate TestExecutionListener [%s]. " +
196
+ if (logger .isDebugEnabled ()) {
197
+ logger .debug (String .format ("Could not instantiate TestExecutionListener [%s]. " +
210
198
"Specify custom listener classes or make the default listener classes " +
211
199
"(and their required dependencies) available. Offending class: [%s]" ,
212
200
listenerClass .getName (), ncdfe .getMessage ()));
0 commit comments