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();
}
Aggregations