org.springframework.boot.test.context.SpringBootTestContextBootstrapper Java Examples
The following examples show how to use
org.springframework.boot.test.context.SpringBootTestContextBootstrapper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestUtils.java From moduliths with Apache License 2.0 | 3 votes |
public static void assertDependencyMissing(Class<?> testClass, Class<?> expectedMissingDependency) { CacheAwareContextLoaderDelegate delegate = new DefaultCacheAwareContextLoaderDelegate(); BootstrapContext bootstrapContext = new DefaultBootstrapContext(testClass, delegate); SpringBootTestContextBootstrapper bootstrapper = new SpringBootTestContextBootstrapper(); bootstrapper.setBootstrapContext(bootstrapContext); MergedContextConfiguration configuration = bootstrapper.buildMergedContextConfiguration(); AssertableApplicationContext context = AssertableApplicationContext.get(() -> { SpringBootContextLoader loader = new SpringBootContextLoader(); try { return (ConfigurableApplicationContext) loader.loadContext(configuration); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RuntimeException(e); } }); assertThat(context).hasFailed(); assertThat(context).getFailure().isInstanceOfSatisfying(UnsatisfiedDependencyException.class, it -> { assertThat(it.getMostSpecificCause()).isInstanceOfSatisfying(NoSuchBeanDefinitionException.class, ex -> { assertThat(ex.getBeanType()).isEqualTo(expectedMissingDependency); }); }); }