AssertableApplicationContext class final
What ApplicationContextRunner.run hands to the test: the started context, or the reason it could not start.
A failed start does not throw, so a test can check that a
configuration rejects bad input: expect(context, hasFailed()). On a
started context, the matchers and getBean read the beans; reading a
bean of a failed one throws a StateError with the failure.
runner.run((context) {
// The starter's default, created because the app has none.
expect(context, hasSingleBean<CacheManager>());
expect(context.getBean<CacheManager>(), isA<InMemoryCacheManager>());
});
Spring (Java): Spring Boot's AssertableApplicationContext, used with
AssertJ's assertThat(context).
Properties
- context → ConfigurableApplicationContext
-
The started context, for checks the shortcuts below do not cover.
Throws a StateError with the failure when the context did not start.
no setter
- environment → ConfigurableEnvironment
-
The context's environment, also after a failed start: to check the
properties the configuration saw.
no setter
- hasFailed → bool
-
Whether the context failed to start.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- startupFailure → Object?
-
The error that stopped the start;
nullwhen the context started.final
Methods
-
containsBean(
String name) → bool -
Whether a bean called
nameexists, here or in a parent context. -
getBean<
T extends Object> ({String? qualifier}) → T -
The bean of type
T; withqualifier, the one it names among several. Throws when no bean matches or the context did not start. -
getBeanByName(
String name) → Object -
The bean called
name, whatever its type. Throws when there is none or the context did not start. -
getBeanNamesForType<
T extends Object> () → List< String> -
The names of the beans of type
Tin this context (not its parent), to check which configuration created them. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited