@Test public void updateFavoritePlaceNotExistTest() { FavoritePlaceDto dto = ModelUtils.getFavoritePlaceDto(); FavoritePlace fp = ModelUtils.getFavoritePlace(); Exception exception = assertThrows( WrongIdException.class, () -> { when(repo.findByPlaceIdAndUserEmail(any(), any())).thenReturn(null); favoritePlaceService.update(dto, fp.getUser().getEmail()); }); String expectedMessage = ErrorMessage.FAVORITE_PLACE_NOT_FOUND; String actualMessage = exception.getMessage(); assertTrue(actualMessage.contains(expectedMessage)); }
@Override public FavoritePlaceDto update(FavoritePlaceDto favoritePlaceDto, String userEmail) { log.info(LogMessage.IN_UPDATE, favoritePlaceDto); FavoritePlace favoritePlace = repo.findByPlaceIdAndUserEmail(favoritePlaceDto.getPlaceId(), userEmail); if (favoritePlace == null) { throw new WrongIdException(ErrorMessage.FAVORITE_PLACE_NOT_FOUND + favoritePlaceDto.getPlaceId()); } favoritePlace.setName(favoritePlaceDto.getName()); return modelMapper.map(repo.save(favoritePlace), FavoritePlaceDto.class); }
FavoritePlaceServiceImpl implements FavoritePlaceService { @Override public FavoritePlaceDto update(FavoritePlaceDto favoritePlaceDto, String userEmail) { log.info(LogMessage.IN_UPDATE, favoritePlaceDto); FavoritePlace favoritePlace = repo.findByPlaceIdAndUserEmail(favoritePlaceDto.getPlaceId(), userEmail); if (favoritePlace == null) { throw new WrongIdException(ErrorMessage.FAVORITE_PLACE_NOT_FOUND + favoritePlaceDto.getPlaceId()); } favoritePlace.setName(favoritePlaceDto.getName()); return modelMapper.map(repo.save(favoritePlace), FavoritePlaceDto.class); } }
FavoritePlaceServiceImpl implements FavoritePlaceService { @Override public FavoritePlaceDto update(FavoritePlaceDto favoritePlaceDto, String userEmail) { log.info(LogMessage.IN_UPDATE, favoritePlaceDto); FavoritePlace favoritePlace = repo.findByPlaceIdAndUserEmail(favoritePlaceDto.getPlaceId(), userEmail); if (favoritePlace == null) { throw new WrongIdException(ErrorMessage.FAVORITE_PLACE_NOT_FOUND + favoritePlaceDto.getPlaceId()); } favoritePlace.setName(favoritePlaceDto.getName()); return modelMapper.map(repo.save(favoritePlace), FavoritePlaceDto.class); }  }
FavoritePlaceServiceImpl implements FavoritePlaceService { @Override public FavoritePlaceDto update(FavoritePlaceDto favoritePlaceDto, String userEmail) { log.info(LogMessage.IN_UPDATE, favoritePlaceDto); FavoritePlace favoritePlace = repo.findByPlaceIdAndUserEmail(favoritePlaceDto.getPlaceId(), userEmail); if (favoritePlace == null) { throw new WrongIdException(ErrorMessage.FAVORITE_PLACE_NOT_FOUND + favoritePlaceDto.getPlaceId()); } favoritePlace.setName(favoritePlaceDto.getName()); return modelMapper.map(repo.save(favoritePlace), FavoritePlaceDto.class); }  @Override FavoritePlaceDto save(FavoritePlaceDto favoritePlaceDto, String userEmail); @Override FavoritePlaceDto update(FavoritePlaceDto favoritePlaceDto, String userEmail); @Override List<FavoritePlaceDto> findAllByUserEmail(String email); @Override @Transactional Long deleteByUserEmailAndPlaceId(Long placeId, String userEmail); @Override FavoritePlace findByPlaceId(Long placeId); @Override PlaceInfoDto getInfoFavoritePlace(Long placeId); @Override PlaceByBoundsDto getFavoritePlaceWithLocation(Long placeId, String email); }
FavoritePlaceServiceImpl implements FavoritePlaceService { @Override public FavoritePlaceDto update(FavoritePlaceDto favoritePlaceDto, String userEmail) { log.info(LogMessage.IN_UPDATE, favoritePlaceDto); FavoritePlace favoritePlace = repo.findByPlaceIdAndUserEmail(favoritePlaceDto.getPlaceId(), userEmail); if (favoritePlace == null) { throw new WrongIdException(ErrorMessage.FAVORITE_PLACE_NOT_FOUND + favoritePlaceDto.getPlaceId()); } favoritePlace.setName(favoritePlaceDto.getName()); return modelMapper.map(repo.save(favoritePlace), FavoritePlaceDto.class); }  @Override FavoritePlaceDto save(FavoritePlaceDto favoritePlaceDto, String userEmail); @Override FavoritePlaceDto update(FavoritePlaceDto favoritePlaceDto, String userEmail); @Override List<FavoritePlaceDto> findAllByUserEmail(String email); @Override @Transactional Long deleteByUserEmailAndPlaceId(Long placeId, String userEmail); @Override FavoritePlace findByPlaceId(Long placeId); @Override PlaceInfoDto getInfoFavoritePlace(Long placeId); @Override PlaceByBoundsDto getFavoritePlaceWithLocation(Long placeId, String email);  }