@Test void search() { SearchNewsDto searchNewsDto = new SearchNewsDto(1L, "title", null, null, Collections.singletonList("tag")); PageableDto<SearchNewsDto> pageableDto = new PageableDto<>(Collections.singletonList(searchNewsDto), 4, 1,2); Page<EcoNews> page = new PageImpl<>(Collections.singletonList(ecoNews), PageRequest.of(1, 3), 1); when(ecoNewsRepo.searchEcoNews(PageRequest.of(0, 3), "test")).thenReturn(page); when(modelMapper.map(ecoNews, SearchNewsDto.class)).thenReturn(searchNewsDto); PageableDto<SearchNewsDto> actual = ecoNewsService.search("test"); assertEquals(pageableDto, actual); }
@Override public PageableDto<SearchNewsDto> search(String searchQuery) { Page<EcoNews> page = ecoNewsRepo.searchEcoNews(PageRequest.of(0, 3), searchQuery); List<SearchNewsDto> ecoNews = page.stream() .map(ecoNews1 -> modelMapper.map(ecoNews1, SearchNewsDto.class)) .collect(Collectors.toList()); return new PageableDto<>( ecoNews, page.getTotalElements(), page.getPageable().getPageNumber(), page.getTotalPages() ); }
EcoNewsServiceImpl implements EcoNewsService { @Override public PageableDto<SearchNewsDto> search(String searchQuery) { Page<EcoNews> page = ecoNewsRepo.searchEcoNews(PageRequest.of(0, 3), searchQuery); List<SearchNewsDto> ecoNews = page.stream() .map(ecoNews1 -> modelMapper.map(ecoNews1, SearchNewsDto.class)) .collect(Collectors.toList()); return new PageableDto<>( ecoNews, page.getTotalElements(), page.getPageable().getPageNumber(), page.getTotalPages() ); } }
EcoNewsServiceImpl implements EcoNewsService { @Override public PageableDto<SearchNewsDto> search(String searchQuery) { Page<EcoNews> page = ecoNewsRepo.searchEcoNews(PageRequest.of(0, 3), searchQuery); List<SearchNewsDto> ecoNews = page.stream() .map(ecoNews1 -> modelMapper.map(ecoNews1, SearchNewsDto.class)) .collect(Collectors.toList()); return new PageableDto<>( ecoNews, page.getTotalElements(), page.getPageable().getPageNumber(), page.getTotalPages() ); }  }
EcoNewsServiceImpl implements EcoNewsService { @Override public PageableDto<SearchNewsDto> search(String searchQuery) { Page<EcoNews> page = ecoNewsRepo.searchEcoNews(PageRequest.of(0, 3), searchQuery); List<SearchNewsDto> ecoNews = page.stream() .map(ecoNews1 -> modelMapper.map(ecoNews1, SearchNewsDto.class)) .collect(Collectors.toList()); return new PageableDto<>( ecoNews, page.getTotalElements(), page.getPageable().getPageNumber(), page.getTotalPages() ); }  @CacheEvict(value = CacheConstants.NEWEST_ECO_NEWS_CACHE_NAME, allEntries = true) @Override AddEcoNewsDtoResponse save(AddEcoNewsDtoRequest addEcoNewsDtoRequest,
                                      MultipartFile image, String email); @Cacheable(value = CacheConstants.NEWEST_ECO_NEWS_CACHE_NAME) @Override List<EcoNewsDto> getThreeLastEcoNews(); @Override List<EcoNewsDto> getThreeRecommendedEcoNews(Long openedEcoNewsId); @Override PageableDto<EcoNewsDto> findAll(Pageable page); @Override PageableDto<EcoNewsDto> find(Pageable page, List<String> tags); @Override EcoNews findById(Long id); @Override EcoNewsDto findDtoById(Long id); @CacheEvict(value = CacheConstants.NEWEST_ECO_NEWS_CACHE_NAME, allEntries = true) @Override void delete(Long id); @Override PageableDto<SearchNewsDto> search(String searchQuery); @Override Long getAmountOfPublishedNewsByUserId(Long id); }
EcoNewsServiceImpl implements EcoNewsService { @Override public PageableDto<SearchNewsDto> search(String searchQuery) { Page<EcoNews> page = ecoNewsRepo.searchEcoNews(PageRequest.of(0, 3), searchQuery); List<SearchNewsDto> ecoNews = page.stream() .map(ecoNews1 -> modelMapper.map(ecoNews1, SearchNewsDto.class)) .collect(Collectors.toList()); return new PageableDto<>( ecoNews, page.getTotalElements(), page.getPageable().getPageNumber(), page.getTotalPages() ); }  @CacheEvict(value = CacheConstants.NEWEST_ECO_NEWS_CACHE_NAME, allEntries = true) @Override AddEcoNewsDtoResponse save(AddEcoNewsDtoRequest addEcoNewsDtoRequest,
                                      MultipartFile image, String email); @Cacheable(value = CacheConstants.NEWEST_ECO_NEWS_CACHE_NAME) @Override List<EcoNewsDto> getThreeLastEcoNews(); @Override List<EcoNewsDto> getThreeRecommendedEcoNews(Long openedEcoNewsId); @Override PageableDto<EcoNewsDto> findAll(Pageable page); @Override PageableDto<EcoNewsDto> find(Pageable page, List<String> tags); @Override EcoNews findById(Long id); @Override EcoNewsDto findDtoById(Long id); @CacheEvict(value = CacheConstants.NEWEST_ECO_NEWS_CACHE_NAME, allEntries = true) @Override void delete(Long id); @Override PageableDto<SearchNewsDto> search(String searchQuery); @Override Long getAmountOfPublishedNewsByUserId(Long id);  }