@Override
 protected void setUp() throws Exception {
   super.setUp();
   prefStore = control.createMock(PreferencesStore.class);
   wac.getBeanFactory().registerSingleton("preferencesStore", prefStore);
   context.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
   filter.init(filterConfig);
 }
  private void filter() throws ServletException, IOException {
    final boolean sessionExisted = request.getSession(false) != null;

    assertFalse(chain.doFilterCalled());

    control.replay();

    filter.doFilter(request, response, chain);

    control.verify();

    assertTrue("Should call chain", chain.doFilterCalled());

    if (!sessionExisted) {
      assertNull("Should not create session", request.getSession(false));
    }
  }