### Question:
HabitFactServiceImpl implements HabitFactService { @Override public Long delete(Long id) { if (!(habitFactRepo.findById(id).isPresent())) { throw new NotDeletedException(ErrorMessage.HABIT_FACT_NOT_DELETED_BY_ID); } habitFactRepo.deleteById(id); return 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);  }### Answer:
@Test public void delete() { when(habitFactRepo.findById(habitFact.getId())).thenReturn(Optional.of(habitFact)); assertEquals(habitFact.getId(), habitFactService.delete(habitFact.getId())); verify(habitFactRepo, times(1)).deleteById(anyLong()); }
@Test(expected = NotDeletedException.class) public void deleteFailed() { habitFactService.delete(habitFact.getId()); }