@Test void getThreeLastEcoNews() { ZonedDateTime zonedDateTime = ZonedDateTime.now(); EcoNewsDto ecoNewsDto = new EcoNewsDto(zonedDateTime, "test image path", 1L, "test title", "test text", null, ModelUtils.getEcoNewsAuthorDto(), Collections.emptyList()); EcoNews ecoNews = ModelUtils.getEcoNews(); List<EcoNewsDto> dtoList = Collections.singletonList(ecoNewsDto); when(ecoNewsRepo.getThreeLastEcoNews()).thenReturn(Collections.singletonList(ecoNews)); when(modelMapper.map(ecoNews, EcoNewsDto.class)).thenReturn(ecoNewsDto); List<EcoNewsDto> actual = ecoNewsService.getThreeLastEcoNews(); assertEquals(dtoList, actual); }
@Cacheable(value = CacheConstants.NEWEST_ECO_NEWS_CACHE_NAME) @Override public List<EcoNewsDto> getThreeLastEcoNews() { List<EcoNews> ecoNewsList = ecoNewsRepo.getThreeLastEcoNews(); if (ecoNewsList.isEmpty()) { throw new NotFoundException(ErrorMessage.ECO_NEWS_NOT_FOUND); } return ecoNewsList .stream() .map(ecoNews -> modelMapper.map(ecoNews, EcoNewsDto.class)) .collect(Collectors.toList()); }
EcoNewsServiceImpl implements EcoNewsService { @Cacheable(value = CacheConstants.NEWEST_ECO_NEWS_CACHE_NAME) @Override public List<EcoNewsDto> getThreeLastEcoNews() { List<EcoNews> ecoNewsList = ecoNewsRepo.getThreeLastEcoNews(); if (ecoNewsList.isEmpty()) { throw new NotFoundException(ErrorMessage.ECO_NEWS_NOT_FOUND); } return ecoNewsList .stream() .map(ecoNews -> modelMapper.map(ecoNews, EcoNewsDto.class)) .collect(Collectors.toList()); } }
EcoNewsServiceImpl implements EcoNewsService { @Cacheable(value = CacheConstants.NEWEST_ECO_NEWS_CACHE_NAME) @Override public List<EcoNewsDto> getThreeLastEcoNews() { List<EcoNews> ecoNewsList = ecoNewsRepo.getThreeLastEcoNews(); if (ecoNewsList.isEmpty()) { throw new NotFoundException(ErrorMessage.ECO_NEWS_NOT_FOUND); } return ecoNewsList .stream() .map(ecoNews -> modelMapper.map(ecoNews, EcoNewsDto.class)) .collect(Collectors.toList()); }  }
EcoNewsServiceImpl implements EcoNewsService { @Cacheable(value = CacheConstants.NEWEST_ECO_NEWS_CACHE_NAME) @Override public List<EcoNewsDto> getThreeLastEcoNews() { List<EcoNews> ecoNewsList = ecoNewsRepo.getThreeLastEcoNews(); if (ecoNewsList.isEmpty()) { throw new NotFoundException(ErrorMessage.ECO_NEWS_NOT_FOUND); } return ecoNewsList .stream() .map(ecoNews -> modelMapper.map(ecoNews, EcoNewsDto.class)) .collect(Collectors.toList()); }  @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 { @Cacheable(value = CacheConstants.NEWEST_ECO_NEWS_CACHE_NAME) @Override public List<EcoNewsDto> getThreeLastEcoNews() { List<EcoNews> ecoNewsList = ecoNewsRepo.getThreeLastEcoNews(); if (ecoNewsList.isEmpty()) { throw new NotFoundException(ErrorMessage.ECO_NEWS_NOT_FOUND); } return ecoNewsList .stream() .map(ecoNews -> modelMapper.map(ecoNews, EcoNewsDto.class)) .collect(Collectors.toList()); }  @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);  }