@Test
  public void testNonconcurrentLogin() throws Exception {
    MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
    filter.init(filterConfig);

    MockHttpServletRequest req = new MockHttpServletRequest(servletContext);
    MockHttpServletResponse res = new MockHttpServletResponse();

    MockHttpSession sessionOfAnon = new MockHttpSession();
    req.setSession(sessionOfAnon);
    filter.doFilter(req, res, new MockFilterChain());
    assertFalse(sessionOfAnon.isInvalid());

    MockHttpSession sessionOfJohn = new MockHttpSession(servletContext);
    req.setUserPrincipal(new TransientUser("john"));
    req.setSession(sessionOfJohn);
    filter.doFilter(req, res, new MockFilterChain());
    assertFalse(sessionOfJohn.isInvalid());

    MockHttpSession sessionOfJane = new MockHttpSession(servletContext);
    req.setUserPrincipal(new TransientUser("jane"));
    req.setSession(sessionOfJane);
    filter.doFilter(req, res, new MockFilterChain());
    assertFalse(sessionOfJane.isInvalid());
  }
  @Test
  public void testConcurrentLoginWithDisallowingAll() throws Exception {
    MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
    filterConfig.addInitParameter("disallowConcurrentLoginUsernames", "*");
    filter.init(filterConfig);

    MockHttpServletRequest req = new MockHttpServletRequest(servletContext);
    MockHttpServletResponse res = new MockHttpServletResponse();

    MockHttpSession sessionOfJohn1 = new MockHttpSession(servletContext);
    req.setUserPrincipal(new TransientUser("john"));
    req.setSession(sessionOfJohn1);
    filter.doFilter(req, res, new MockFilterChain());
    assertFalse(sessionOfJohn1.isInvalid());

    MockHttpSession sessionOfJohn2 = new MockHttpSession(servletContext);
    req.setUserPrincipal(new TransientUser("john"));
    req.setSession(sessionOfJohn2);
    filter.doFilter(req, res, new MockFilterChain());
    assertFalse(sessionOfJohn2.isInvalid());

    req.setSession(sessionOfJohn1);
    filter.doFilter(req, res, new MockFilterChain());
    assertTrue(sessionOfJohn1.isInvalid());

    req.setSession(sessionOfJohn2);
    filter.doFilter(req, res, new MockFilterChain());
    assertFalse(sessionOfJohn2.isInvalid());
  }