ForumService { public void addPost(Post post){ postDao.save(post); User user = post.getUser(); user.setCredit(user.getCredit() + 5); userDao.update(user); Topic topic = topicDao.get(post.getTopic().getTopicId()); topic.setReplies(topic.getReplies() + 1); topic.setLastPost(new Date()); }  @Autowired void setTopicDao(TopicDao topicDao); @Autowired void setUserDao(UserDao userDao); @Autowired void setBoardDao(BoardDao boardDao); @Autowired void setPostDao(PostDao postDao); void addTopic(Topic topic); void removeTopic(int topicId); void addPost(Post post); void removePost(int postId); void addBoard(Board board); void removeBoard(int boardId); void makeDigestTopic(int topicId); List<Board> getAllBoards(); Page getPagedTopics(int boardId,int pageNo,int pageSize); Page getPagedPosts(int topicId,int pageNo,int pageSize); Page queryTopicByTitle(String title,int pageNo,int pageSize); Board getBoardById(int boardId); Topic getTopicByTopicId(int topicId); Post getPostByPostId(int postId); void addBoardManager(int boardId,String userName); void updateTopic(Topic topic); void updatePost(Post post);  }
@Test @DataSet("XiaoChun.DataSet.xls") public void addPost() throws Exception { Post post = XlsDataSetBeanFactory.createBean(ForumServiceTest.class, "XiaoChun.DataSet.xls", "t_post", Post.class); User user = XlsDataSetBeanFactory.createBean(ForumServiceTest.class, "XiaoChun.DataSet.xls", "t_user", User.class); Topic topic = new Topic(); topic.setTopicId(1); post.setUser(user); post.setTopic(topic); forumService.addPost(post); User userDb = userService.getUserByUserName("tom"); Topic topicDb = forumService.getTopicByTopicId(1); assertEquals(post.getPostId()>1, true); assertEquals(userDb.getCredit(), 105); assertEquals(topicDb.getReplies(), 2); }