use of cn.taketoday.context.support.AbstractApplicationContext in project today-infrastructure by TAKETODAY.
the class ApplicationEventsTestExecutionListener method registerListenerAndResolvableDependencyIfNecessary.
private void registerListenerAndResolvableDependencyIfNecessary(ApplicationContext applicationContext) {
Assert.isInstanceOf(AbstractApplicationContext.class, applicationContext, "The ApplicationContext for the test must be an AbstractApplicationContext");
AbstractApplicationContext aac = (AbstractApplicationContext) applicationContext;
// Synchronize to avoid race condition in parallel test execution
synchronized (applicationEventsMonitor) {
boolean notAlreadyRegistered = aac.getApplicationListeners().stream().map(Object::getClass).noneMatch(ApplicationEventsApplicationListener.class::equals);
if (notAlreadyRegistered) {
// Register a new ApplicationEventsApplicationListener.
aac.addApplicationListener(new ApplicationEventsApplicationListener());
// Register ApplicationEvents as a resolvable dependency for @Autowired support in test classes.
ConfigurableBeanFactory beanFactory = aac.getBeanFactory();
beanFactory.registerDependency(ApplicationEvents.class, new ApplicationEventsObjectFactory());
}
}
}
use of cn.taketoday.context.support.AbstractApplicationContext in project today-framework by TAKETODAY.
the class ApplicationEventsTestExecutionListener method registerListenerAndResolvableDependencyIfNecessary.
private void registerListenerAndResolvableDependencyIfNecessary(ApplicationContext applicationContext) {
Assert.isInstanceOf(AbstractApplicationContext.class, applicationContext, "The ApplicationContext for the test must be an AbstractApplicationContext");
AbstractApplicationContext aac = (AbstractApplicationContext) applicationContext;
// Synchronize to avoid race condition in parallel test execution
synchronized (applicationEventsMonitor) {
boolean notAlreadyRegistered = aac.getApplicationListeners().stream().map(Object::getClass).noneMatch(ApplicationEventsApplicationListener.class::equals);
if (notAlreadyRegistered) {
// Register a new ApplicationEventsApplicationListener.
aac.addApplicationListener(new ApplicationEventsApplicationListener());
// Register ApplicationEvents as a resolvable dependency for @Autowired support in test classes.
ConfigurableBeanFactory beanFactory = aac.getBeanFactory();
beanFactory.registerDependency(ApplicationEvents.class, new ApplicationEventsObjectFactory());
}
}
}
Aggregations