### Question:
PasswordAuthenticator implements Authenticator { @Override public Result<Map<String, String>> authenticate(String username, String password, String extra) { Result<Map<String, String>> result = new Result<>(); User user = userService.queryUser(username, password); if (user == null) { result.setCode(Status.USER_NAME_PASSWD_ERROR.getCode()); result.setMsg(Status.USER_NAME_PASSWD_ERROR.getMsg()); return result; } if (user.getState() == Flag.NO.ordinal()) { result.setCode(Status.USER_DISABLED.getCode()); result.setMsg(Status.USER_DISABLED.getMsg()); return result; } String sessionId = sessionService.createSession(user, extra); if (sessionId == null) { result.setCode(Status.LOGIN_SESSION_FAILED.getCode()); result.setMsg(Status.LOGIN_SESSION_FAILED.getMsg()); return result; } logger.info("sessionId : {}" , sessionId); result.setData(Collections.singletonMap(Constants.SESSION_ID, sessionId)); result.setCode(Status.SUCCESS.getCode()); result.setMsg(Status.LOGIN_SUCCESS.getMsg()); return result; }  @Override Result<Map<String, String>> authenticate(String username, String password, String extra); @Override User getAuthUser(HttpServletRequest request);  }### Answer:
@Test public void testAuthenticate() { when(usersService.queryUser("test", "test")).thenReturn(mockUser); when(sessionService.createSession(mockUser, "127.0.0.1")).thenReturn(mockSession.getId()); Result result = authenticator.authenticate("test", "test", "127.0.0.1"); Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode()); logger.info(result.toString()); mockUser.setState(0); when(usersService.queryUser("test", "test")).thenReturn(mockUser); when(sessionService.createSession(mockUser, "127.0.0.1")).thenReturn(mockSession.getId()); Result result1 = authenticator.authenticate("test", "test", "127.0.0.1"); Assert.assertEquals(Status.USER_DISABLED.getCode(), (int) result1.getCode()); logger.info(result1.toString()); }