### Question:
AdviceServiceImpl implements AdviceService { @Override public Advice update(AdvicePostDTO advice, Long id) { return adviceRepo.findById(id) .map(employee -> { employee.setHabitDictionary(habitDictionaryRepo.findById(advice.getHabitDictionary().getId()).get()); return adviceRepo.save(employee); }) .orElseThrow(() -> new NotUpdatedException(ErrorMessage.ADVICE_NOT_UPDATED)); } @Autowired  AdviceServiceImpl(AdviceRepo adviceRepo, HabitDictionaryRepo habitDictionaryRepo,
                             AdviceTranslationRepo adviceTranslationRepo, ModelMapper modelMapper); @Override List<LanguageTranslationDTO> getAllAdvices(); @Override LanguageTranslationDTO getRandomAdviceByHabitIdAndLanguage(Long id, String language); @Override AdviceDTO getAdviceById(Long id); @Override AdviceDTO getAdviceByName(String language, String name); @Override Advice save(AdvicePostDTO advicePostDTO); @Override Advice update(AdvicePostDTO advice, Long id); @Override Long delete(Long id);  }### Answer:
@Test public void update() { when(habitDictionaryRepo.findById(anyLong())).thenReturn(Optional.of(habitDictionary)); when(adviceRepo.findById(anyLong())).thenReturn(Optional.of(advice)); when(adviceRepo.save(advice)).thenReturn(advice); when(adviceService.update(advicePostDTO, 1L)).thenReturn(advice); assertEquals(advice, adviceService.update(advicePostDTO, 1L)); }
@Test(expected = NotUpdatedException.class) public void updateFailed() { adviceService.update(advicePostDTO, 1L); }