Search in sources :

Example 1 with BeanThatBroadcasts

use of org.springframework.context.testfixture.beans.BeanThatBroadcasts in project spring-framework by spring-projects.

the class ApplicationContextEventTests method listenerAndBroadcasterWithCircularReference.

@Test
public void listenerAndBroadcasterWithCircularReference() {
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerBeanDefinition("broadcaster", new RootBeanDefinition(BeanThatBroadcasts.class));
    RootBeanDefinition listenerDef = new RootBeanDefinition(BeanThatListens.class);
    listenerDef.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("broadcaster"));
    context.registerBeanDefinition("listener", listenerDef);
    context.refresh();
    BeanThatBroadcasts broadcaster = context.getBean("broadcaster", BeanThatBroadcasts.class);
    context.publishEvent(new MyEvent(context));
    assertThat(broadcaster.receivedCount).as("The event was not received by the listener").isEqualTo(2);
    context.close();
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) BeanThatBroadcasts(org.springframework.context.testfixture.beans.BeanThatBroadcasts) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)1 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1 BeanThatBroadcasts (org.springframework.context.testfixture.beans.BeanThatBroadcasts)1