Avoid NPE when @SpringBootConfiguration not found in test
See gh-33371
This commit is contained in:
parent
93f8dc76ab
commit
f5d0171fcc
|
@ -244,8 +244,6 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
Class<?> found = findConfigurationClass(mergedConfig.getTestClass());
|
Class<?> found = findConfigurationClass(mergedConfig.getTestClass());
|
||||||
Assert.state(found != null, "Unable to find a @SpringBootConfiguration, you need to use "
|
|
||||||
+ "@ContextConfiguration or @SpringBootTest(classes=...) with your test");
|
|
||||||
logger.info("Found @SpringBootConfiguration " + found.getName() + " for test " + mergedConfig.getTestClass());
|
logger.info("Found @SpringBootConfiguration " + found.getName() + " for test " + mergedConfig.getTestClass());
|
||||||
return merge(found, classes);
|
return merge(found, classes);
|
||||||
}
|
}
|
||||||
|
@ -258,6 +256,8 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
|
||||||
return ClassUtils.resolveClassName(foundClassName, testClass.getClassLoader());
|
return ClassUtils.resolveClassName(foundClassName, testClass.getClassLoader());
|
||||||
}
|
}
|
||||||
Class<?> found = new AnnotatedClassFinder(SpringBootConfiguration.class).findFromClass(testClass);
|
Class<?> found = new AnnotatedClassFinder(SpringBootConfiguration.class).findFromClass(testClass);
|
||||||
|
Assert.state(found != null, "Unable to find a @SpringBootConfiguration, you need to use "
|
||||||
|
+ "@ContextConfiguration or @SpringBootTest(classes=...) with your test");
|
||||||
this.aotTestAttributes.setAttribute(propertyName, found.getName());
|
this.aotTestAttributes.setAttribute(propertyName, found.getName());
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue