### Question:
MailMessageManager { public boolean takeMailGift(User user, int mailIndex) { Jedis jedisDB = JedisFactory.getJedisDB(); String mailbox = MailMessageManager.getMailboxName(user.getUsername()); String mailMessage = jedisDB.lindex(mailbox, mailIndex); if ( StringUtil.checkNotEmpty(mailMessage) ) { String[] fields = mailMessage.split(SEP); if ( fields.length >= 7 ) { String gift = fields[6]; Reward reward = Reward.fromString(gift); ArrayList<Reward> rewards = new ArrayList<Reward>(); rewards.add(reward); PickRewardResult result = RewardManager.getInstance().pickRewardWithResult( user, rewards, StatAction.ProduceMailGift); boolean success = (result == PickRewardResult.SUCCESS); if ( success ) { String newMailMessage = mailMessage.substring(0, mailMessage.length()-gift.length()-1); jedisDB.lset(mailbox, mailIndex, newMailMessage); } return success; } else { logger.debug("The mail does not have attacked gift."); } } return false; } MailMessageManager(); static final MailMessageManager getInstance(); boolean sendAdminMail(UserId toUserId, 
			String subject, String content, Reward gift); boolean sendMail(UserId fromUserId, UserId toUserId, 
			String subject, String content, Collection<Reward> gifts, boolean isAdmin); void readMail(User user, int mailIndex, MailBoxType type); boolean takeMailGift(User user, int mailIndex); void checkMail(User user); void checkSendBox(User user, Jedis jedisDB); int deleteMail(User user, int[] mailIndex, MailBoxType type); void deleteAllMail(User user, MailBoxType type); void pushValueInList(String list, String content, int maxListCount, int expireSeconds); int deleteValueInList(String list, int[] indexes); void deleteAllInList(String list); String popValueFromList(String list, int expireSeconds); int acquireMailCount(String list); final boolean pushSimpleMessage(final String roleName, 
			final String deviceToken, final String text, int expireSeconds); final Collection<String> listSimplePushMessages(final String roleName); final Map<String, Date> getIosInactiveDevices(); final MailData parseMailString(String mailMessage); static final String getMailboxName(String userName); static final String getOfflineboxName(String roleName); static final String getMailboxName(String userName, MailBoxType type);  }### Answer:
@Test public void testTakeMailGift() throws Exception { String userName = "test-001"; User user = prepareUser(userName); user.setSessionKey(null); Collection<Reward> rewards = prepareRewards(); int bagCount = user.getBag().getCurrentCount(); MailMessageManager mail = MailMessageManager.getInstance(); mail.sendMail(null, user.get_id(), null, "这是一封测试邮件", rewards, true); Jedis jedisDB = JedisFactory.getJedisDB(); String mailbox = mail.getMailboxName(userName); mail.takeMailGift(user, 0); assertEquals(bagCount+1, user.getBag().getCurrentCount()); mail.takeMailGift(user, 0); assertEquals(bagCount+1, user.getBag().getCurrentCount()); }