@Test void updateUserProfilePictureTest() throws MalformedURLException { MultipartFile image = new MockMultipartFile("data", "filename.txt", "text/plain", "some xml".getBytes()); when(userRepo.findByEmail(anyString())).thenReturn(Optional.of(user)); when(fileService.upload(image)).thenReturn(new URL("http: userService.updateUserProfilePicture(image, anyString()); verify(userRepo).save(user); }
@Override public User updateUserProfilePicture(MultipartFile image, String email) { User user = userRepo .findByEmail(email) .orElseThrow(() -> new WrongEmailException(USER_NOT_FOUND_BY_EMAIL + email)); if (image == null) { throw new NotUpdatedException(IMAGE_EXISTS); } String url = fileService.upload(image).toString(); user.setProfilePicturePath(url); return userRepo.save(user); }
UserServiceImpl implements UserService { @Override public User updateUserProfilePicture(MultipartFile image, String email) { User user = userRepo .findByEmail(email) .orElseThrow(() -> new WrongEmailException(USER_NOT_FOUND_BY_EMAIL + email)); if (image == null) { throw new NotUpdatedException(IMAGE_EXISTS); } String url = fileService.upload(image).toString(); user.setProfilePicturePath(url); return userRepo.save(user); } }
UserServiceImpl implements UserService { @Override public User updateUserProfilePicture(MultipartFile image, String email) { User user = userRepo .findByEmail(email) .orElseThrow(() -> new WrongEmailException(USER_NOT_FOUND_BY_EMAIL + email)); if (image == null) { throw new NotUpdatedException(IMAGE_EXISTS); } String url = fileService.upload(image).toString(); user.setProfilePicturePath(url); return userRepo.save(user); }  }
UserServiceImpl implements UserService { @Override public User updateUserProfilePicture(MultipartFile image, String email) { User user = userRepo .findByEmail(email) .orElseThrow(() -> new WrongEmailException(USER_NOT_FOUND_BY_EMAIL + email)); if (image == null) { throw new NotUpdatedException(IMAGE_EXISTS); } String url = fileService.upload(image).toString(); user.setProfilePicturePath(url); return userRepo.save(user); }  @Override User save(User user); @Override User findById(Long id); @Override PageableDto<UserForListDto> findByPage(Pageable pageable); @Override PageableDto<UserManagementDto> findUserForManagementByPage(Pageable pageable); @Override void updateUser(UserManagementDto dto); @Override void deleteById(Long id); @Override User findByEmail(String email); @Override Long findIdByEmail(String email); @Override UserRoleDto updateRole(Long id, ROLE role, String email); @Override UserStatusDto updateStatus(Long id, UserStatus userStatus, String email); @Override RoleDto getRoles(); @Override List<EmailNotification> getEmailNotificationsStatuses(); @Override User updateLastVisit(User user); PageableDto<UserForListDto> getUsersByFilter(FilterUserDto filterUserDto, Pageable pageable); @Override UserUpdateDto getUserUpdateDtoByEmail(String email); @Override User update(UserUpdateDto dto, String email); @Transactional @Override List<UserGoalResponseDto> getUserGoals(Long userId, String language); @Transactional @Override List<GoalDto> getAvailableGoals(Long userId, String language); @Transactional @Override List<UserGoalResponseDto> saveUserGoals(Long userId, BulkSaveUserGoalDto bulkDto, String language); @Transactional @Override List<Long> deleteUserGoals(String ids); @Transactional @Override UserGoalResponseDto updateUserGoalStatus(Long userId, Long goalId, String language); @Override int updateUserRefreshToken(String refreshTokenKey, Long id); @Transactional @Override List<greencity.dto.user.HabitDictionaryDto> getAvailableHabitDictionary(Long userId, String language); @Override List<HabitCreateDto> createUserHabit(Long userId, List<HabitIdDto> habitIdDto, String language); @Transactional @Override List<CustomGoalResponseDto> getAvailableCustomGoals(Long userId); @Override long getActivatedUsersAmount(); @Transactional @Override void deleteHabitByUserIdAndHabitDictionary(Long userId, Long habitId); @Override void addDefaultHabit(Long userId, String language); @Override String getProfilePicturePathByUserId(Long id); @Override User updateUserProfilePicture(MultipartFile image, String email); @Override List<User> getAllUserFriends(Long userId); @Override @Transactional void deleteUserFriendById(Long userId, Long friendId); @Override @Transactional void addNewFriend(Long userId, Long friendId); @Override List<UserProfilePictureDto> getSixFriendsWithTheHighestRating(Long userId); @Override UserProfileDtoResponse saveUserProfile(UserProfileDtoRequest userProfileDtoRequest, MultipartFile image,
                                                  String email); @Override UserProfileDtoResponse getUserProfileInformation(Long userId); @Override void updateUserLastActivityTime(Long userId, Date userLastActivityTime); @Override boolean checkIfTheUserIsOnline(Long userId); @Override UserProfileStatisticsDto getUserProfileStatistics(Long userId); @Override UserAndFriendsWithOnlineStatusDto getUserAndSixFriendsWithOnlineStatus(Long userId); @Override UserAndAllFriendsWithOnlineStatusDto getAllFriendsWithTheOnlineStatus(Long userId, Pageable pageable); @Override void deactivateUser(Long id); }
UserServiceImpl implements UserService { @Override public User updateUserProfilePicture(MultipartFile image, String email) { User user = userRepo .findByEmail(email) .orElseThrow(() -> new WrongEmailException(USER_NOT_FOUND_BY_EMAIL + email)); if (image == null) { throw new NotUpdatedException(IMAGE_EXISTS); } String url = fileService.upload(image).toString(); user.setProfilePicturePath(url); return userRepo.save(user); }  @Override User save(User user); @Override User findById(Long id); @Override PageableDto<UserForListDto> findByPage(Pageable pageable); @Override PageableDto<UserManagementDto> findUserForManagementByPage(Pageable pageable); @Override void updateUser(UserManagementDto dto); @Override void deleteById(Long id); @Override User findByEmail(String email); @Override Long findIdByEmail(String email); @Override UserRoleDto updateRole(Long id, ROLE role, String email); @Override UserStatusDto updateStatus(Long id, UserStatus userStatus, String email); @Override RoleDto getRoles(); @Override List<EmailNotification> getEmailNotificationsStatuses(); @Override User updateLastVisit(User user); PageableDto<UserForListDto> getUsersByFilter(FilterUserDto filterUserDto, Pageable pageable); @Override UserUpdateDto getUserUpdateDtoByEmail(String email); @Override User update(UserUpdateDto dto, String email); @Transactional @Override List<UserGoalResponseDto> getUserGoals(Long userId, String language); @Transactional @Override List<GoalDto> getAvailableGoals(Long userId, String language); @Transactional @Override List<UserGoalResponseDto> saveUserGoals(Long userId, BulkSaveUserGoalDto bulkDto, String language); @Transactional @Override List<Long> deleteUserGoals(String ids); @Transactional @Override UserGoalResponseDto updateUserGoalStatus(Long userId, Long goalId, String language); @Override int updateUserRefreshToken(String refreshTokenKey, Long id); @Transactional @Override List<greencity.dto.user.HabitDictionaryDto> getAvailableHabitDictionary(Long userId, String language); @Override List<HabitCreateDto> createUserHabit(Long userId, List<HabitIdDto> habitIdDto, String language); @Transactional @Override List<CustomGoalResponseDto> getAvailableCustomGoals(Long userId); @Override long getActivatedUsersAmount(); @Transactional @Override void deleteHabitByUserIdAndHabitDictionary(Long userId, Long habitId); @Override void addDefaultHabit(Long userId, String language); @Override String getProfilePicturePathByUserId(Long id); @Override User updateUserProfilePicture(MultipartFile image, String email); @Override List<User> getAllUserFriends(Long userId); @Override @Transactional void deleteUserFriendById(Long userId, Long friendId); @Override @Transactional void addNewFriend(Long userId, Long friendId); @Override List<UserProfilePictureDto> getSixFriendsWithTheHighestRating(Long userId); @Override UserProfileDtoResponse saveUserProfile(UserProfileDtoRequest userProfileDtoRequest, MultipartFile image,
                                                  String email); @Override UserProfileDtoResponse getUserProfileInformation(Long userId); @Override void updateUserLastActivityTime(Long userId, Date userLastActivityTime); @Override boolean checkIfTheUserIsOnline(Long userId); @Override UserProfileStatisticsDto getUserProfileStatistics(Long userId); @Override UserAndFriendsWithOnlineStatusDto getUserAndSixFriendsWithOnlineStatus(Long userId); @Override UserAndAllFriendsWithOnlineStatusDto getAllFriendsWithTheOnlineStatus(Long userId, Pageable pageable); @Override void deactivateUser(Long id);  }