11/*
2- * Copyright 2002-2016 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.
2020import java .util .Arrays ;
2121import java .util .Collection ;
2222import java .util .Collections ;
23- import java .util .HashSet ;
2423import java .util .LinkedHashSet ;
2524import java .util .List ;
2625import java .util .Map ;
@@ -82,17 +81,11 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
8281 private BootstrapContext bootstrapContext ;
8382
8483
85- /**
86- * {@inheritDoc}
87- */
8884 @ Override
8985 public void setBootstrapContext (BootstrapContext bootstrapContext ) {
9086 this .bootstrapContext = bootstrapContext ;
9187 }
9288
93- /**
94- * {@inheritDoc}
95- */
9689 @ Override
9790 public BootstrapContext getBootstrapContext () {
9891 return this .bootstrapContext ;
@@ -113,9 +106,6 @@ public TestContext buildTestContext() {
113106 getCacheAwareContextLoaderDelegate ());
114107 }
115108
116- /**
117- * {@inheritDoc}
118- */
119109 @ Override
120110 public final List <TestExecutionListener > getTestExecutionListeners () {
121111 Class <?> clazz = getBootstrapContext ().getTestClass ();
@@ -168,28 +158,25 @@ public final List<TestExecutionListener> getTestExecutionListeners() {
168158 }
169159 }
170160
161+ Collection <Class <? extends TestExecutionListener >> classesToUse = classesList ;
171162 // Remove possible duplicates if we loaded default listeners.
172163 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 );
177165 }
178166
179- List <TestExecutionListener > listeners = instantiateListeners (classesList );
180-
167+ List <TestExecutionListener > listeners = instantiateListeners (classesToUse );
181168 // Sort by Ordered/@Order if we loaded default listeners.
182169 if (usingDefaults ) {
183170 AnnotationAwareOrderComparator .sort (listeners );
184171 }
185172
186173 if (logger .isInfoEnabled ()) {
187- logger .info (String . format ( "Using TestExecutionListeners: %s" , listeners ) );
174+ logger .info ("Using TestExecutionListeners: " + listeners );
188175 }
189176 return listeners ;
190177 }
191178
192- private List <TestExecutionListener > instantiateListeners (List <Class <? extends TestExecutionListener >> classesList ) {
179+ private List <TestExecutionListener > instantiateListeners (Collection <Class <? extends TestExecutionListener >> classesList ) {
193180 List <TestExecutionListener > listeners = new ArrayList <TestExecutionListener >(classesList .size ());
194181 for (Class <? extends TestExecutionListener > listenerClass : classesList ) {
195182 NoClassDefFoundError ncdfe = null ;
@@ -200,13 +187,14 @@ private List<TestExecutionListener> instantiateListeners(List<Class<? extends Te
200187 ncdfe = err ;
201188 }
202189 catch (BeanInstantiationException ex ) {
203- if (ex .getCause () instanceof NoClassDefFoundError ) {
204- ncdfe = ( NoClassDefFoundError ) ex . getCause () ;
190+ if (!( ex .getCause () instanceof NoClassDefFoundError ) ) {
191+ throw ex ;
205192 }
193+ ncdfe = (NoClassDefFoundError ) ex .getCause ();
206194 }
207195 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]. " +
210198 "Specify custom listener classes or make the default listener classes " +
211199 "(and their required dependencies) available. Offending class: [%s]" ,
212200 listenerClass .getName (), ncdfe .getMessage ()));
0 commit comments