### Question:
LoginHandlerInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { String token = request.getHeader("token"); User user = null; if (StringUtils.isEmpty(token)){ user = authenticator.getAuthUser(request); if (user == null) { response.setStatus(HttpStatus.SC_UNAUTHORIZED); logger.info("user does not exist"); return false; } }else { user = userMapper.queryUserByToken(token); if (user == null) { response.setStatus(HttpStatus.SC_UNAUTHORIZED); logger.info("user token has expired"); return false; } } if (user.getState() == Flag.NO.ordinal()) { response.setStatus(HttpStatus.SC_UNAUTHORIZED); logger.info(Status.USER_DISABLED.getMsg()); return false; } request.setAttribute(Constants.SESSION_USER, user); return true; }  @Override boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler);  }### Answer:
@Test public void testPreHandle() { HttpServletRequest request = Mockito.mock(HttpServletRequest.class); HttpServletResponse response = Mockito.mock(HttpServletResponse.class); Assert.assertFalse(interceptor.preHandle(request, response, null)); User mockUser = new User(); mockUser.setId(1); mockUser.setUserType(UserType.GENERAL_USER); mockUser.setState(1); when(authenticator.getAuthUser(request)).thenReturn(mockUser); Assert.assertTrue(interceptor.preHandle(request, response, null)); String token = "123456"; when(request.getHeader("token")).thenReturn(token); when(userMapper.queryUserByToken(token)).thenReturn(mockUser); Assert.assertTrue(interceptor.preHandle(request, response, null)); mockUser.setState(0); when(authenticator.getAuthUser(request)).thenReturn(mockUser); Assert.assertFalse(interceptor.preHandle(request, response, null)); }