### Question:
HabitFactServiceImpl implements HabitFactService { @Override public LanguageTranslationDTO getRandomHabitFactByHabitIdAndLanguage(Long id, String language) { return modelMapper.map(factTranslationRepo.getRandomFactTranslationByHabitIdAndLanguage(language, id) .orElseThrow(() -> new NotFoundException(ErrorMessage.HABIT_FACT_NOT_FOUND_BY_ID + id)), LanguageTranslationDTO.class); } @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);  }### Answer:
@Test public void getRandomHabitFactByHabitId() { when(factTranslationRepo.getRandomFactTranslationByHabitIdAndLanguage("en", 1L)).thenReturn(Optional.of(factTranslation)); when(modelMapper.map(factTranslation, LanguageTranslationDTO.class)).thenReturn(languageTranslationDTO); assertEquals(languageTranslationDTO, habitFactService.getRandomHabitFactByHabitIdAndLanguage(1L, "en")); }
@Test(expected = NotFoundException.class) public void getRandomHabitFactByHabitIdFailed() { habitFactService.getRandomHabitFactByHabitIdAndLanguage(1L, "en"); }