@Test public void getRandomAdviceByHabitIdAndLanguage() { when(adviceTranslationRepo.getRandomAdviceTranslationByHabitIdAndLanguage("en", 1L)) .thenReturn(Optional.of(adviceTranslation)); when(modelMapper.map(adviceTranslation, LanguageTranslationDTO.class)).thenReturn(languageTranslationDTO); assertEquals(languageTranslationDTO, adviceService.getRandomAdviceByHabitIdAndLanguage(1L, "en")); }
@Override public LanguageTranslationDTO getRandomAdviceByHabitIdAndLanguage(Long id, String language) { return modelMapper.map(adviceTranslationRepo.getRandomAdviceTranslationByHabitIdAndLanguage(language, id) .orElseThrow(() -> new NotFoundException(ErrorMessage.ADVICE_NOT_FOUND_BY_ID + id)), LanguageTranslationDTO.class); }
AdviceServiceImpl implements AdviceService { @Override public LanguageTranslationDTO getRandomAdviceByHabitIdAndLanguage(Long id, String language) { return modelMapper.map(adviceTranslationRepo.getRandomAdviceTranslationByHabitIdAndLanguage(language, id) .orElseThrow(() -> new NotFoundException(ErrorMessage.ADVICE_NOT_FOUND_BY_ID + id)), LanguageTranslationDTO.class); } }
AdviceServiceImpl implements AdviceService { @Override public LanguageTranslationDTO getRandomAdviceByHabitIdAndLanguage(Long id, String language) { return modelMapper.map(adviceTranslationRepo.getRandomAdviceTranslationByHabitIdAndLanguage(language, id) .orElseThrow(() -> new NotFoundException(ErrorMessage.ADVICE_NOT_FOUND_BY_ID + id)), LanguageTranslationDTO.class); } @Autowired  AdviceServiceImpl(AdviceRepo adviceRepo, HabitDictionaryRepo habitDictionaryRepo,
                             AdviceTranslationRepo adviceTranslationRepo, ModelMapper modelMapper); }
AdviceServiceImpl implements AdviceService { @Override public LanguageTranslationDTO getRandomAdviceByHabitIdAndLanguage(Long id, String language) { return modelMapper.map(adviceTranslationRepo.getRandomAdviceTranslationByHabitIdAndLanguage(language, id) .orElseThrow(() -> new NotFoundException(ErrorMessage.ADVICE_NOT_FOUND_BY_ID + id)), LanguageTranslationDTO.class); } @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); }
AdviceServiceImpl implements AdviceService { @Override public LanguageTranslationDTO getRandomAdviceByHabitIdAndLanguage(Long id, String language) { return modelMapper.map(adviceTranslationRepo.getRandomAdviceTranslationByHabitIdAndLanguage(language, id) .orElseThrow(() -> new NotFoundException(ErrorMessage.ADVICE_NOT_FOUND_BY_ID + id)), LanguageTranslationDTO.class); } @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);  }