public void addComment(Comment comment) { if (!comment.isCommentSet()) { List<Comment> commentList = getComments(); commentList.add(comment); comment.commentSet = true; } }
@Test public void testCreateComment() throws Exception { Comment comment = new Comment("Comment name", "Article name"); entityTransactionComment.begin(); Comment returned = jpaCommentDao.createComment(comment); entityTransactionComment.commit(); assertEquals(4, returned.getCommentId()); }
@Test public void testFindNewsByComment() throws Exception { Comment comment = jpaCommentDao.getCommentById(1); List<Comment> commentList = new ArrayList(); commentList.add(comment); News news = jpaNewsDao.getNewsById(1); news.setComments(commentList); Comment commentWithNews = jpaCommentDao.getCommentById(1); assertEquals(news, commentWithNews.getNews()); }
@Test public void testCommentContainsComments() throws Exception { Comment parentComment = jpaCommentDao.getCommentById(1); Comment childComment1 = jpaCommentDao.getCommentById(2); Comment childComment2 = jpaCommentDao.getCommentById(3); parentComment.addComment(childComment1); parentComment.addComment(childComment2); entityTransactionComment.begin(); jpaCommentDao.updateComment(parentComment); entityTransactionComment.commit(); Comment newCom = jpaCommentDao.getCommentById(1); assertEquals(2, newCom.getComments().size()); }
@Test public void testUpdateComment() throws Exception { Comment comment = jpaCommentDao.getCommentById(1); comment.setName("updatedName"); Comment returnedComment = jpaCommentDao.updateComment(comment); Comment updatedComment = jpaCommentDao.getCommentById(1); assertEquals(returnedComment.getName(), "updatedName"); assertEquals(updatedComment.getName(), "updatedName"); }
@Test public void testGetCommentByName() throws Exception { Comment comment = jpaCommentDao.getCommentByName("commentName1"); assertEquals(1, comment.getCommentId()); }
@Test public void testCommentHaveUser() throws Exception { Comment comment = jpaCommentDao.getCommentById(1); assertEquals(User.class, comment.getUser().getClass()); }
@Test public void testGetCommentById() throws Exception { Comment comment = jpaCommentDao.getCommentById(1); assertEquals(comment.getName(), "commentName1"); }