getBean

open fun <T> getBean(type: Class<T>): AbstractObjectAssert<out Any, T>

Obtain 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 on null is returned.

Example:

	assertThat(context).getBean(Foo.class).isInstanceOf(DefaultFoo.class);
	assertThat(context).getBean(Bar.class).isNull();

Return

bean assertions for the bean, or an assert on null if the no beanis found

Parameters

<T>

the bean type

type

the bean type

Throws

if the application context contains multiple beans of thegiven type


open fun <T> getBean(type: Class<T>, scope: ApplicationContextAssert.Scope): AbstractObjectAssert<out Any, T>

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 on null is returned.

Example:

	assertThat(context).getBean(Foo.class, Scope.NO_ANCESTORS).isInstanceOf(DefaultFoo.class);
	assertThat(context).getBean(Bar.class, Scope.NO_ANCESTORS).isNull();

Return

bean assertions for the bean, or an assert on null if the no beanis found

Parameters

<T>

the bean type

type

the bean type

scope

the scope of the assertion

Throws

if the application context contains multiple beans of thegiven type


open fun getBean(name: String): AbstractObjectAssert<out Any, Any>

Obtain 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 on null is returned.

Example:

	assertThat(context).getBean("foo").isInstanceOf(Foo.class);
	assertThat(context).getBean("foo").isNull();

Return

bean assertions for the bean, or an assert on null if the no beanis found

Parameters

name

the name of the bean

Throws

if the application context did not start


open fun <T> getBean(name: String, type: Class<T>): AbstractObjectAssert<out Any, T>

Obtain 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 on null is returned.

Example:

	assertThat(context).getBean("foo", Foo.class).isInstanceOf(DefaultFoo.class);
	assertThat(context).getBean("foo", Foo.class).isNull();

Return

bean assertions for the bean, or an assert on null if the no beanis found

Parameters

<T>

the bean type

name

the name of the bean

type

the bean type

Throws

if the application context contains a bean with the givenname but a different type