CommentService { public List<Comment> getAllCommentsForToday() { LocalDate localDate = LocalDate.now(); return commentRepository.findByCreatedYearAndMonthAndDay(localDate.getYear(), localDate.getMonth().getValue(), localDate.getDayOfMonth()); } CommentService(CommentRepository commentRepository); @Transactional(rollbackFor = Exception.class) List<Comment> saveAll(List<Comment> comments); List<Comment> getAllCommentsForToday();  }
@Test public void getAllCommentsForToday_HappyPath_ShouldReturn1Comment() { Comment comment = new Comment(); comment.setComment("Test"); comment.setType(CommentType.PLUS); comment.setCreatedDate(new Timestamp(System.currentTimeMillis())); List<Comment> comments = Arrays.asList(comment); LocalDate now = LocalDate.now(); when(commentRepository.findByCreatedYearAndMonthAndDay(now.getYear(), now.getMonth().getValue(), now.getDayOfMonth())).thenReturn(comments); List<Comment> actualComments = commentService.getAllCommentsForToday(); verify(commentRepository, times(1)).findByCreatedYearAndMonthAndDay(now.getYear(), now.getMonth().getValue(), now.getDayOfMonth()); assertThat(comments).isEqualTo(actualComments); }