@Test void getPlacesByStatusTest() { int pageNumber = 0; int pageSize = 1; Pageable pageable = PageRequest.of(pageNumber, pageSize); Place place = new Place(); place.setName("Place"); AdminPlaceDto dto = new AdminPlaceDto(); dto.setName("Place"); Page<Place> placesPage = new PageImpl<>(Collections.singletonList(place), pageable, 1); List<AdminPlaceDto> listDto = Collections.singletonList(dto); PageableDto<AdminPlaceDto> pageableDto = new PageableDto<>(listDto, listDto.size(), 0,1); pageableDto.setPage(listDto); when(placeRepo.findAllByStatusOrderByModifiedDateDesc(any(), any())).thenReturn(placesPage); when(modelMapper.map(any(), any())).thenReturn(dto); assertEquals(pageableDto, placeService.getPlacesByStatus(any(), any())); verify(placeRepo, times(1)).findAllByStatusOrderByModifiedDateDesc(any(), any()); }
@Override public PageableDto<AdminPlaceDto> getPlacesByStatus(PlaceStatus placeStatus, Pageable pageable) { Page<Place> places = placeRepo.findAllByStatusOrderByModifiedDateDesc(placeStatus, pageable); List<AdminPlaceDto> list = places.stream() .map(place -> modelMapper.map(place, AdminPlaceDto.class)) .collect(Collectors.toList()); return new PageableDto<>(list, places.getTotalElements(), places.getPageable().getPageNumber(), places.getTotalPages()); }
PlaceServiceImpl implements PlaceService { @Override public PageableDto<AdminPlaceDto> getPlacesByStatus(PlaceStatus placeStatus, Pageable pageable) { Page<Place> places = placeRepo.findAllByStatusOrderByModifiedDateDesc(placeStatus, pageable); List<AdminPlaceDto> list = places.stream() .map(place -> modelMapper.map(place, AdminPlaceDto.class)) .collect(Collectors.toList()); return new PageableDto<>(list, places.getTotalElements(), places.getPageable().getPageNumber(), places.getTotalPages()); } }
PlaceServiceImpl implements PlaceService { @Override public PageableDto<AdminPlaceDto> getPlacesByStatus(PlaceStatus placeStatus, Pageable pageable) { Page<Place> places = placeRepo.findAllByStatusOrderByModifiedDateDesc(placeStatus, pageable); List<AdminPlaceDto> list = places.stream() .map(place -> modelMapper.map(place, AdminPlaceDto.class)) .collect(Collectors.toList()); return new PageableDto<>(list, places.getTotalElements(), places.getPageable().getPageNumber(), places.getTotalPages()); } @Autowired  PlaceServiceImpl(PlaceRepo placeRepo,
                            ModelMapper modelMapper,
                            CategoryService categoryService,
                            LocationService locationService,
                            SpecificationService specificationService,
                            UserService userService,
                            OpenHoursService openingHoursService,
                            DiscountService discountService,
                            NotificationService notificationService,
                            @Qualifier(value = "datasourceTimezone") ZoneId datasourceTimezone,
                            RabbitTemplate rabbitTemplate,
                            ProposePlaceServiceImpl proposePlaceService); }
PlaceServiceImpl implements PlaceService { @Override public PageableDto<AdminPlaceDto> getPlacesByStatus(PlaceStatus placeStatus, Pageable pageable) { Page<Place> places = placeRepo.findAllByStatusOrderByModifiedDateDesc(placeStatus, pageable); List<AdminPlaceDto> list = places.stream() .map(place -> modelMapper.map(place, AdminPlaceDto.class)) .collect(Collectors.toList()); return new PageableDto<>(list, places.getTotalElements(), places.getPageable().getPageNumber(), places.getTotalPages()); } @Autowired  PlaceServiceImpl(PlaceRepo placeRepo,
                            ModelMapper modelMapper,
                            CategoryService categoryService,
                            LocationService locationService,
                            SpecificationService specificationService,
                            UserService userService,
                            OpenHoursService openingHoursService,
                            DiscountService discountService,
                            NotificationService notificationService,
                            @Qualifier(value = "datasourceTimezone") ZoneId datasourceTimezone,
                            RabbitTemplate rabbitTemplate,
                            ProposePlaceServiceImpl proposePlaceService); @Override PageableDto<AdminPlaceDto> getPlacesByStatus(PlaceStatus placeStatus, Pageable pageable); @Transactional @Override Place save(PlaceAddDto dto, String email); @Transactional @Override Place update(PlaceUpdateDto dto); @Override void deleteById(Long id); @Transactional @Override Long bulkDelete(List<Long> ids); @Override List<Place> findAll(); @Override UpdatePlaceStatusDto updateStatus(Long id, PlaceStatus status); @Transactional @Override List<UpdatePlaceStatusDto> updateStatuses(BulkUpdatePlaceStatusDto dto); @Override Place findById(Long id); @Override Optional<Place> findByIdOptional(Long id); @Override PlaceInfoDto getInfoById(Long id); @Override PlaceUpdateDto getInfoForUpdatingById(Long id); @Override List<PlaceByBoundsDto> findPlacesByMapsBounds(@Valid FilterPlaceDto filterPlaceDto); @Override boolean existsById(Long id); @Override Double averageRate(Long id); @Override List<PlaceByBoundsDto> getPlacesByFilter(FilterPlaceDto filterDto); @Override PageableDto<AdminPlaceDto> filterPlaceBySearchPredicate(FilterPlaceDto filterDto, Pageable pageable); @Override List<PlaceStatus> getStatuses(); }
PlaceServiceImpl implements PlaceService { @Override public PageableDto<AdminPlaceDto> getPlacesByStatus(PlaceStatus placeStatus, Pageable pageable) { Page<Place> places = placeRepo.findAllByStatusOrderByModifiedDateDesc(placeStatus, pageable); List<AdminPlaceDto> list = places.stream() .map(place -> modelMapper.map(place, AdminPlaceDto.class)) .collect(Collectors.toList()); return new PageableDto<>(list, places.getTotalElements(), places.getPageable().getPageNumber(), places.getTotalPages()); } @Autowired  PlaceServiceImpl(PlaceRepo placeRepo,
                            ModelMapper modelMapper,
                            CategoryService categoryService,
                            LocationService locationService,
                            SpecificationService specificationService,
                            UserService userService,
                            OpenHoursService openingHoursService,
                            DiscountService discountService,
                            NotificationService notificationService,
                            @Qualifier(value = "datasourceTimezone") ZoneId datasourceTimezone,
                            RabbitTemplate rabbitTemplate,
                            ProposePlaceServiceImpl proposePlaceService); @Override PageableDto<AdminPlaceDto> getPlacesByStatus(PlaceStatus placeStatus, Pageable pageable); @Transactional @Override Place save(PlaceAddDto dto, String email); @Transactional @Override Place update(PlaceUpdateDto dto); @Override void deleteById(Long id); @Transactional @Override Long bulkDelete(List<Long> ids); @Override List<Place> findAll(); @Override UpdatePlaceStatusDto updateStatus(Long id, PlaceStatus status); @Transactional @Override List<UpdatePlaceStatusDto> updateStatuses(BulkUpdatePlaceStatusDto dto); @Override Place findById(Long id); @Override Optional<Place> findByIdOptional(Long id); @Override PlaceInfoDto getInfoById(Long id); @Override PlaceUpdateDto getInfoForUpdatingById(Long id); @Override List<PlaceByBoundsDto> findPlacesByMapsBounds(@Valid FilterPlaceDto filterPlaceDto); @Override boolean existsById(Long id); @Override Double averageRate(Long id); @Override List<PlaceByBoundsDto> getPlacesByFilter(FilterPlaceDto filterDto); @Override PageableDto<AdminPlaceDto> filterPlaceBySearchPredicate(FilterPlaceDto filterDto, Pageable pageable); @Override List<PlaceStatus> getStatuses();  }