Browse Source

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
pull/451/head
Sam Brannen 11 years ago
parent
commit
fb12e234fc
  1. 15
      spring-test/src/main/java/org/springframework/test/context/TestContextManager.java

15
spring-test/src/main/java/org/springframework/test/context/TestContextManager.java

@ -180,7 +180,6 @@ public class TestContextManager { @@ -180,7 +180,6 @@ public class TestContextManager {
List<Class<? extends TestExecutionListener>> classesList = new ArrayList<Class<? extends TestExecutionListener>>();
AnnotationDescriptor<TestExecutionListeners> descriptor = findAnnotationDescriptor(clazz, annotationType);
boolean defaultListeners = false;
// Use defaults?
if (descriptor == null) {
@ -188,7 +187,6 @@ public class TestContextManager { @@ -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 { @@ -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()));
}
}
}

Loading…
Cancel
Save