@Test void getUserGoalResponseDtoFromCustomGoalFailed() { when(modelMapper.map(customUserGoal, UserGoalResponseDto.class)).thenReturn(customUserGoalDto); when(customGoalRepo.findById(anyLong())).thenReturn(Optional.empty()); assertThrows(NotFoundException.class, () -> goalService.getUserGoalResponseDtoFromCustomGoal(customUserGoal)); }
@Override public UserGoalResponseDto getUserGoalResponseDtoFromCustomGoal(UserGoal userGoal) { UserGoalResponseDto userGoalResponseDto = modelMapper.map(userGoal, UserGoalResponseDto.class); if (userGoal.getGoal() == null) { CustomGoal customGoal = customGoalRepo.findById(userGoal .getCustomGoal().getId()).orElseThrow(() -> new NotFoundException(CUSTOM_GOAL_NOT_FOUND_BY_ID)); userGoalResponseDto.setText(customGoal.getText()); } return userGoalResponseDto; }
GoalServiceImpl implements GoalService { @Override public UserGoalResponseDto getUserGoalResponseDtoFromCustomGoal(UserGoal userGoal) { UserGoalResponseDto userGoalResponseDto = modelMapper.map(userGoal, UserGoalResponseDto.class); if (userGoal.getGoal() == null) { CustomGoal customGoal = customGoalRepo.findById(userGoal .getCustomGoal().getId()).orElseThrow(() -> new NotFoundException(CUSTOM_GOAL_NOT_FOUND_BY_ID)); userGoalResponseDto.setText(customGoal.getText()); } return userGoalResponseDto; } }
GoalServiceImpl implements GoalService { @Override public UserGoalResponseDto getUserGoalResponseDtoFromCustomGoal(UserGoal userGoal) { UserGoalResponseDto userGoalResponseDto = modelMapper.map(userGoal, UserGoalResponseDto.class); if (userGoal.getGoal() == null) { CustomGoal customGoal = customGoalRepo.findById(userGoal .getCustomGoal().getId()).orElseThrow(() -> new NotFoundException(CUSTOM_GOAL_NOT_FOUND_BY_ID)); userGoalResponseDto.setText(customGoal.getText()); } return userGoalResponseDto; }  }
GoalServiceImpl implements GoalService { @Override public UserGoalResponseDto getUserGoalResponseDtoFromCustomGoal(UserGoal userGoal) { UserGoalResponseDto userGoalResponseDto = modelMapper.map(userGoal, UserGoalResponseDto.class); if (userGoal.getGoal() == null) { CustomGoal customGoal = customGoalRepo.findById(userGoal .getCustomGoal().getId()).orElseThrow(() -> new NotFoundException(CUSTOM_GOAL_NOT_FOUND_BY_ID)); userGoalResponseDto.setText(customGoal.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 getUserGoalResponseDtoFromCustomGoal(UserGoal userGoal) { UserGoalResponseDto userGoalResponseDto = modelMapper.map(userGoal, UserGoalResponseDto.class); if (userGoal.getGoal() == null) { CustomGoal customGoal = customGoalRepo.findById(userGoal .getCustomGoal().getId()).orElseThrow(() -> new NotFoundException(CUSTOM_GOAL_NOT_FOUND_BY_ID)); userGoalResponseDto.setText(customGoal.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);  }