@Test void findAllTest() { List<TipsAndTricks> tipsAndTricks = Collections.singletonList(ModelUtils.getTipsAndTricks()); PageRequest pageRequest = PageRequest.of(0, 2); Page<TipsAndTricks> page = new PageImpl<>(tipsAndTricks, pageRequest, tipsAndTricks.size()); List<TipsAndTricksDtoResponse> dtoList = Collections.singletonList(ModelUtils.getTipsAndTricksDtoResponse()); PageableDto<TipsAndTricksDtoResponse> pageableDto = new PageableDto<>(dtoList, dtoList.size(), 0,1); when(tipsAndTricksRepo.findAllByOrderByCreationDateDesc(pageRequest)).thenReturn(page); when(modelMapper.map(tipsAndTricks.get(0), TipsAndTricksDtoResponse.class)).thenReturn(dtoList.get(0)); PageableDto<TipsAndTricksDtoResponse> actual = tipsAndTricksService.findAll(pageRequest); assertEquals(pageableDto, actual); }
@Cacheable(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME) @Override public PageableDto<TipsAndTricksDtoResponse> findAll(Pageable page) { Page<TipsAndTricks> pages = tipsAndTricksRepo.findAllByOrderByCreationDateDesc(page); return getPagesWithTipsAndTricksResponseDto(pages); }
TipsAndTricksServiceImpl implements TipsAndTricksService { @Cacheable(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME) @Override public PageableDto<TipsAndTricksDtoResponse> findAll(Pageable page) { Page<TipsAndTricks> pages = tipsAndTricksRepo.findAllByOrderByCreationDateDesc(page); return getPagesWithTipsAndTricksResponseDto(pages); } }
TipsAndTricksServiceImpl implements TipsAndTricksService { @Cacheable(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME) @Override public PageableDto<TipsAndTricksDtoResponse> findAll(Pageable page) { Page<TipsAndTricks> pages = tipsAndTricksRepo.findAllByOrderByCreationDateDesc(page); return getPagesWithTipsAndTricksResponseDto(pages); }  }
TipsAndTricksServiceImpl implements TipsAndTricksService { @Cacheable(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME) @Override public PageableDto<TipsAndTricksDtoResponse> findAll(Pageable page) { Page<TipsAndTricks> pages = tipsAndTricksRepo.findAllByOrderByCreationDateDesc(page); return getPagesWithTipsAndTricksResponseDto(pages); }  @CacheEvict(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME, allEntries = true) @Override TipsAndTricksDtoResponse save(TipsAndTricksDtoRequest tipsAndTricksDtoRequest, MultipartFile image,
                                         String email); @CacheEvict(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME, allEntries = true) @Override void update(TipsAndTricksDtoManagement tipsAndTricksDtoManagement,
                       MultipartFile image); @Cacheable(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME) @Override PageableDto<TipsAndTricksDtoResponse> findAll(Pageable page); @Override PageableDto<TipsAndTricksDtoResponse> find(Pageable page, List<String> tags); @Override TipsAndTricksDtoResponse findDtoById(Long id); @CacheEvict(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME, allEntries = true) @Override void delete(Long id); @CacheEvict(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME, allEntries = true) @Override void deleteAll(List<Long> listId); TipsAndTricks findById(Long id); @Override TipsAndTricksDtoManagement findManagementDtoById(Long id); @Override PageableDto<SearchTipsAndTricksDto> search(String searchQuery); @Override Long getAmountOfWrittenTipsAndTrickByUserId(Long id); }
TipsAndTricksServiceImpl implements TipsAndTricksService { @Cacheable(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME) @Override public PageableDto<TipsAndTricksDtoResponse> findAll(Pageable page) { Page<TipsAndTricks> pages = tipsAndTricksRepo.findAllByOrderByCreationDateDesc(page); return getPagesWithTipsAndTricksResponseDto(pages); }  @CacheEvict(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME, allEntries = true) @Override TipsAndTricksDtoResponse save(TipsAndTricksDtoRequest tipsAndTricksDtoRequest, MultipartFile image,
                                         String email); @CacheEvict(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME, allEntries = true) @Override void update(TipsAndTricksDtoManagement tipsAndTricksDtoManagement,
                       MultipartFile image); @Cacheable(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME) @Override PageableDto<TipsAndTricksDtoResponse> findAll(Pageable page); @Override PageableDto<TipsAndTricksDtoResponse> find(Pageable page, List<String> tags); @Override TipsAndTricksDtoResponse findDtoById(Long id); @CacheEvict(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME, allEntries = true) @Override void delete(Long id); @CacheEvict(value = CacheConstants.TIPS_AND_TRICKS_CACHE_NAME, allEntries = true) @Override void deleteAll(List<Long> listId); TipsAndTricks findById(Long id); @Override TipsAndTricksDtoManagement findManagementDtoById(Long id); @Override PageableDto<SearchTipsAndTricksDto> search(String searchQuery); @Override Long getAmountOfWrittenTipsAndTrickByUserId(Long id);  }