### Question:
SessionManager { public boolean deregisterSession(IoSession session, User user) { boolean result = true; SessionKey sessionKey = null; if ( user != null ) { sessionKey = user.getSessionKey(); } if ( session != null ) { if ( user.isProxy() ) { ArrayList<SessionKey> proxySessionKeys = (ArrayList<SessionKey>)session.getAttribute(PROXY_SESSION_KEYS); if ( proxySessionKeys != null ) { proxySessionKeys.remove(sessionKey); } logger.debug("Remove User {}'s proxy sessionKey {}", user.getRoleName(), sessionKey.toString()); } else { if ( sessionKey == null ) { sessionKey = (SessionKey)session.getAttribute(Constant.SESSION_KEY); } session.removeAttribute(Constant.SESSION_KEY); session.removeAttribute(LOCALE_SESSION_KEY); } } int sessionTimeoutSeconds = GameDataManager.getInstance().getGameDataAsInt(GameDataKey.SESSION_TIMEOUT, 60); if ( user != null ) { if ( user.isAI() || user.isProxy() || sessionTimeoutSeconds <= 0 ) { try { Jedis jedis = JedisFactory.getJedis(); if ( user != null ) { user.setSessionKey(null); user.setSession(null); String userIdStr = null; if ( user.isProxy() ) { userIdStr = getProxyUserIdKey(user.get_id()); } else { userIdStr = user.get_id().toString(); } jedis.del(userIdStr); } if ( sessionKey != null ) { jedis.del(sessionKey.toString()); jedis.del(localSessionPrefix.concat(sessionKey.toString())); logger.debug("User [{}] session [{}] is removed", user.getRoleName(), sessionKey.toString()); } } catch (Exception e) { logger.warn("Deregister session exception: {}", e.getMessage()); if ( logger.isDebugEnabled() ) { logger.debug(e.getMessage(), e); } result = false; } } else { Jedis jedis = JedisFactory.getJedis(); if ( sessionKey != null ) { jedis.expire(sessionKey.toString(), sessionTimeoutSeconds); jedis.expire(localSessionPrefix.concat(sessionKey.toString()), sessionTimeoutSeconds); } if ( user != null && user.get_id() != null ) { jedis.expire(user.get_id().toString(), sessionTimeoutSeconds); } logger.debug("User [{}] session {} is to be removed after 10 seconds.", user!=null?user.getRoleName():Constant.EMPTY, user.getSessionKey().toString()); user.setStatus(UserStatus.SESSION_CLOSED); } } return result; } SessionManager(); String getLocalSessionPrefix(); SessionKey registerSession(IoSession session, User user); SessionKey registerSession(IoSession session, User user, SessionKey existSessionKey); boolean deregisterSession(IoSession session, User user); Locale findUserLocale(SessionKey sessionKey); String findUserMachineId(UserId userId); String findUserRpcId(UserId userId); String findUserRpcId(SessionKey userSessionKey); String findUserGameServerId(UserId userId); String findUserGameServerId(SessionKey userSessionKey); List<SessionKey> findAllOnlineUsers(); List<SessionKey> findAllOnlineUsers(int limit); String findSessionMachineId(SessionKey sessionKey); UserId findUserIdBySessionKey(SessionKey sessionKey); SessionKey findSessionKeyByUserId(UserId userId); SessionKey findSessionKeyByProxyUserId(UserId userId); boolean isSessionKeyFromAI(SessionKey sessionKey); boolean isSessionKeyFromProxy(SessionKey sesseionKey); static final String PROXY_SESSION_KEYS; static final String LOCALE_SESSION_KEY; static final String H_MACHINE_KEY; static final String H_RPCSERVER_KEY; static final String H_GAMESERVER_KEY; static final String H_USERID_KEY; static final String H_SESSION_KEY; static final String H_LOCALE_KEY; static final String H_ISAI; static final String H_ISPROXY; static final String V_TRUE; static final String V_FALSE; static final String Q_SESSION_PATTERN; static final String L_SESSION_PATTERN; }### Answer:
@Test public void testDeregisterSession1() { SessionManager manager = new SessionManager(); manager.deregisterSession(null, null); }