I have a utility method that I wanted to write a unit test for. Since this utility runs under a webapp, it is designed to get a Spring bean from the WebApplicationContext.(follow code is not under unit test) action bean class
private IUnitBiz unitBiz;
public UnitBean()
{
unitBiz = CommonUtils.getBean(IUnitBiz.class);
}
in CommonUtils.class
public static ApplicationContext getWebApplicationContext() {
return FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
}
public static <T> T getBean(Class<T> beanType) {
return getWebApplicationContext().getBean(beanType);
}
------------------in unit test----------------
In unit test it is return null, how can i init WebApplicationContext or getBean for my unit test? when i new action bean, getBean method is return null.