Q:

Init WebApplicationContext in unit test

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.

A:

EasyMock could be a solution.
Example:
WebApplicationContext mockWebApplicationContext = EasyMock.createMock(WebApplicationContext.class);
MockServletContext mockServletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
                                    mockWebApplicationContext);

EasyMock.expect(mockWebApplicationContext.getServletContext()).andReturn(mockServletContext).anyTimes();

