I've got a CDI web application which has a ServletContextListener to initialise a few things on startup.
In that ServletContextListener, this (among other things) happens:
@Inject
Config config;
public void contextInitialized(ServletContextEvent event) {
....
config.init(....)
}
This works well enough, as this makes sure that the init is performed before other CDI beans are instantiated (such as App, which injects Config itself too)
However, I'm unable to work out how to realise this logic for unit testing. With CDI-Unit from jglue, I can do this in my test class:
@Inject
Config config;
@Inject
App application;
But when I run my test, I keep on getting issues, as the @PostConstruct in App needs Config to be inited already. So, how can I possibly call the Config.init() method in time?