??????????????????????????“????”???

??????t????????????????????????????????????????????????????????????????????????в??e????

public boolean preHandle(HttpServletRequest request?? HttpServletResponse response) {
     if (SessionUtils.isUnexpired(request)) {
          return true;
     } else {
          //??response?????alert???
     }
}

?????????????????ж??????session?е?????????????У?飬???????в????????????session????????????

@Test
public void returnTrueWhenUserSessionIsNotExpired() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpSession session = new MockHttpSession();
    request.setSession(session);
    session.set......blablabla

    assertTrue(target.preHandle(request));
}

@Test
public void printAlertAndreturnFalseWhenUserSessionIsExpired() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpSession session = new MockHttpSession();
    request.setSession(session);
    session.set......blablabla
   

    assertFalse(target.preHandle(request?? response));
    assertEquals(ALERT?? response.getContentAsString());
}

??????????????????????????????????д???????????滻??????????????SessionUtils.isUnexpired(req)????????????????????????裬???ò????????????????????????·???鷳???????????????????°???????????????????????isUnexpired(req)?????С???а?

???????????????????????????????Stub/mock???滻SessionGateway??????

@Test
public void returnTrueWhenUserSessionIsNotExpired() throws Exception {
  
    context.checking(new Expectations() {
        {
               allowing(sessionGateway).isUnexpired(request)??
               will(returnValue(true));
         }
    });

    assertTrue(target.preHandle(request?? response));
}

@Test
public void printAlertAndreturnFalseWhenUserSessionIsExpired() throws Exception {
    context.checking(new Expectations() {
        {
               allowing(sessionGateway).isUnexpired(request)??
               will(returnValue(false));
         }
    });
   

    assertFalse(target.preHandle(request?? response));
    assertEquals(ALERT?? response.getContentAsString());
}