CommentService { @Transactional(rollbackFor = Exception.class) public List<Comment> saveAll(List<Comment> comments) { LOGGER.info("Saving {}", comments); return commentRepository.saveAll(comments); } CommentService(CommentRepository commentRepository); @Transactional(rollbackFor = Exception.class) List<Comment> saveAll(List<Comment> comments); List<Comment> getAllCommentsForToday();  }
@Test public void saveAll_HappyPath_ShouldSave2Comments() { Comment comment = new Comment(); comment.setComment("Test Plus"); comment.setType(CommentType.PLUS); comment.setCreatedBy("Shazin"); comment.setCreatedDate(new Timestamp(System.currentTimeMillis())); Comment comment2 = new Comment(); comment2.setComment("Test Star"); comment2.setType(CommentType.STAR); comment2.setCreatedBy("Shahim"); comment2.setCreatedDate(new Timestamp(System.currentTimeMillis())); List<Comment> comments = Arrays.asList(comment, comment2); when(commentRepository.saveAll(comments)).thenReturn(comments); List<Comment> saved = commentService.saveAll(comments); assertThat(saved).isNotEmpty(); verify(commentRepository, times(1)).saveAll(comments); }