### Question:
OfflineChallManager { public final void storeChallengeInfo(User fromUser, User toUser, boolean win, long currentTimeMillis) { if ( fromUser == null || toUser == null ) { logger.debug("#storeChallengeInfo: No from user or to user."); return; } if ( fromUser.get_id().equals(toUser.get_id() )) { return; } String dateStr = DateUtil.getToday(currentTimeMillis); String fromRoleName = fromUser.getRoleName(); String toRoleName = toUser.getRoleName(); String key = getRedisKeyName(dateStr, toRoleName); Jedis jedis = JedisFactory.getJedis(); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(currentTimeMillis); String timeStr = DateUtil.formatDateTime(cal.getTime()); String value = StringUtil.concat(timeStr, Constant.COMMA, fromRoleName, Constant.COMMA, win); jedis.lpush(key, value); int seconds = DateUtil.getSecondsToNextDateUnit(DateUnit.DAILY, cal)+86400; jedis.expire(key, seconds); } OfflineChallManager(); void reload(); final static OfflineChallManager getInstance(); final void storeChallengeInfo(User fromUser, User toUser, boolean win, long currentTimeMillis); final int[] queryChallengeInfo(User user, String dateStr); final void cleanChallengeData(User user, String dateStr); static final String getRedisKeyName(String dateStr, String roleName); static final String OFFLIEN_CHALL_KEY; }### Answer:
@Test public void testStoreChallengeInfo() { OfflineChallManager manager = OfflineChallManager.getInstance(); User fromUser = createUser("challengee"); User toUser = createUser("challenger"); boolean win = true; Calendar cal = Calendar.getInstance(); long currentTimeMillis = cal.getTimeInMillis(); String dateStr = DateUtil.getYesterday(currentTimeMillis); manager.cleanChallengeData(toUser, dateStr); manager.storeChallengeInfo(fromUser, toUser, win, currentTimeMillis); cal.add(Calendar.DAY_OF_MONTH, 1); currentTimeMillis = cal.getTimeInMillis(); dateStr = DateUtil.getYesterday(currentTimeMillis); int [] winAndLose = manager.queryChallengeInfo(toUser, dateStr); assertEquals(2, winAndLose.length); assertEquals(1, winAndLose[0]); assertEquals(0, winAndLose[1]); }