From 19640ec3f980b01497779533e15b258c96258693 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 19 Jan 2018 19:10:31 +0100 Subject: [PATCH] Log non-loadable TestExecutionListener classes at debug level only Issue: SPR-16369 --- .../AbstractTestContextBootstrapper.java | 34 ++++++------------- 1 file changed, 11 insertions(+), 23 deletions(-) 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 fb9e28c036a..937603d9f23 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-2016 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; @@ -82,17 +81,11 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot private BootstrapContext bootstrapContext; - /** - * {@inheritDoc} - */ @Override public void setBootstrapContext(BootstrapContext bootstrapContext) { this.bootstrapContext = bootstrapContext; } - /** - * {@inheritDoc} - */ @Override public BootstrapContext getBootstrapContext() { return this.bootstrapContext; @@ -113,9 +106,6 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot getCacheAwareContextLoaderDelegate()); } - /** - * {@inheritDoc} - */ @Override public final List getTestExecutionListeners() { Class clazz = getBootstrapContext().getTestClass(); @@ -168,28 +158,25 @@ 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; @@ -200,13 +187,14 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot ncdfe = err; } catch (BeanInstantiationException ex) { - if (ex.getCause() instanceof NoClassDefFoundError) { - ncdfe = (NoClassDefFoundError) ex.getCause(); + if (!(ex.getCause() instanceof NoClassDefFoundError)) { + throw ex; } + 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()));