@Test public void getAllCommentsTest() { PageRequest pageRequest = new PageRequest(0, 2); List<CommentAdminDto> commentAdminDtos = Collections.singletonList(new CommentAdminDto()); List<Comment> list = Collections.singletonList(ModelUtils.getComment()); Page<Comment> comments = new PageImpl<Comment>(list, pageRequest, list.size()); PageableDto<CommentAdminDto> result = new PageableDto<>(commentAdminDtos, commentAdminDtos.size(), 0,1); when(modelMapper.map(list.get(0), CommentAdminDto.class)).thenReturn(commentAdminDtos.get(0)); when(placeCommentRepo.findAll(pageRequest)).thenReturn(comments); assertEquals(result, placeCommentService.getAllComments(pageRequest)); }
@Override public PageableDto getAllComments(Pageable pageable) { Page<Comment> comments = placeCommentRepo.findAll(pageable); List<CommentAdminDto> commentList = comments.getContent() .stream().map(comment -> modelMapper.map(comment, CommentAdminDto.class)) .collect(Collectors.toList()); return new PageableDto<CommentAdminDto>( commentList, comments.getTotalElements(), comments.getPageable().getPageNumber(), comments.getTotalPages() ); }
PlaceCommentServiceImpl implements PlaceCommentService { @Override public PageableDto getAllComments(Pageable pageable) { Page<Comment> comments = placeCommentRepo.findAll(pageable); List<CommentAdminDto> commentList = comments.getContent() .stream().map(comment -> modelMapper.map(comment, CommentAdminDto.class)) .collect(Collectors.toList()); return new PageableDto<CommentAdminDto>( commentList, comments.getTotalElements(), comments.getPageable().getPageNumber(), comments.getTotalPages() ); } }
PlaceCommentServiceImpl implements PlaceCommentService { @Override public PageableDto getAllComments(Pageable pageable) { Page<Comment> comments = placeCommentRepo.findAll(pageable); List<CommentAdminDto> commentList = comments.getContent() .stream().map(comment -> modelMapper.map(comment, CommentAdminDto.class)) .collect(Collectors.toList()); return new PageableDto<CommentAdminDto>( commentList, comments.getTotalElements(), comments.getPageable().getPageNumber(), comments.getTotalPages() ); }  }
PlaceCommentServiceImpl implements PlaceCommentService { @Override public PageableDto getAllComments(Pageable pageable) { Page<Comment> comments = placeCommentRepo.findAll(pageable); List<CommentAdminDto> commentList = comments.getContent() .stream().map(comment -> modelMapper.map(comment, CommentAdminDto.class)) .collect(Collectors.toList()); return new PageableDto<CommentAdminDto>( commentList, comments.getTotalElements(), comments.getPageable().getPageNumber(), comments.getTotalPages() ); }  @Override CommentReturnDto findById(Long id); @Override CommentReturnDto save(Long placeId, AddCommentDto addCommentDto, String email); @Override void deleteById(Long id); @Override PageableDto getAllComments(Pageable pageable); }
PlaceCommentServiceImpl implements PlaceCommentService { @Override public PageableDto getAllComments(Pageable pageable) { Page<Comment> comments = placeCommentRepo.findAll(pageable); List<CommentAdminDto> commentList = comments.getContent() .stream().map(comment -> modelMapper.map(comment, CommentAdminDto.class)) .collect(Collectors.toList()); return new PageableDto<CommentAdminDto>( commentList, comments.getTotalElements(), comments.getPageable().getPageNumber(), comments.getTotalPages() ); }  @Override CommentReturnDto findById(Long id); @Override CommentReturnDto save(Long placeId, AddCommentDto addCommentDto, String email); @Override void deleteById(Long id); @Override PageableDto getAllComments(Pageable pageable);  }