@Test public void update() { when(habitDictionaryRepo.findById(anyLong())).thenReturn(Optional.of(habitDictionary)); when(habitFactRepo.findById(anyLong())).thenReturn(Optional.of(habitFact)); when(habitFactRepo.save(habitFact)).thenReturn(habitFact); when(habitFactService.update(habitFactPostDTO, 1L)).thenReturn(habitFact); assertEquals(habitFact, habitFactService.update(habitFactPostDTO, 1L)); }
@Override public HabitFact update(HabitFactPostDTO fact, Long id) { return habitFactRepo.findById(id) .map(employee -> { employee.setHabitDictionary(habitDictionaryRepo.findById(fact.getHabitDictionary().getId()).get()); return habitFactRepo.save(employee); }) .orElseThrow(() -> new NotUpdatedException(ErrorMessage.HABIT_FACT_NOT_UPDATED_BY_ID)); }
HabitFactServiceImpl implements HabitFactService { @Override public HabitFact update(HabitFactPostDTO fact, Long id) { return habitFactRepo.findById(id) .map(employee -> { employee.setHabitDictionary(habitDictionaryRepo.findById(fact.getHabitDictionary().getId()).get()); return habitFactRepo.save(employee); }) .orElseThrow(() -> new NotUpdatedException(ErrorMessage.HABIT_FACT_NOT_UPDATED_BY_ID)); } }
HabitFactServiceImpl implements HabitFactService { @Override public HabitFact update(HabitFactPostDTO fact, Long id) { return habitFactRepo.findById(id) .map(employee -> { employee.setHabitDictionary(habitDictionaryRepo.findById(fact.getHabitDictionary().getId()).get()); return habitFactRepo.save(employee); }) .orElseThrow(() -> new NotUpdatedException(ErrorMessage.HABIT_FACT_NOT_UPDATED_BY_ID)); } @Autowired  HabitFactServiceImpl(ModelMapper modelMapper, HabitFactRepo habitFactRepo,
                                HabitDictionaryRepo habitDictionaryRepo, FactTranslationRepo factTranslationRepo); }
HabitFactServiceImpl implements HabitFactService { @Override public HabitFact update(HabitFactPostDTO fact, Long id) { return habitFactRepo.findById(id) .map(employee -> { employee.setHabitDictionary(habitDictionaryRepo.findById(fact.getHabitDictionary().getId()).get()); return habitFactRepo.save(employee); }) .orElseThrow(() -> new NotUpdatedException(ErrorMessage.HABIT_FACT_NOT_UPDATED_BY_ID)); } @Autowired  HabitFactServiceImpl(ModelMapper modelMapper, HabitFactRepo habitFactRepo,
                                HabitDictionaryRepo habitDictionaryRepo, FactTranslationRepo factTranslationRepo); @Override List<LanguageTranslationDTO> getAllHabitFacts(); @Override LanguageTranslationDTO getRandomHabitFactByHabitIdAndLanguage(Long id, String language); @Override HabitFactDTO getHabitFactById(Long id); @Override HabitFactDTO getHabitFactByName(String language, String name); @Override HabitFact save(HabitFactPostDTO fact); @Override HabitFact update(HabitFactPostDTO fact, Long id); @Override Long delete(Long id); }
HabitFactServiceImpl implements HabitFactService { @Override public HabitFact update(HabitFactPostDTO fact, Long id) { return habitFactRepo.findById(id) .map(employee -> { employee.setHabitDictionary(habitDictionaryRepo.findById(fact.getHabitDictionary().getId()).get()); return habitFactRepo.save(employee); }) .orElseThrow(() -> new NotUpdatedException(ErrorMessage.HABIT_FACT_NOT_UPDATED_BY_ID)); } @Autowired  HabitFactServiceImpl(ModelMapper modelMapper, HabitFactRepo habitFactRepo,
                                HabitDictionaryRepo habitDictionaryRepo, FactTranslationRepo factTranslationRepo); @Override List<LanguageTranslationDTO> getAllHabitFacts(); @Override LanguageTranslationDTO getRandomHabitFactByHabitIdAndLanguage(Long id, String language); @Override HabitFactDTO getHabitFactById(Long id); @Override HabitFactDTO getHabitFactByName(String language, String name); @Override HabitFact save(HabitFactPostDTO fact); @Override HabitFact update(HabitFactPostDTO fact, Long id); @Override Long delete(Long id);  }