??ò??????????????
???????????? ???????[ 2013/6/17 10:36:25 ] ????????
??????????????????????????“????”???
??????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());
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11