From fb12e234fcee416c4ea6359a2242ce7e3977b0b6 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 22 Jan 2014 23:28:36 +0100 Subject: [PATCH] Handle NoClassDefFoundError consistently for TELs Prior to this commit, a NoClassDefFoundError caught in TestContextManager's retrieveTestExecutionListeners() method would be handled differently for implicit default listeners (i.e., listeners not declared via @TestExecutionListeners) and listeners explicitly declared via @TestExecutionListeners. Specifically, a NoClassDefFoundError would cause a test to fail for an explicitly declared TestExecutionListener but not for an implicitly declared one. This commit addresses this issue by: - Always swallowing a NoClassDefFoundError for both implicitly and explicitly declared TestExecutionListeners. - Changing the log level from DEBUG to INFO to make such situations more visible to the average end user. Issue: SPR-11347 --- .../test/context/TestContextManager.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java b/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java index 736b724e67..8255db3b27 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java @@ -180,7 +180,6 @@ public class TestContextManager { List> classesList = new ArrayList>(); AnnotationDescriptor descriptor = findAnnotationDescriptor(clazz, annotationType); - boolean defaultListeners = false; // Use defaults? if (descriptor == null) { @@ -188,7 +187,6 @@ public class TestContextManager { logger.debug("@TestExecutionListeners is not present for class [" + clazz + "]: using defaults."); } classesList.addAll(getDefaultTestExecutionListenerClasses()); - defaultListeners = true; } else { // Traverse the class hierarchy... @@ -232,15 +230,10 @@ public class TestContextManager { listeners.add(BeanUtils.instantiateClass(listenerClass)); } catch (NoClassDefFoundError err) { - if (defaultListeners) { - if (logger.isDebugEnabled()) { - logger.debug("Could not instantiate default TestExecutionListener class [" - + listenerClass.getName() - + "]. Specify custom listener classes or make the default listener classes available."); - } - } - else { - throw err; + if (logger.isInfoEnabled()) { + logger.info(String.format("Could not instantiate TestExecutionListener class [%s]. " + + "Specify custom listener classes or make the default listener classes " + + "(and their dependencies) available.", listenerClass.getName())); } } }