Class ApplicationContextAssert<C extends ApplicationContext>
java.lang.Object
org.assertj.core.api.AbstractAssert<ApplicationContextAssert<C>,C>
 
org.springframework.boot.test.context.assertj.ApplicationContextAssert<C>
- Type Parameters:
- C- the application context type
- All Implemented Interfaces:
- org.assertj.core.api.Assert<ApplicationContextAssert<C>,,- C> - org.assertj.core.api.Descriptable<ApplicationContextAssert<C>>,- org.assertj.core.api.ExtensionPoints<ApplicationContextAssert<C>,- C> 
public class ApplicationContextAssert<C extends ApplicationContext>
extends org.assertj.core.api.AbstractAssert<ApplicationContextAssert<C>,C> 
AssertJ 
assertions that can be applied to an
 ApplicationContext.- Since:
- 2.0.0
- Author:
- Phillip Webb, Andy Wilkinson
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic enumThe scope of an assertion.
- 
Field SummaryFields inherited from class org.assertj.core.api.AbstractAssertactual, info, myself, objects, throwUnsupportedExceptionOnEquals
- 
Method SummaryModifier and TypeMethodDescriptiondoesNotHaveBean(Class<?> type) Verifies that the application context (or ancestors) does not contain any beans of the given type.doesNotHaveBean(Class<?> type, ApplicationContextAssert.Scope scope) Verifies that the application context does not contain any beans of the given type.doesNotHaveBean(String name) Verifies that the application context does not contain a beans of the given name.protected final C<T> org.assertj.core.api.AbstractObjectAssert<?,T> Obtain a single bean of the given type from the application context (or ancestors), the bean becoming the object under test.<T> org.assertj.core.api.AbstractObjectAssert<?,T> getBean(Class<T> type, ApplicationContextAssert.Scope scope) Obtain a single bean of the given type from the application context, the bean becoming the object under test.org.assertj.core.api.AbstractObjectAssert<?,Object> Obtain a single bean of the given name from the application context, the bean becoming the object under test.<T> org.assertj.core.api.AbstractObjectAssert<?,T> Obtain a single bean of the given name and type from the application context, the bean becoming the object under test.<T> org.assertj.core.api.AbstractObjectArrayAssert<?,String> getBeanNames(Class<T> type) Obtain the beans names of the given type from the application context, the names becoming the object array under test.<T> org.assertj.core.api.MapAssert<String,T> Obtain a map bean names and instances of the given type from the application context (or ancestors), the map becoming the object under test.<T> org.assertj.core.api.MapAssert<String,T> getBeans(Class<T> type, ApplicationContextAssert.Scope scope) Obtain a map bean names and instances of the given type from the application context, the map becoming the object under test.org.assertj.core.api.AbstractThrowableAssert<?,? extends Throwable> Obtain the failure that stopped the application context from running, the failure becoming the object under test.protected final ThrowableVerifies that the application context contains a bean with the given name.Verifies that the application has failed to start.Verifies that the application has not failed to start.hasSingleBean(Class<?> type) Verifies that the application context (or ancestors) contains a single bean with the given type.hasSingleBean(Class<?> type, ApplicationContextAssert.Scope scope) Verifies that the application context contains a single bean with the given type.Methods inherited from class org.assertj.core.api.AbstractAssertareEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.assertj.core.api.Descriptableas, as, as, describedAs
- 
Method Details- 
hasBeanVerifies that the application context contains a bean with the given name.Example: assertThat(context).hasBean("fooBean");- Parameters:
- name- the name of the bean
- Returns:
- thisassertion object.
- Throws:
- AssertionError- if the application context did not start
- AssertionError- if the application context does not contain a bean with the given name
 
- 
hasSingleBeanVerifies that the application context (or ancestors) contains a single bean with the given type.Example: assertThat(context).hasSingleBean(Foo.class); - Parameters:
- type- the bean type
- Returns:
- thisassertion object.
- Throws:
- AssertionError- if the application context did not start
- AssertionError- if the application context does no beans of the given type
- AssertionError- if the application context contains multiple beans of the given type
 
- 
hasSingleBeanpublic ApplicationContextAssert<C> hasSingleBean(Class<?> type, ApplicationContextAssert.Scope scope) Verifies that the application context contains a single bean with the given type.Example: assertThat(context).hasSingleBean(Foo.class, Scope.NO_ANCESTORS); - Parameters:
- type- the bean type
- scope- the scope of the assertion
- Returns:
- thisassertion object.
- Throws:
- AssertionError- if the application context did not start
- AssertionError- if the application context does no beans of the given type
- AssertionError- if the application context contains multiple beans of the given type
 
- 
doesNotHaveBeanVerifies that the application context (or ancestors) does not contain any beans of the given type.Example: assertThat(context).doesNotHaveBean(Foo.class); - Parameters:
- type- the bean type
- Returns:
- thisassertion object.
- Throws:
- AssertionError- if the application context did not start
- AssertionError- if the application context contains any beans of the given type
 
- 
doesNotHaveBeanpublic ApplicationContextAssert<C> doesNotHaveBean(Class<?> type, ApplicationContextAssert.Scope scope) Verifies that the application context does not contain any beans of the given type.Example: assertThat(context).doesNotHaveBean(Foo.class, Scope.NO_ANCESTORS); - Parameters:
- type- the bean type
- scope- the scope of the assertion
- Returns:
- thisassertion object.
- Throws:
- AssertionError- if the application context did not start
- AssertionError- if the application context contains any beans of the given type
 
- 
doesNotHaveBeanVerifies that the application context does not contain a beans of the given name.Example: assertThat(context).doesNotHaveBean("fooBean");- Parameters:
- name- the name of the bean
- Returns:
- thisassertion object.
- Throws:
- AssertionError- if the application context did not start
- AssertionError- if the application context contains a beans of the given name
 
- 
getBeanNamesObtain the beans names of the given type from the application context, the names becoming the object array under test.Example: assertThat(context).getBeanNames(Foo.class).containsOnly("fooBean");- Type Parameters:
- T- the bean type
- Parameters:
- type- the bean type
- Returns:
- array assertions for the bean names
- Throws:
- AssertionError- if the application context did not start
 
- 
getBeanObtain a single bean of the given type from the application context (or ancestors), the bean becoming the object under test. If no beans of the specified type can be found an assert onnullis returned.Example: assertThat(context).getBean(Foo.class).isInstanceOf(DefaultFoo.class); assertThat(context).getBean(Bar.class).isNull(); - Type Parameters:
- T- the bean type
- Parameters:
- type- the bean type
- Returns:
- bean assertions for the bean, or an assert on nullif the no bean is found
- Throws:
- AssertionError- if the application context did not start
- AssertionError- if the application context contains multiple beans of the given type
 
- 
getBeanpublic <T> org.assertj.core.api.AbstractObjectAssert<?,T> getBean(Class<T> type, ApplicationContextAssert.Scope scope) Obtain a single bean of the given type from the application context, the bean becoming the object under test. If no beans of the specified type can be found an assert onnullis returned.Example: assertThat(context).getBean(Foo.class, Scope.NO_ANCESTORS).isInstanceOf(DefaultFoo.class); assertThat(context).getBean(Bar.class, Scope.NO_ANCESTORS).isNull(); - Type Parameters:
- T- the bean type
- Parameters:
- type- the bean type
- scope- the scope of the assertion
- Returns:
- bean assertions for the bean, or an assert on nullif the no bean is found
- Throws:
- AssertionError- if the application context did not start
- AssertionError- if the application context contains multiple beans of the given type
 
- 
getBeanObtain a single bean of the given name from the application context, the bean becoming the object under test. If no bean of the specified name can be found an assert onnullis returned.Example: assertThat(context).getBean("foo").isInstanceOf(Foo.class); assertThat(context).getBean("foo").isNull();- Parameters:
- name- the name of the bean
- Returns:
- bean assertions for the bean, or an assert on nullif the no bean is found
- Throws:
- AssertionError- if the application context did not start
 
- 
getBeanObtain a single bean of the given name and type from the application context, the bean becoming the object under test. If no bean of the specified name can be found an assert onnullis returned.Example: assertThat(context).getBean("foo", Foo.class).isInstanceOf(DefaultFoo.class); assertThat(context).getBean("foo", Foo.class).isNull();- Type Parameters:
- T- the bean type
- Parameters:
- name- the name of the bean
- type- the bean type
- Returns:
- bean assertions for the bean, or an assert on nullif the no bean is found
- Throws:
- AssertionError- if the application context did not start
- AssertionError- if the application context contains a bean with the given name but a different type
 
- 
getBeansObtain a map bean names and instances of the given type from the application context (or ancestors), the map becoming the object under test. If no bean of the specified type can be found an assert on an emptymapis returned.Example: assertThat(context).getBeans(Foo.class).containsKey("foo");- Type Parameters:
- T- the bean type
- Parameters:
- type- the bean type
- Returns:
- bean assertions for the beans, or an assert on an empty mapif the no beans are found
- Throws:
- AssertionError- if the application context did not start
 
- 
getBeanspublic <T> org.assertj.core.api.MapAssert<String,T> getBeans(Class<T> type, ApplicationContextAssert.Scope scope) Obtain a map bean names and instances of the given type from the application context, the map becoming the object under test. If no bean of the specified type can be found an assert on an emptymapis returned.Example: assertThat(context).getBeans(Foo.class, Scope.NO_ANCESTORS).containsKey("foo");- Type Parameters:
- T- the bean type
- Parameters:
- type- the bean type
- scope- the scope of the assertion
- Returns:
- bean assertions for the beans, or an assert on an empty mapif the no beans are found
- Throws:
- AssertionError- if the application context did not start
 
- 
getFailureObtain the failure that stopped the application context from running, the failure becoming the object under test.Example: assertThat(context).getFailure().containsMessage("missing bean");- Returns:
- assertions on the cause of the failure
- Throws:
- AssertionError- if the application context started without a failure
 
- 
hasFailedVerifies that the application has failed to start.Example: assertThat(context).hasFailed(); - Returns:
- thisassertion object.
- Throws:
- AssertionError- if the application context started without a failure
 
- 
hasNotFailedVerifies that the application has not failed to start.Example: assertThat(context).hasNotFailed(); - Returns:
- thisassertion object.
- Throws:
- AssertionError- if the application context failed to start
 
- 
getApplicationContext
- 
getStartupFailure
 
-