@Test void getUserGoalResponseDtoFromPredefinedGoal() { Goal goal = predefinedUserGoal.getGoal(); String code = ModelUtils.getLanguage().getCode(); when(modelMapper.map(predefinedUserGoal, UserGoalResponseDto.class)).thenReturn(predefinedUserGoalDto); when(languageService.extractLanguageCodeFromRequest()).thenReturn(code); when(goalRepo.findById(1L)).thenReturn(Optional.ofNullable(goal)); when(goalTranslationRepo.findByGoalAndLanguageCode(goal, code)) .thenReturn(Optional.of(ModelUtils.getGoalTranslation())); UserGoalResponseDto actual = goalService.getUserGoalResponseDtoFromPredefinedGoal(predefinedUserGoal); assertEquals(predefinedUserGoalDto, actual); }
@Override public UserGoalResponseDto getUserGoalResponseDtoFromPredefinedGoal(UserGoal userGoal) { UserGoalResponseDto userGoalResponseDto = modelMapper.map(userGoal, UserGoalResponseDto.class); String languageCode = languageService.extractLanguageCodeFromRequest(); if (userGoal.getCustomGoal() == null) { Goal goal = goalRepo .findById(userGoal .getGoal().getId()).orElseThrow(() -> new GoalNotFoundException(GOAL_NOT_FOUND_BY_ID)); userGoalResponseDto.setText(goalTranslationRepo.findByGoalAndLanguageCode(goal, languageCode) .orElseThrow(() -> new GoalNotFoundException(GOAL_NOT_FOUND_BY_LANGUAGE_CODE)).getText()); } return userGoalResponseDto; }
GoalServiceImpl implements GoalService { @Override public UserGoalResponseDto getUserGoalResponseDtoFromPredefinedGoal(UserGoal userGoal) { UserGoalResponseDto userGoalResponseDto = modelMapper.map(userGoal, UserGoalResponseDto.class); String languageCode = languageService.extractLanguageCodeFromRequest(); if (userGoal.getCustomGoal() == null) { Goal goal = goalRepo .findById(userGoal .getGoal().getId()).orElseThrow(() -> new GoalNotFoundException(GOAL_NOT_FOUND_BY_ID)); userGoalResponseDto.setText(goalTranslationRepo.findByGoalAndLanguageCode(goal, languageCode) .orElseThrow(() -> new GoalNotFoundException(GOAL_NOT_FOUND_BY_LANGUAGE_CODE)).getText()); } return userGoalResponseDto; } }
GoalServiceImpl implements GoalService { @Override public UserGoalResponseDto getUserGoalResponseDtoFromPredefinedGoal(UserGoal userGoal) { UserGoalResponseDto userGoalResponseDto = modelMapper.map(userGoal, UserGoalResponseDto.class); String languageCode = languageService.extractLanguageCodeFromRequest(); if (userGoal.getCustomGoal() == null) { Goal goal = goalRepo .findById(userGoal .getGoal().getId()).orElseThrow(() -> new GoalNotFoundException(GOAL_NOT_FOUND_BY_ID)); userGoalResponseDto.setText(goalTranslationRepo.findByGoalAndLanguageCode(goal, languageCode) .orElseThrow(() -> new GoalNotFoundException(GOAL_NOT_FOUND_BY_LANGUAGE_CODE)).getText()); } return userGoalResponseDto; }  }
GoalServiceImpl implements GoalService { @Override public UserGoalResponseDto getUserGoalResponseDtoFromPredefinedGoal(UserGoal userGoal) { UserGoalResponseDto userGoalResponseDto = modelMapper.map(userGoal, UserGoalResponseDto.class); String languageCode = languageService.extractLanguageCodeFromRequest(); if (userGoal.getCustomGoal() == null) { Goal goal = goalRepo .findById(userGoal .getGoal().getId()).orElseThrow(() -> new GoalNotFoundException(GOAL_NOT_FOUND_BY_ID)); userGoalResponseDto.setText(goalTranslationRepo.findByGoalAndLanguageCode(goal, languageCode) .orElseThrow(() -> new GoalNotFoundException(GOAL_NOT_FOUND_BY_LANGUAGE_CODE)).getText()); } return userGoalResponseDto; }  @Override List<GoalDto> findAll(String language); @Override UserGoalResponseDto getUserGoalResponseDtoFromPredefinedGoal(UserGoal userGoal); @Override UserGoalResponseDto getUserGoalResponseDtoFromCustomGoal(UserGoal userGoal); @Override List<ShoppingListDtoResponse> getShoppingList(Long userId, String languageCode); @Override @Transactional void changeGoalOrCustomGoalStatus(Long userId, boolean status, Long goalId, Long customGoalId); }
GoalServiceImpl implements GoalService { @Override public UserGoalResponseDto getUserGoalResponseDtoFromPredefinedGoal(UserGoal userGoal) { UserGoalResponseDto userGoalResponseDto = modelMapper.map(userGoal, UserGoalResponseDto.class); String languageCode = languageService.extractLanguageCodeFromRequest(); if (userGoal.getCustomGoal() == null) { Goal goal = goalRepo .findById(userGoal .getGoal().getId()).orElseThrow(() -> new GoalNotFoundException(GOAL_NOT_FOUND_BY_ID)); userGoalResponseDto.setText(goalTranslationRepo.findByGoalAndLanguageCode(goal, languageCode) .orElseThrow(() -> new GoalNotFoundException(GOAL_NOT_FOUND_BY_LANGUAGE_CODE)).getText()); } return userGoalResponseDto; }  @Override List<GoalDto> findAll(String language); @Override UserGoalResponseDto getUserGoalResponseDtoFromPredefinedGoal(UserGoal userGoal); @Override UserGoalResponseDto getUserGoalResponseDtoFromCustomGoal(UserGoal userGoal); @Override List<ShoppingListDtoResponse> getShoppingList(Long userId, String languageCode); @Override @Transactional void changeGoalOrCustomGoalStatus(Long userId, boolean status, Long goalId, Long customGoalId);  }