Avoid NPE when @SpringBootConfiguration not found in test

See gh-33371
This commit is contained in:
lishangbu 2022-11-26 19:54:52 +08:00 committed by Moritz Halbritter
parent 93f8dc76ab
commit f5d0171fcc
1 changed files with 2 additions and 2 deletions

View File

@ -244,8 +244,6 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
return classes;
}
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());
return merge(found, classes);
}
@ -258,6 +256,8 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
return ClassUtils.resolveClassName(foundClassName, testClass.getClassLoader());
}
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());
return found;
}