Interface ApplicationContextAssertProvider<C extends org.springframework.context.ApplicationContext>
- Type Parameters:
C
- the application context type
- All Superinterfaces:
org.springframework.context.ApplicationContext
,org.springframework.context.ApplicationEventPublisher
,org.assertj.core.api.AssertProvider<ApplicationContextAssert<C>>
,AutoCloseable
,org.springframework.beans.factory.BeanFactory
,Closeable
,org.springframework.core.env.EnvironmentCapable
,org.springframework.beans.factory.HierarchicalBeanFactory
,org.springframework.beans.factory.ListableBeanFactory
,org.springframework.context.MessageSource
,org.springframework.core.io.ResourceLoader
,org.springframework.core.io.support.ResourcePatternResolver
- All Known Subinterfaces:
AssertableApplicationContext
,AssertableReactiveWebApplicationContext
,AssertableWebApplicationContext
public interface ApplicationContextAssertProvider<C extends org.springframework.context.ApplicationContext> extends org.springframework.context.ApplicationContext, org.assertj.core.api.AssertProvider<ApplicationContextAssert<C>>, Closeable
AnApplicationContext
that additionally supports AssertJ style assertions. Can be used to decorate an existing application context or an application context that failed to start.Assertions can be applied using the standard AssertJ
assertThat(...)
style (seeApplicationContextAssert
for a complete list). For example:assertThat(applicationContext).hasSingleBean(MyBean.class);
If the original
ApplicationContext
is needed for any reason thegetSourceApplicationContext()
method can be used.Any
ApplicationContext
method called on a context that has failed to start will throw anIllegalStateException
.
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description ApplicationContextAssert<C>
assertThat()
Deprecated.use standard AssertJassertThat(context)...
calls instead.void
close()
static <T extends ApplicationContextAssertProvider<C>,C extends org.springframework.context.ApplicationContext>
Tget(Class<T> type, Class<? extends C> contextType, Supplier<? extends C> contextSupplier)
Factory method to create a newApplicationContextAssertProvider
instance.C
getSourceApplicationContext()
Return the original sourceApplicationContext
.<T extends C>
TgetSourceApplicationContext(Class<T> requiredType)
Return the original sourceApplicationContext
, casting it to the requested type.Throwable
getStartupFailure()
Return the failure that caused application context to fail ornull
if the context started without issue.Methods inherited from interface org.springframework.context.ApplicationContext
getApplicationName, getAutowireCapableBeanFactory, getDisplayName, getId, getParent, getStartupDate
Methods inherited from interface org.springframework.context.ApplicationEventPublisher
publishEvent, publishEvent
Methods inherited from interface org.springframework.beans.factory.BeanFactory
containsBean, getAliases, getBean, getBean, getBean, getBean, getBean, getBeanProvider, getBeanProvider, getType, isPrototype, isSingleton, isTypeMatch, isTypeMatch
Methods inherited from interface org.springframework.beans.factory.HierarchicalBeanFactory
containsLocalBean, getParentBeanFactory
Methods inherited from interface org.springframework.beans.factory.ListableBeanFactory
containsBeanDefinition, findAnnotationOnBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeansOfType, getBeansOfType, getBeansWithAnnotation
Methods inherited from interface org.springframework.context.MessageSource
getMessage, getMessage, getMessage
Method Detail
assertThat
@Deprecated ApplicationContextAssert<C> assertThat()
Deprecated.use standard AssertJassertThat(context)...
calls instead.Return an assert for AspectJ.- Specified by:
assertThat
in interfaceorg.assertj.core.api.AssertProvider<C extends org.springframework.context.ApplicationContext>
- Returns:
- an AspectJ assert
getSourceApplicationContext
C getSourceApplicationContext()
Return the original sourceApplicationContext
.- Returns:
- the source application context
- Throws:
IllegalStateException
- if the source context failed to start
getSourceApplicationContext
<T extends C> T getSourceApplicationContext(Class<T> requiredType)
Return the original sourceApplicationContext
, casting it to the requested type.- Type Parameters:
T
- the context type- Parameters:
requiredType
- the required context type- Returns:
- the source application context
- Throws:
IllegalStateException
- if the source context failed to start
getStartupFailure
Throwable getStartupFailure()
Return the failure that caused application context to fail ornull
if the context started without issue.- Returns:
- the startup failure or
null
close
void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
get
static <T extends ApplicationContextAssertProvider<C>,C extends org.springframework.context.ApplicationContext> T get(Class<T> type, Class<? extends C> contextType, Supplier<? extends C> contextSupplier)
Factory method to create a newApplicationContextAssertProvider
instance.- Type Parameters:
T
- the assert provider typeC
- the context type- Parameters:
type
- the type ofApplicationContextAssertProvider
required (must be an interface)contextType
- the type ofApplicationContext
being managed (must be an interface)contextSupplier
- a supplier that will either return a fully configuredApplicationContext
or throw an exception if the context fails to start.- Returns:
- a
ApplicationContextAssertProvider
instance