@Test public void addDefaultHabitTest() { when(modelMapper.map(user, Habit.class)).thenReturn(new Habit()); when(habitRepo.findByUserIdAndStatusHabit(user.getId())).thenReturn(Collections.emptyList()); when(userRepo.findById(user.getId())).thenReturn(Optional.of(user)); userService.addDefaultHabit(user.getId(), "en"); verify(habitRepo, times(1)).saveAll(Collections.singletonList(new Habit())); }
@Override public void addDefaultHabit(Long userId, String language) { if (habitRepo.findByUserIdAndStatusHabit(userId).isEmpty()) { HabitIdDto habitIdDto = new HabitIdDto(); habitIdDto.setHabitDictionaryId(1L); createUserHabit(userId, Collections.singletonList(habitIdDto), language); } }
UserServiceImpl implements UserService { @Override public void addDefaultHabit(Long userId, String language) { if (habitRepo.findByUserIdAndStatusHabit(userId).isEmpty()) { HabitIdDto habitIdDto = new HabitIdDto(); habitIdDto.setHabitDictionaryId(1L); createUserHabit(userId, Collections.singletonList(habitIdDto), language); } } }
UserServiceImpl implements UserService { @Override public void addDefaultHabit(Long userId, String language) { if (habitRepo.findByUserIdAndStatusHabit(userId).isEmpty()) { HabitIdDto habitIdDto = new HabitIdDto(); habitIdDto.setHabitDictionaryId(1L); createUserHabit(userId, Collections.singletonList(habitIdDto), language); } }  }
UserServiceImpl implements UserService { @Override public void addDefaultHabit(Long userId, String language) { if (habitRepo.findByUserIdAndStatusHabit(userId).isEmpty()) { HabitIdDto habitIdDto = new HabitIdDto(); habitIdDto.setHabitDictionaryId(1L); createUserHabit(userId, Collections.singletonList(habitIdDto), language); } }  @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 void addDefaultHabit(Long userId, String language) { if (habitRepo.findByUserIdAndStatusHabit(userId).isEmpty()) { HabitIdDto habitIdDto = new HabitIdDto(); habitIdDto.setHabitDictionaryId(1L); createUserHabit(userId, Collections.singletonList(habitIdDto), language); } }  @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);  }