refactored the test of update method in AdviceServiceImpl
@@ -176,17 +176,12 @@ class AdviceServiceImplTest {
when(adviceRepo.findById(adviceId)).thenReturn(Optional.of(advice));
when(habitRepo.findById(habitId)).thenReturn(Optional.of(habit));
advice.setHabit(habit);
- Type type = new TypeToken<List<AdviceTranslation>>() {
- }.getType();
- when(modelMapper.map(advicePostDto.getTranslations(), type)).thenReturn(adviceTranslations);
- advice.setTranslations(adviceTranslations);
when(adviceRepo.save(advice)).thenReturn(advice);
AdviceVO expected = modelMapper.map(advice, AdviceVO.class);
when(modelMapper.map(advice, AdviceVO.class)).thenReturn(expected);
AdviceVO actual = adviceService.update(advicePostDto, adviceId);
assertEquals(expected, actual);
- verify(adviceTranslationRepo, times(1)).deleteAllByAdvice(advice);
}
@Test
