Consistent logging for skipped TestExecutionListeners
With this commit we now log an identical message (without a stack trace) for a TestExecutionListener skipped due to a ClassNotFoundException like we already do for a listener skipped due to a NoClassDefFoundError.
This commit is contained in:
parent
7f88f315a4
commit
ab20a189c5
|
@ -217,8 +217,9 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
|
||||||
listeners.add(BeanUtils.instantiateClass(listenerClass));
|
listeners.add(BeanUtils.instantiateClass(listenerClass));
|
||||||
}
|
}
|
||||||
catch (BeanInstantiationException ex) {
|
catch (BeanInstantiationException ex) {
|
||||||
if (ex.getCause() instanceof NoClassDefFoundError noClassDefFoundError) {
|
Throwable cause = ex.getCause();
|
||||||
handleNoClassDefFoundError(listenerClass.getName(), noClassDefFoundError);
|
if (cause instanceof ClassNotFoundException || cause instanceof NoClassDefFoundError) {
|
||||||
|
logSkippedListener(listenerClass.getName(), cause);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw ex;
|
throw ex;
|
||||||
|
@ -233,11 +234,12 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
|
||||||
|
|
||||||
Throwable ex = (failure instanceof InvocationTargetException ite ?
|
Throwable ex = (failure instanceof InvocationTargetException ite ?
|
||||||
ite.getTargetException() : failure);
|
ite.getTargetException() : failure);
|
||||||
if (ex instanceof LinkageError || ex instanceof ClassNotFoundException) {
|
|
||||||
if (ex instanceof NoClassDefFoundError noClassDefFoundError) {
|
if (ex instanceof ClassNotFoundException || ex instanceof NoClassDefFoundError) {
|
||||||
handleNoClassDefFoundError(listenerClassName, noClassDefFoundError);
|
logSkippedListener(listenerClassName, ex);
|
||||||
}
|
}
|
||||||
else if (logger.isDebugEnabled()) {
|
else if (ex instanceof LinkageError) {
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("""
|
logger.debug("""
|
||||||
Could not load default TestExecutionListener [%s]. Specify custom \
|
Could not load default TestExecutionListener [%s]. Specify custom \
|
||||||
listener classes or make the default listener classes available."""
|
listener classes or make the default listener classes available."""
|
||||||
|
@ -256,14 +258,14 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleNoClassDefFoundError(String listenerClassName, NoClassDefFoundError error) {
|
private void logSkippedListener(String listenerClassName, Throwable ex) {
|
||||||
// TestExecutionListener not applicable due to a missing dependency
|
// TestExecutionListener not applicable due to a missing dependency
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("""
|
logger.debug("""
|
||||||
Skipping candidate TestExecutionListener [%s] due to a missing dependency. \
|
Skipping candidate TestExecutionListener [%s] due to a missing dependency. \
|
||||||
Specify custom listener classes or make the default listener classes \
|
Specify custom listener classes or make the default listener classes \
|
||||||
and their required dependencies available. Offending class: [%s]"""
|
and their required dependencies available. Offending class: [%s]"""
|
||||||
.formatted(listenerClassName, error.getMessage()));
|
.formatted(listenerClassName, ex.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue